Skip to content
Snippets Groups Projects
Commit 927b8954 authored by rswindell's avatar rswindell
Browse files

Part of MCMLXXIX's request, new behavior for iniGet/ReadNamedStringList():

Returns NULL if section doesn't exist and empty array if section exists but
contains no key/values (previously returned NULL for both conditions).
parent 89811e27
No related branches found
No related tags found
No related merge requests found
......@@ -1005,12 +1005,16 @@ iniReadNamedStringList(FILE* fp, const char* section)
named_string_t** np;
if(fp==NULL)
return(lp);
return(NULL);
rewind(fp);
if(!seek_section(fp,section))
return(lp);
return(NULL);
/* New behavior, if section exists but is empty, return single element array (terminator only) */
if((lp=(named_string_t**)malloc(sizeof(named_string_t*)))==NULL)
return(NULL);
while(!feof(fp)) {
if(fgets(str,sizeof(str),fp)==NULL)
......@@ -1033,8 +1037,7 @@ iniReadNamedStringList(FILE* fp, const char* section)
items++;
}
if(items)
lp[items]=NULL; /* terminate list */
lp[items]=NULL; /* terminate list */
return(lp);
}
......@@ -1050,9 +1053,17 @@ iniGetNamedStringList(str_list_t list, const char* section)
named_string_t** np;
if(list==NULL)
return(lp);
return(NULL);
for(i=find_section(list,section);list[i]!=NULL;i++) {
i=find_section(list,section);
if(list[i]==NULL)
return(NULL);
/* New behavior, if section exists but is empty, return single element array (terminator only) */
if((lp=(named_string_t**)malloc(sizeof(named_string_t*)))==NULL)
return(NULL);
for(;list[i]!=NULL;i++) {
SAFECOPY(str,list[i]);
if(is_eof(str))
break;
......@@ -1072,8 +1083,7 @@ iniGetNamedStringList(str_list_t list, const char* section)
items++;
}
if(items)
lp[items]=NULL; /* terminate list */
lp[items]=NULL; /* terminate list */
return(lp);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment