Commit fc1cb743 authored by rswindell's avatar rswindell
Browse files

Created functions to copy and append string blocks (e.g. environment blocks).

This should've been commited before xtrn.cpp (whoops) <shrug>.
parent 47744b8e
......@@ -393,14 +393,52 @@ size_t strListWriteFile(FILE* fp, const str_list_t list, const char* separator)
return(i);
}
char* strListCreateBlock(str_list_t list)
size_t strListBlockLength(char* block)
{
char* p=block;
size_t str_len;
size_t block_len=0;
if(block==NULL)
return(0);
/* calculate total block length */
while((str_len=strlen(p))!=0) {
block_len+=(str_len + 1);
p+=(str_len + 1);
}
/* block must be double-NULL terminated */
if(!block_len)
block_len=1;
block_len++;
return(block_len);
}
char* strListCopyBlock(char* block)
{
char* p;
size_t block_len;
if((block_len=strListBlockLength(block))==0)
return(NULL);
if((p=(char*)malloc(block_len))==NULL)
return(NULL);
memcpy(p, block, block_len);
return(p);
}
char* strListAppendBlock(char* block, str_list_t list)
{
char* block=NULL;
char* p;
size_t str_len;
size_t block_len=0;
size_t block_len;
size_t i;
if((block_len=strListBlockLength(block))!=0)
block_len--; /* Over-write existing NULL terminator */
for(i=0; list[i]!=NULL; i++) {
str_len=strlen(list[i]);
if(str_len==0)
......@@ -428,6 +466,11 @@ char* strListCreateBlock(str_list_t list)
return(block);
}
char* strListCreateBlock(str_list_t list)
{
return(strListAppendBlock(NULL,list));
}
void strListFreeBlock(char* block)
{
FREE_AND_NULL(block); /* this must be done here for Windows-DLL reasons */
......
......@@ -108,8 +108,12 @@ void strListSortAlphaReverse(str_list_t);
void strListSortAlphaCase(str_list_t);
void strListSortAlphaCaseReverse(str_list_t);
/* Create/free NULL-terminated string block (e.g. for environment variable blocks) */
/* Create/Copy/Append/Free NULL-terminated string block */
/* (e.g. for environment variable blocks) */
char* strListCreateBlock(str_list_t);
char* strListCopyBlock(char* block);
char* strListAppendBlock(char* block, str_list_t);
size_t strListBlockLength(char* block);
void strListFreeBlock(char*);
/************/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment