Browse Source

Merge branch 'master' of ssh://git.sip-router.org/sip-router into daniel

* 'master' of ssh://git.sip-router.org/sip-router:
  kamailio compatibility, add shm_strdup and pkg_strdup implementation
Daniel-Constantin Mierla 17 years ago
parent
commit
731027de13
1 changed files with 41 additions and 0 deletions
  1. 41 0
      ut.h

+ 41 - 0
ut.h

@@ -61,6 +61,8 @@
 #include "config.h"
 #include "dprint.h"
 #include "str.h"
+#include "mem/mem.h"
+#include "mem/shm_mem.h"
 
 
 
@@ -592,6 +594,45 @@ static inline int str2sint(str* _s, int* _r)
 	return 0;
 }
 
+/**
+ * \brief Make a copy of a str structure using shm_malloc
+ * \param dst destination
+ * \param src source
+ * \return 0 on success, -1 on failure
+ */
+static inline int shm_str_dup(str* dst, const str* src)
+{
+	dst->s = shm_malloc(src->len);
+	if (!dst->s) {
+		SHM_MEM_ERROR;
+		return -1;
+	}
+
+	memcpy(dst->s, src->s, src->len);
+	dst->len = src->len;
+	return 0;
+}
+
+/**
+ * \brief Make a copy of a str structure using pkg_malloc
+ * \param dst destination
+ * \param src source
+ * \return 0 on success, -1 on failure
+ */
+static inline int pkg_str_dup(str* dst, const str* src)
+{
+	dst->s = pkg_malloc(src->len);
+	if (dst->s==NULL)
+	{
+		PKG_MEM_ERROR;
+		return -1;
+	}
+
+	memcpy(dst->s, src->s, src->len);
+	dst->len = src->len;
+	return 0;
+}
+
 /* converts a username into uid:gid,
  * returns -1 on error & 0 on success */
 int user2uid(int* uid, int* gid, char* user);