Browse code

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

Daniel-Constantin Mierla authored on 19/01/2021 20:00:54
Showing 1 changed files
... ...
@@ -745,6 +745,29 @@ static inline int strz2sint(char* _s, int* _r)
745 745
 	return 0;
746 746
 }
747 747
 
748
+/**
749
+ * duplicate str structure and content in a single shm block
750
+ */
751
+static str* shm_str_dup_block(const str* src)
752
+{
753
+	str *dst;
754
+
755
+	if(src==NULL) {
756
+		return NULL;
757
+	}
758
+	dst = (str*)shm_malloc(sizeof(str) + src->len + 1);
759
+	if (dst == NULL) {
760
+		SHM_MEM_ERROR;
761
+		return NULL;
762
+	}
763
+	memset(dst, 0, sizeof(str) + src->len + 1);
764
+
765
+	dst->s = (char*)dst + sizeof(str);
766
+	dst->len = src->len;
767
+	memcpy(dst->s, src->s, src->len);
768
+
769
+	return dst;
770
+}
748 771
 
749 772
 /**
750 773
  * \brief Make a copy of a str structure to a str using shm_malloc