Skip to content

Commit

Permalink
Merge pull request #158 from ndevilla/JulianHurst-master
Browse files Browse the repository at this point in the history
Support for loading string/custom streams
  • Loading branch information
lmoellendorf authored Mar 24, 2024
2 parents 24b5d4b + 4a97a81 commit cbd3ad2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
47 changes: 35 additions & 12 deletions src/iniparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,21 +722,19 @@ static line_status iniparser_line(
/*-------------------------------------------------------------------------*/
/**
@brief Parse an ini file and return an allocated dictionary object
@param ininame Name of the ini file to read.
@param in File to read.
@param ininame Name of the ini file to read (only used for nicer error messages)
@return Pointer to newly allocated dictionary
This is the parser for ini files. This function is called, providing
the name of the file to be read. It returns a dictionary object that
should not be accessed directly, but through accessor functions
instead.
the file to be read. It returns a dictionary object that should not
be accessed directly, but through accessor functions instead.
The returned dictionary must be freed using iniparser_freedict().
*/
/*--------------------------------------------------------------------------*/
dictionary * iniparser_load(const char * ininame)
dictionary * iniparser_load_file(FILE * in, const char * ininame)
{
FILE * in ;

char line [ASCIILINESZ+1] ;
char section [ASCIILINESZ+1] ;
char key [ASCIILINESZ+1] ;
Expand All @@ -751,11 +749,6 @@ dictionary * iniparser_load(const char * ininame)

dictionary * dict ;

if ((in=fopen(ininame, "r"))==NULL) {
iniparser_error_callback("iniparser: cannot open %s\n", ininame);
return NULL ;
}

dict = dictionary_new(0) ;
if (!dict) {
fclose(in);
Expand Down Expand Up @@ -841,6 +834,36 @@ dictionary * iniparser_load(const char * ininame)
return dict ;
}

/*-------------------------------------------------------------------------*/
/**
@brief Parse an ini file and return an allocated dictionary object
@param ininame Name of the ini file to read.
@return Pointer to newly allocated dictionary
This is the parser for ini files. This function is called, providing
the name of the file to be read. It returns a dictionary object that
should not be accessed directly, but through accessor functions
instead.
The returned dictionary must be freed using iniparser_freedict().
*/
/*--------------------------------------------------------------------------*/
dictionary * iniparser_load(const char * ininame)
{
FILE * in ;
dictionary * dict ;

if ((in=fopen(ininame, "r"))==NULL) {
iniparser_error_callback("iniparser: cannot open %s\n", ininame);
return NULL ;
}

dict = iniparser_load_file(in, ininame);

return dict ;
}


/*-------------------------------------------------------------------------*/
/**
@brief Free all memory associated to an ini dictionary
Expand Down
16 changes: 16 additions & 0 deletions src/iniparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,22 @@ int iniparser_find_entry(const dictionary * ini, const char * entry) ;
/*--------------------------------------------------------------------------*/
dictionary * iniparser_load(const char * ininame);

/*-------------------------------------------------------------------------*/
/**
@brief Parse an ini file and return an allocated dictionary object
@param ininame File to read.
@param ininame Name of the ini file to read (only used for nicer error messages)
@return Pointer to newly allocated dictionary
This is the parser for ini files. This function is called, providing
the file to be read. It returns a dictionary object that should not
be accessed directly, but through accessor functions instead.
The returned dictionary must be freed using iniparser_freedict().
*/
/*--------------------------------------------------------------------------*/
dictionary * iniparser_load_file(FILE * in, const char * ininame);

/*-------------------------------------------------------------------------*/
/**
@brief Free all memory associated to an ini dictionary
Expand Down

0 comments on commit cbd3ad2

Please sign in to comment.