X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=string.c;h=198e9f1d286ee2228638a2a7994fe9e65f41ccac;hp=6033a008dbf154953de673f85048eb78812d1722;hb=4ffb9e1500e70611e453e1dd4810577629a31cdd;hpb=780adf95bc4c7cfbb0c4e99cc56ec1282a4818a1 diff --git a/string.c b/string.c index 6033a008..198e9f1d 100644 --- a/string.c +++ b/string.c @@ -1,8 +1,4 @@ -/* - * Copyright (C) 2004 Andre Noll - * - * Licensed under the GPL v2. For licencing details see COPYING. - */ +/* Copyright (C) 2004 Andre Noll , see file COPYING. */ /** \file string.c Memory allocation and string handling functions. */ @@ -10,7 +6,6 @@ #include #include /* uname() */ -#include #include #include #include @@ -118,9 +113,9 @@ __must_check __malloc char *para_strdup(const char *s) } /** - * 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. * @@ -190,7 +185,7 @@ __printf_2_3 unsigned xasprintf(char **result, const char *fmt, ...) * \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, ...) { @@ -204,17 +199,22 @@ __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; + } } /** @@ -230,7 +230,7 @@ void freep(void *arg) * 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) { @@ -548,7 +548,7 @@ __printf_2_3 int para_printf(struct para_buffer *b, const char *fmt, ...) * * \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) { @@ -585,7 +585,7 @@ 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) {