Skip to content

Commit

Permalink
core: utils - functions to shm-duplicate str in a block
Browse files Browse the repository at this point in the history
(cherry picked from commit 6684b57)
  • Loading branch information
miconda committed Feb 9, 2021
1 parent 6769d44 commit c3f12eb
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/core/ut.h
Expand Up @@ -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
Expand Down

0 comments on commit c3f12eb

Please sign in to comment.