more allocators se_alloc0() se_memdups() se_strdup() se_strndup() se_strdup_printf()
authorlego <lego@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 16 Aug 2005 00:55:08 +0000 (00:55 +0000)
committerlego <lego@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 16 Aug 2005 00:55:08 +0000 (00:55 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@15364 f5534014-38df-0310-8fa8-9805f1628bb7

epan/emem.c
epan/emem.h

index ad516350eb74adbd9da7faa3beb75bd33bbea495..909a535c2e0006872c2e5c07d59f1e543b13edbb 100644 (file)
@@ -312,6 +312,56 @@ gchar** ep_strsplit(const gchar* string, const gchar* sep, int max_tokens) {
        return vec;
 }
 
+
+
+void* se_alloc0(size_t size) {
+       return memset(se_alloc(size),'\0',size);
+}
+
+gchar* se_strdup(const gchar* src) {
+       guint len = strlen(src);
+       gchar* dst;
+       
+       dst = strncpy(se_alloc(len+1), src, len);
+       
+       dst[len] = '\0';
+       
+       return dst;
+}
+
+gchar* se_strndup(const gchar* src, size_t len) {
+       guint actual_len = strlen(src);
+       gchar* dst;
+       
+       if (len > actual_len)
+               len = actual_len;
+       
+       dst = strncpy(se_alloc(len+1), src, len);
+       
+       dst[len] = '\0';
+       
+       return dst;
+}
+
+guint8* se_memdup(const guint8* src, size_t len) {
+       return memcpy(se_alloc(len), src, len);
+}
+
+gchar* se_strdup_printf(const gchar* fmt, ...) {
+       va_list ap;
+       guint len;
+       gchar* dst;
+       
+       va_start(ap,fmt);
+       len = g_printf_string_upper_bound (fmt, ap);
+       
+       dst = se_alloc(len+1);
+       g_vsnprintf (dst, len, fmt, ap);
+       
+       va_end(ap);
+       return dst;
+}
+
 /* release all allocated memory back to the pool.
  */
 void
index d2a9487328746d33f8b795a543697a3a17166ca5..f7919cf1ed61ef3428bd7762716d248ce9a0e650 100644 (file)
@@ -60,13 +60,14 @@ guint8* ep_memdup(const guint8* src, size_t len);
 /* Create a formated string with a packet lifetime scope */
 gchar* ep_strdup_printf(const gchar* fmt, ...);
 
-/* allocates with a packet lifetime scope a array of type made of num elements */
+/* 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))
 
 /* 
  * Splits a string into a maximum of max_tokens pieces, using the given
  * delimiter. If max_tokens is reached, the remainder of string is appended
- * to the last token.
+ * to the last token. Consecutive delimiters are treated as a single delimiter.
+ *
  * the vector and all the strings are allocated with packet lifetime scope
  */
 gchar** ep_strsplit(const gchar* string, const gchar* delimiter, int max_tokens);
@@ -96,6 +97,24 @@ void se_init_chunk(void);
 /* Allocate memory with a capture lifetime scope */
 void *se_alloc(size_t size);
 
+/* Allocate memory with a capture lifetime scope and fill it with zeros*/
+void* se_alloc0(size_t size);
+
+/* Duplicate a string with a capture lifetime scope */
+gchar* se_strdup(const gchar* src);
+
+/* Duplicate at most n characters of a string with a capture lifetime scope */
+gchar* se_strndup(const gchar* src, size_t len);
+
+/* Duplicate a buffer with a capture lifetime scope */
+guint8* se_memdup(const guint8* src, size_t len);
+
+/* Create a formated string with a capture lifetime scope */
+gchar* se_strdup_printf(const gchar* fmt, ...);
+
+/* allocates with a capture lifetime scope an array of type made of num elements */
+#define se_alloc_array(type,num) (type*)ep_alloc(sizeof(type)*(num))
+
 /* release all memory allocated */
 void se_free_all(void);