diff --git a/src/xpdev/ini_file.c b/src/xpdev/ini_file.c index f3aaa40ea88f29b54ed5f951b896d9ba0bf91c97..6986fd434aba28088c106d2ea929818acf22daec 100644 --- a/src/xpdev/ini_file.c +++ b/src/xpdev/ini_file.c @@ -1013,6 +1013,27 @@ char* iniReadString(FILE* fp, const char* section, const char* key, const char* return(value); } +char* iniReadSString(FILE* fp, const char* section, const char* key, const char* deflt, char* value, size_t sz) +{ + char fval[INI_MAX_VALUE_LEN]; + char *ret; + size_t pos; + + ret = iniReadString(fp, section, key, deflt, value); + if (ret == NULL) + return ret; + if (sz < 1 || value == NULL) + return NULL; + for (pos = 0; fval[pos]; pos++) { + if (pos == sz - 1) { + value[pos] = 0; + break; + } + value[pos] = fval[pos]; + } + return value; +} + /* Does NOT support string literals: */ char* iniReadValue(FILE* fp, const char* section, const char* key, const char* deflt, char* value) { diff --git a/src/xpdev/ini_file.h b/src/xpdev/ini_file.h index 2049f4ad60ee7f2ed6fea275d588824ce6cfd550..c5cb7b6bb81ed95814f95cbb4a151ca886ce113c 100644 --- a/src/xpdev/ini_file.h +++ b/src/xpdev/ini_file.h @@ -72,6 +72,8 @@ DLLEXPORT char* iniReadExistingValue(FILE*, const char* section, const char* k /* These functions read a single key of the specified type */ DLLEXPORT char* iniReadString(FILE*, const char* section, const char* key ,const char* deflt, char* value); +DLLEXPORT char* iniReadSString(FILE* fp, const char* section, const char* key + ,const char* deflt, char* value, size_t sz); /* If the key doesn't exist, iniReadExistingString just returns NULL */ DLLEXPORT char* iniReadExistingString(FILE*, const char* section, const char* key ,const char* deflt, char* value);