diff options
Diffstat (limited to 'jnlib')
-rw-r--r-- | jnlib/ChangeLog | 4 | ||||
-rw-r--r-- | jnlib/strlist.c | 19 | ||||
-rw-r--r-- | jnlib/strlist.h | 1 |
3 files changed, 24 insertions, 0 deletions
diff --git a/jnlib/ChangeLog b/jnlib/ChangeLog index 84e37c52f..54984930d 100644 --- a/jnlib/ChangeLog +++ b/jnlib/ChangeLog @@ -1,3 +1,7 @@ +2009-10-19 Werner Koch <[email protected]> + + * strlist.c (add_to_strlist_try): New. + 2009-09-22 Werner Koch <[email protected]> * dotlock.h (DOTLOCK): Rename to dotlock_t. Change all users. diff --git a/jnlib/strlist.c b/jnlib/strlist.c index d45a1648a..b31e6213a 100644 --- a/jnlib/strlist.c +++ b/jnlib/strlist.c @@ -57,6 +57,25 @@ add_to_strlist( strlist_t *list, const char *string ) } +/* Add STRING to the LIST at the front. This function returns NULL + and sets ERRNO on memory shortage. */ +strlist_t +add_to_strlist_try (strlist_t *list, const char *string) +{ + strlist_t sl; + + sl = jnlib_malloc (sizeof *sl + strlen (string)); + if (sl) + { + sl->flags = 0; + strcpy (sl->d, string); + sl->next = *list; + *list = sl; + } + return sl; +} + + /* Same as add_to_strlist() but if IS_UTF8 is *not* set, a conversion to UTF-8 is done. This function terminates the process on memory shortage. */ diff --git a/jnlib/strlist.h b/jnlib/strlist.h index 4191624ae..1e2ffa8da 100644 --- a/jnlib/strlist.h +++ b/jnlib/strlist.h @@ -30,6 +30,7 @@ typedef struct string_list *strlist_t; void free_strlist (strlist_t sl); strlist_t add_to_strlist (strlist_t *list, const char *string); +strlist_t add_to_strlist_try (strlist_t *list, const char *string); strlist_t add_to_strlist2( strlist_t *list, const char *string, int is_utf8); |