diff --git a/src/iniparser.c b/src/iniparser.c index 354b673..b24f8b2 100644 --- a/src/iniparser.c +++ b/src/iniparser.c @@ -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] ; @@ -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); @@ -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 diff --git a/src/iniparser.h b/src/iniparser.h index a242cd6..df5306f 100644 --- a/src/iniparser.h +++ b/src/iniparser.h @@ -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