diff --git a/src/xpdev/ini_file.c b/src/xpdev/ini_file.c index 6b2ed6285a93849cb07d0fbe4de6723991034a09..f3aaa40ea88f29b54ed5f951b896d9ba0bf91c97 100644 --- a/src/xpdev/ini_file.c +++ b/src/xpdev/ini_file.c @@ -1038,6 +1038,29 @@ char* iniGetString(str_list_t list, const char* section, const char* key, const return(vp); } +char* iniGetSString(str_list_t list, 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 = iniGetString(list, section, key, deflt, value); + if (ret == NULL) + return ret; + if (sz < 1 || value == NULL) + return ret; + for (pos = 0; fval[pos]; pos++) { + if (pos == sz - 1) { + value[pos] = 0; + break; + } + value[pos] = fval[pos]; + } + if (ret == fval) + return value; + return ret; +} + /* Does NOT support string literals: */ char* iniGetValue(str_list_t list, 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 0179019c2e005d5d4d155565628ba5f285b5f077..2049f4ad60ee7f2ed6fea275d588824ce6cfd550 100644 --- a/src/xpdev/ini_file.h +++ b/src/xpdev/ini_file.h @@ -149,6 +149,11 @@ DLLEXPORT char* iniGetExistingValue(str_list_t, const char* section, const cha /* Return the string value (potentially string literals separated by colon rather than equal): */ DLLEXPORT char* iniGetString(str_list_t, const char* section, const char* key ,const char* deflt, char* value /* may be NULL */); + +/* As above but specify the size of value */ +DLLEXPORT char* iniGetSString(str_list_t listr, const char* section, const char* key + ,const char* deflt, char* value /* may be NULL */, size_t sz); + /* If the key doesn't exist, iniGetExistingString just returns NULL */ DLLEXPORT char* iniGetExistingString(str_list_t, const char* section, const char* key ,const char* deflt, char* value /* may be NULL */);