X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=string.c;h=a6019e30cee2d71f0825e4eae2970b7209d9d74e;hp=bf10783442df4dc97644f58b0fca309d52ed3163;hb=5d581fbd46a6d1949bfd876aec63041dc6724eb0;hpb=ea689d919fd6fdbfaba2de9d1cd207e033c319fd diff --git a/string.c b/string.c index bf107834..a6019e30 100644 --- a/string.c +++ b/string.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2007 Andre Noll + * Copyright (C) 2004-2008 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -63,7 +63,8 @@ __must_check __malloc void *para_malloc(size_t size) void *p = malloc(size); if (!p) { - PARA_EMERG_LOG("%s", "malloc failed, aborting\n"); + PARA_EMERG_LOG("malloc failed (size = %zu), aborting\n", + size); exit(EXIT_FAILURE); } return p; @@ -162,13 +163,13 @@ __must_check __malloc char *para_strcat(char *a, const char *b) } /** - * paraslash's version of dirname() + * Paraslash's version of dirname(). * - * \param name pointer to the full path + * \param name Pointer to the full path. * - * Compute the directory component of \p name + * Compute the directory component of \p name. * - * \return If \p name is \รพ NULL or the empty string, return \p NULL. + * \return If \p name is \p NULL or the empty string, return \p NULL. * Otherwise, Make a copy of \p name and return its directory component. Caller * is responsible to free the result. */ @@ -188,29 +189,27 @@ __must_check __malloc char *para_dirname(const char *name) } /** - * paraslash's version of basename() + * Paraslash's version of basename(). * - * \param name Pointer to the full path + * \param name Pointer to the full path. * - * Compute the filename component of \p name + * Compute the filename component of \a name. * - * \return If \p name is \p NULL or the empty string, return \p NULL, - * Otherwise, make a copy of \p name and return its filename component. Caller - * is responsible to free the result. + * \return \p NULL if (a) \a name is the empty string of \p NULL, or (b) name + * ends with a slash. Otherwise, a pointer within \a name is returned. Caller + * must not free the result. */ -__must_check __malloc char *para_basename(const char *name) +__must_check const char *para_basename(const char *name) { - char *p; + const char *ret; if (!name || !*name) return NULL; - p = strrchr(name, '/'); - if (!p) - return para_strdup(name); - p++; - if (!*p) - return NULL; - return para_strdup(p); + ret = strrchr(name, '/'); + if (!ret) + return name; + ret++; + return ret; } /**