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
/* 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);
/* 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);