diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-04-01 19:31:28 +0200 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-04-01 19:31:28 +0200 |
commit | 4d05e2bc73496cd2e5637dd2153f09d9a34e6b3d (patch) | |
tree | 143410e6fea5e13af4c8e712b1b60ae7ac919990 /FICS/variable.c | |
parent | 89cc559a614a086b6927ff5d5d25e77029c5d4fa (diff) |
Revised set_prompt()
Diffstat (limited to 'FICS/variable.c')
-rw-r--r-- | FICS/variable.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/FICS/variable.c b/FICS/variable.c index 7840b40..0d28752 100644 --- a/FICS/variable.c +++ b/FICS/variable.c @@ -468,22 +468,29 @@ PRIVATE int set_promote(int p, char *var, char *val) return VAR_OK; } -PRIVATE int set_prompt(int p, char *var, char *val) +PRIVATE int +set_prompt(int p, char *var, char *val) { - if (!val) { - if (parray[p].prompt && (parray[p].prompt != def_prompt)) - rfree(parray[p].prompt); - parray[p].prompt = def_prompt; - return VAR_OK; - } - if (!printablestring(val)) - return VAR_BADVAL; - if (parray[p].prompt != def_prompt) - rfree(parray[p].prompt); - parray[p].prompt = (char *) rmalloc(strlen(val) + 2); - strcpy(parray[p].prompt, val); - strcat(parray[p].prompt, " "); - return VAR_OK; + if (!val) { + if (parray[p].prompt && parray[p].prompt != def_prompt) + rfree(parray[p].prompt); + parray[p].prompt = def_prompt; + return VAR_OK; + } + + if (!printablestring(val)) + return VAR_BADVAL; + + if (parray[p].prompt != def_prompt) + rfree(parray[p].prompt); + + const size_t size = strlen(val) + 2; + parray[p].prompt = rmalloc(size); + + strlcpy(parray[p].prompt, val, size); + strlcat(parray[p].prompt, " ", size); + + return VAR_OK; } PRIVATE int |