From c69a4f981eec3c009772fb59dc55c8a12a31146c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deuc=D0=B5?= <shurd@sasktel.net> Date: Tue, 20 Feb 2024 08:21:35 -0500 Subject: [PATCH] Add iniReadSString() as well. --- src/xpdev/ini_file.c | 21 +++++++++++++++++++++ src/xpdev/ini_file.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/xpdev/ini_file.c b/src/xpdev/ini_file.c index f3aaa40ea8..6986fd434a 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 2049f4ad60..c5cb7b6bb8 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); -- GitLab