Module: kamailio
Branch: master
Commit: 57144a263680e86616dea49e9f2ca9f84a48d777
URL: 
https://github.com/kamailio/kamailio/commit/57144a263680e86616dea49e9f2ca9f84a48d777

Author: Henning Westerholt <h...@gilawa.com>
Committer: Henning Westerholt <h...@gilawa.com>
Date: 2024-08-23T09:26:06Z

core: add new function pkg_char_dup, similar as shm_char_dup but for PKG memory

---

Modified: src/core/ut.h

---

Diff:  
https://github.com/kamailio/kamailio/commit/57144a263680e86616dea49e9f2ca9f84a48d777.diff
Patch: 
https://github.com/kamailio/kamailio/commit/57144a263680e86616dea49e9f2ca9f84a48d777.patch

---

diff --git a/src/core/ut.h b/src/core/ut.h
index aa51108229b..31b45fe5b4d 100644
--- a/src/core/ut.h
+++ b/src/core/ut.h
@@ -1017,6 +1017,34 @@ static inline int pkg_str_dup(str *dst, const str *src)
        return 0;
 }
 
+/**
+ * \brief Make a copy of a char pointer to a char pointer using pkg_malloc
+ * \param src source
+ * \return a pointer to the new allocated char on success, 0 on failure
+ */
+static inline char *pkg_char_dup(const char *src)
+{
+       char *rval;
+       int len;
+
+       if(!src) {
+               LM_ERR("NULL src or dst\n");
+               return NULL;
+       }
+
+       len = strlen(src) + 1;
+       rval = (char *)pkg_malloc(len);
+       if(!rval) {
+               PKG_MEM_ERROR;
+               return NULL;
+       }
+
+       memcpy(rval, src, len);
+
+       return rval;
+}
+
+
 /**
  * \brief Compare two str's case sensitive
  * \param str1 first str

_______________________________________________
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org

Reply via email to