diff options
author | Jeff Morriss <jeff.morriss@ulticom.com> | 2011-03-26 02:39:04 +0000 |
---|---|---|
committer | Jeff Morriss <jeff.morriss@ulticom.com> | 2011-03-26 02:39:04 +0000 |
commit | 3161977bf8ef24a58c2b452e2205f64e1a5d0a93 (patch) | |
tree | 541fbfccc8b56ac4b8f1faac0366ee7f686495f4 | |
parent | b838995e60c717cd0d1dd75999bde42ebffbe8ae (diff) | |
download | wireshark-3161977bf8ef24a58c2b452e2205f64e1a5d0a93.tar.gz |
Introduce ep_strconcat (copied from the glib version)
svn path=/trunk/; revision=36344
-rw-r--r-- | epan/emem.c | 37 | ||||
-rw-r--r-- | epan/emem.h | 2 | ||||
-rw-r--r-- | epan/g_gnuc_malloc.h | 5 | ||||
-rw-r--r-- | epan/libwireshark.def | 1 |
4 files changed, 45 insertions, 0 deletions
diff --git a/epan/emem.c b/epan/emem.c index dad7d69de9..27e11c78b3 100644 --- a/epan/emem.c +++ b/epan/emem.c @@ -1064,6 +1064,43 @@ ep_strsplit(const gchar* string, const gchar* sep, int max_tokens) return vec; } +gchar * +ep_strconcat(const gchar *string1, ...) +{ + gsize l; + va_list args; + gchar *s; + gchar *concat; + gchar *ptr; + + if (!string1) + return NULL; + + l = 1 + strlen(string1); + va_start(args, string1); + s = va_arg(args, gchar*); + while (s) { + l += strlen(s); + s = va_arg(args, gchar*); + } + va_end(args); + + concat = ep_alloc(l); + ptr = concat; + + ptr = g_stpcpy(ptr, string1); + va_start(args, string1); + s = va_arg(args, gchar*); + while (s) { + ptr = g_stpcpy(ptr, s); + s = va_arg(args, gchar*); + } + va_end(args); + + return concat; +} + + /* release all allocated memory back to the pool. */ static void diff --git a/epan/emem.h b/epan/emem.h index a2646d0c23..2acf29d96b 100644 --- a/epan/emem.h +++ b/epan/emem.h @@ -69,6 +69,8 @@ gchar* ep_strdup_vprintf(const gchar* fmt, va_list ap) G_GNUC_MALLOC; gchar* ep_strdup_printf(const gchar* fmt, ...) G_GNUC_MALLOC G_GNUC_PRINTF(1, 2); +gchar *ep_strconcat(const gchar *string, ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED; + /** allocates with a packet lifetime scope an array of type made of num elements */ #define ep_alloc_array(type,num) (type*)ep_alloc(sizeof(type)*(num)) diff --git a/epan/g_gnuc_malloc.h b/epan/g_gnuc_malloc.h index 37f8d2eeab..236234207e 100644 --- a/epan/g_gnuc_malloc.h +++ b/epan/g_gnuc_malloc.h @@ -33,4 +33,9 @@ #define G_GNUC_MALLOC #endif +/* Glib 2.8 and later has this. */ +#if ! GLIB_CHECK_VERSION(2,8,0) + #define G_GNUC_NULL_TERMINATED +#endif + #endif /* g_gnuc_malloc.h */ diff --git a/epan/libwireshark.def b/epan/libwireshark.def index 068890728b..fe47927800 100644 --- a/epan/libwireshark.def +++ b/epan/libwireshark.def @@ -380,6 +380,7 @@ ep_strbuf_new_label ep_strbuf_printf ep_strbuf_sized_new ep_strbuf_truncate +ep_strconcat ep_strdup ep_strdup_printf ep_strdup_vprintf |