瀏覽代碼

core: utils - functions to shm-duplicate str in a block

Daniel-Constantin Mierla 4 年之前
父節點
當前提交
6684b57641
共有 1 個文件被更改,包括 23 次插入0 次删除
  1. 23 0
      src/core/ut.h

+ 23 - 0
src/core/ut.h

@@ -745,6 +745,29 @@ static inline int strz2sint(char* _s, int* _r)
 	return 0;
 }
 
+/**
+ * duplicate str structure and content in a single shm block
+ */
+static str* shm_str_dup_block(const str* src)
+{
+	str *dst;
+
+	if(src==NULL) {
+		return NULL;
+	}
+	dst = (str*)shm_malloc(sizeof(str) + src->len + 1);
+	if (dst == NULL) {
+		SHM_MEM_ERROR;
+		return NULL;
+	}
+	memset(dst, 0, sizeof(str) + src->len + 1);
+
+	dst->s = (char*)dst + sizeof(str);
+	dst->len = src->len;
+	memcpy(dst->s, src->s, src->len);
+
+	return dst;
+}
 
 /**
  * \brief Make a copy of a str structure to a str using shm_malloc