Re: [PATCH 1/3] MINOR: add list_append_word function

2016-05-13 Thread Willy Tarreau
I've merged all the series, thank you Maxime!

Willy




[PATCH 1/3] MINOR: add list_append_word function

2016-05-13 Thread Maxime de Roucy
int list_append_word(struct list *li, const char *str, char **err)

Append a copy of string  (inside a wordlist) at the end of
the list .
The caller is responsible for freeing the  and  copy memory
area using free().

On failure : return 0 and  filled with an error message.
---
 include/common/standard.h |  8 
 src/standard.c| 32 
 2 files changed, 40 insertions(+)

diff --git a/include/common/standard.h b/include/common/standard.h
index cd2208c..f123f1a 100644
--- a/include/common/standard.h
+++ b/include/common/standard.h
@@ -1089,4 +1089,12 @@ static inline unsigned long long rdtsc()
 }
 #endif
 
+/* append a copy of string  (in a wordlist) at the end of the list 
+ * On failure : return 0 and  filled with an error message.
+ * The caller is responsible for freeing the  and  copy
+ * memory area using free()
+ */
+struct list;
+int list_append_word(struct list *li, const char *str, char **err);
+
 #endif /* _COMMON_STANDARD_H */
diff --git a/src/standard.c b/src/standard.c
index a4d2097..cfed94d 100644
--- a/src/standard.c
+++ b/src/standard.c
@@ -3439,6 +3439,38 @@ unsigned char utf8_next(const char *s, int len, unsigned 
int *c)
return code | ((p-(unsigned char *)s)&0x0f);
 }
 
+/* append a copy of string  (in a wordlist) at the end of the list 
+ * On failure : return 0 and  filled with an error message.
+ * The caller is responsible for freeing the  and  copy
+ * memory area using free()
+ */
+int list_append_word(struct list *li, const char *str, char **err)
+{
+   struct wordlist *wl;
+
+   wl = calloc(1, sizeof(*wl));
+   if (!wl) {
+   memprintf(err, "out of memory");
+   goto fail_wl;
+   }
+
+   wl->s = strdup(str);
+   if (!wl->s) {
+   memprintf(err, "out of memory");
+   goto fail_wl_s;
+   }
+
+   LIST_ADDQ(li, >list);
+
+   return 1;
+
+fail_wl_s:
+   free(wl->s);
+fail_wl:
+   free(wl);
+   return 0;
+}
+
 /*
  * Local variables:
  *  c-indent-level: 8
-- 
2.8.2