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 594
 	return 0;
593 595
 }
594 596
 
597
+/**
598
+ * \brief Make a copy of a str structure using shm_malloc
599
+ * \param dst destination
600
+ * \param src source
601
+ * \return 0 on success, -1 on failure
602
+ */
603
+static inline int shm_str_dup(str* dst, const str* src)
604
+{
605
+	dst->s = shm_malloc(src->len);
606
+	if (!dst->s) {
607
+		SHM_MEM_ERROR;
608
+		return -1;
609
+	}
610
+
611
+	memcpy(dst->s, src->s, src->len);
612
+	dst->len = src->len;
613
+	return 0;
614
+}
615
+
616
+/**
617
+ * \brief Make a copy of a str structure using pkg_malloc
618
+ * \param dst destination
619
+ * \param src source
620
+ * \return 0 on success, -1 on failure
621
+ */
622
+static inline int pkg_str_dup(str* dst, const str* src)
623
+{
624
+	dst->s = pkg_malloc(src->len);
625
+	if (dst->s==NULL)
626
+	{
627
+		PKG_MEM_ERROR;
628
+		return -1;
629
+	}
630
+
631
+	memcpy(dst->s, src->s, src->len);
632
+	dst->len = src->len;
633
+	return 0;
634
+}
635
+
595 636
 /* converts a username into uid:gid,
596 637
  * returns -1 on error & 0 on success */
597 638
 int user2uid(int* uid, int* gid, char* user);