diff --git a/src/xpdev/str_list.c b/src/xpdev/str_list.c index 7fbb0827df53559eff209d6356bafff6aba31f5d..5cc356434f2768531b2fe3e15a4d714cf1bf026c 100644 --- a/src/xpdev/str_list.c +++ b/src/xpdev/str_list.c @@ -349,7 +349,7 @@ void strListFree(str_list_t* list) } } -str_list_t strListReadFile(FILE* fp, str_list_t* lp, size_t max_line_len) +static str_list_t str_list_read_file(FILE* fp, str_list_t* lp, size_t max_line_len) { char* buf=NULL; size_t count; @@ -364,7 +364,7 @@ str_list_t strListReadFile(FILE* fp, str_list_t* lp, size_t max_line_len) lp=&list; } - count = strListCount(*lp); + count=strListCount(*lp); while(!feof(fp)) { if(buf==NULL && (buf=(char*)malloc(max_line_len+1))==NULL) return(NULL); @@ -380,6 +380,26 @@ str_list_t strListReadFile(FILE* fp, str_list_t* lp, size_t max_line_len) return(*lp); } +size_t strListInsertFile(FILE* fp, str_list_t* lp, size_t index, size_t max_line_len) +{ + str_list_t list; + size_t count; + + if((list=str_list_read_file(fp, NULL, max_line_len)) == NULL) + return(0); + + count = strListInsertList(lp, list, index); + + strListFree(&list); + + return(count); +} + +str_list_t strListReadFile(FILE* fp, str_list_t* lp, size_t max_line_len) +{ + return str_list_read_file(fp,lp,max_line_len); +} + size_t strListWriteFile(FILE* fp, const str_list_t list, const char* separator) { size_t i; diff --git a/src/xpdev/str_list.h b/src/xpdev/str_list.h index 20e0338a95fa2d0ecd28119bfb08622b2e18341b..7a5710381492466ceba4cf4922b0d38d89626934 100644 --- a/src/xpdev/str_list.h +++ b/src/xpdev/str_list.h @@ -124,6 +124,7 @@ void strListFreeBlock(char*); /* Read lines from file appending each line to string list */ /* Pass NULL list to have list allocated for you */ str_list_t strListReadFile(FILE*, str_list_t*, size_t max_line_len); +size_t strListInsertFile(FILE*, str_list_t*, size_t index, size_t max_line_len); /* Write to file (fp) each string in the list, optionally separated by separator (e.g. "\n") */ size_t strListWriteFile(FILE*, const str_list_t, const char* separator);