Mercurial > trustbridge
comparison common/strhelp.h @ 60:6acb1dae6185
Use strn functions and improve error handling.
Even if we know the strings are NULL terminated we use
length terminated string functions after a first strlen
this makes it easier to assert that at one point we know
the string is terminated and afterwards use the length
of that.
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Tue, 18 Mar 2014 11:28:02 +0000 |
parents | 3f6378647371 |
children | 80ab2168760f |
comparison
equal
deleted
inserted
replaced
59:3f6378647371 | 60:6acb1dae6185 |
---|---|
1 #ifndef STRHELP_H | |
2 #define STRHELP_H | |
1 /* @file Helper functions for c strings and memory management | 3 /* @file Helper functions for c strings and memory management |
2 * | 4 * |
3 * strhelp contains terminating memory allocation functions and | 5 * strhelp contains terminating memory allocation functions and |
4 * some conveniance functions to work with c strings or arrays | 6 * some conveniance functions to work with c strings or arrays |
5 * of c strings. | 7 * of c strings. |
6 */ | 8 */ |
7 void *xmalloc( size_t n ); | 9 void *xmalloc( size_t n ); |
8 void *xrealloc( void *a, size_t n ); | 10 void *xrealloc( void *a, size_t n ); |
9 void *xcalloc( size_t n, size_t m ); | 11 void *xcalloc( size_t n, size_t m ); |
10 char *xstrdup( const char *string ); | 12 char *xstrndup( const char *string, const size_t len ); |
11 | 13 |
12 /** | 14 /** |
13 * strv_length: | 15 * strv_length: |
14 * @str_array: a %NULL-terminated array of strings | 16 * @str_array: a %NULL-terminated array of strings |
15 * | 17 * |
23 | 25 |
24 /* @brief append a string to a NULL terminated array of strings. | 26 /* @brief append a string to a NULL terminated array of strings. |
25 * | 27 * |
26 * @param[inout] array pointer to the NULL terminated list of string pointers. | 28 * @param[inout] array pointer to the NULL terminated list of string pointers. |
27 * @param[in] string pointer to the string to append to the list. | 29 * @param[in] string pointer to the string to append to the list. |
30 * @param[in] len length of the string to append to the list | |
28 * */ | 31 * */ |
29 void array_append_str(char ***pArray, const char *string); | 32 void array_append_str(char ***pArray, const char *string, const size_t len); |
30 | 33 |
31 /* @brief append a string to another string. | 34 /* @brief append a string to another string. |
32 * | 35 * |
33 * @param[inout] pDst pointer to the string to be extended. | 36 * @param[inout] pDst pointer to the string to be extended. |
34 * @param[in] appendage pointer to the string to append. | 37 * @param[in] appendage pointer to the string to append. |
38 * @param[in] len length of the string to append. | |
35 * */ | 39 * */ |
36 void str_append_str(char **pDst, const char *appendage); | 40 void str_append_str(char **pDst, const char *appendage, const size_t len); |
37 | 41 |
38 void strfreev (char **str_array); | 42 void strfreev (char **str_array); |
43 #endif |