Browse code

kamailio compatibility, add shm_strdup and pkg_strdup implementation

Henning Westerholt authored on 02/12/2008 15:05:48
Showing 1 changed files
... ...
@@ -61,6 +61,8 @@
61 61
 #include "config.h"
62 62
 #include "dprint.h"
63 63
 #include "str.h"
64
+#include "mem/mem.h"
65
+#include "mem/shm_mem.h"
64 66
 
65 67
 
66 68
 
... ...
@@ -592,6 +594,45 @@ static inline int str2sint(str* _s, int* _r)
592 592
 	return 0;
593 593
 }
594 594
 
595
+/**
596
+ * \brief Make a copy of a str structure using shm_malloc
597
+ * \param dst destination
598
+ * \param src source
599
+ * \return 0 on success, -1 on failure
600
+ */
601
+static inline int shm_str_dup(str* dst, const str* src)
602
+{
603
+	dst->s = shm_malloc(src->len);
604
+	if (!dst->s) {
605
+		SHM_MEM_ERROR;
606
+		return -1;
607
+	}
608
+
609
+	memcpy(dst->s, src->s, src->len);
610
+	dst->len = src->len;
611
+	return 0;
612
+}
613
+
614
+/**
615
+ * \brief Make a copy of a str structure using pkg_malloc
616
+ * \param dst destination
617
+ * \param src source
618
+ * \return 0 on success, -1 on failure
619
+ */
620
+static inline int pkg_str_dup(str* dst, const str* src)
621
+{
622
+	dst->s = pkg_malloc(src->len);
623
+	if (dst->s==NULL)
624
+	{
625
+		PKG_MEM_ERROR;
626
+		return -1;
627
+	}
628
+
629
+	memcpy(dst->s, src->s, src->len);
630
+	dst->len = src->len;
631
+	return 0;
632
+}
633
+
595 634
 /* converts a username into uid:gid,
596 635
  * returns -1 on error & 0 on success */
597 636
 int user2uid(int* uid, int* gid, char* user);