-/*
- * Copyright (C) 2004 Andre Noll <maan@tuebingen.mpg.de>
- *
- * Licensed under the GPL v2. For licencing details see COPYING.
- */
+/* Copyright (C) 2004 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
/** \file string.c Memory allocation and string handling functions. */
}
/**
- * Print a formated message to a dynamically allocated string.
+ * Print a formatted message to a dynamically allocated string.
*
- * \param result The formated string is returned here.
+ * \param result The formatted string is returned here.
* \param fmt The format string.
* \param ap Initialized list of arguments.
*
* \return This function either returns a pointer to a string that must be
* freed by the caller or aborts without returning.
*
- * \sa printf(3), xasprintf().
+ * \sa printf(3), \ref xasprintf().
*/
__must_check __printf_1_2 __malloc char *make_message(const char *fmt, ...)
{
}
/**
- * Free the content of a pointer and set it to \p NULL.
+ * Free the content of a pointer and set it to NULL.
*
- * This is equivalent to "free(*arg); *arg = NULL;".
+ * \param arg A pointer to the pointer whose content should be freed.
*
- * \param arg The pointer whose content should be freed.
+ * If arg is NULL, the function returns immediately. Otherwise it frees the
+ * memory pointed to by *arg and sets *arg to NULL. Hence callers have to pass
+ * the *address* of the pointer variable that points to the memory which should
+ * be freed.
*/
void freep(void *arg)
{
- void **ptr = (void **)arg;
- free(*ptr);
- *ptr = NULL;
+ if (arg) {
+ void **ptr = arg;
+ free(*ptr);
+ *ptr = NULL;
+ }
}
/**
* return \a a without making a copy of \a a. Otherwise, construct the
* concatenation \a c, free \a a (but not \a b) and return \a c.
*
- * \sa strcat(3)
+ * \sa strcat(3).
*/
__must_check __malloc char *para_strcat(char *a, const char *b)
{
return tmp;
}
-/**
- * Paraslash's version of dirname().
- *
- * \param name Pointer to the full path.
- *
- * Compute the directory component of \p name.
- *
- * \return If \a name is \p NULL or the empty string, return \p NULL.
- * Otherwise, Make a copy of \a name and return its directory component. Caller
- * is responsible to free the result.
- */
-__must_check __malloc char *para_dirname(const char *name)
-{
- char *p, *ret;
-
- if (!name || !*name)
- return NULL;
- ret = para_strdup(name);
- p = strrchr(ret, '/');
- if (!p)
- *ret = '\0';
- else
- *p = '\0';
- return ret;
-}
-
-/**
- * Paraslash's version of basename().
- *
- * \param name Pointer to the full path.
- *
- * Compute the filename component of \a name.
- *
- * \return \p NULL if (a) \a name is the empty string or \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 char *para_basename(const char *name)
-{
- char *ret;
-
- if (!name || !*name)
- return NULL;
- ret = strrchr(name, '/');
- if (!ret)
- return (char *)name;
- ret++;
- return ret;
-}
-
/**
* Get the logname of the current user.
*
*
* \return Standard.
*
- * \sa para_atoi32(), strtol(3), atoi(3).
+ * \sa \ref para_atoi32(), strtol(3), atoi(3).
*/
int para_atoi64(const char *str, int64_t *value)
{
*
* \return Standard.
*
- * \sa para_atoi64().
+ * \sa \ref para_atoi64().
*/
int para_atoi32(const char *str, int32_t *value)
{