aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2022-03-17 00:13:25 -0800
committerDavid M. Syzdek <david@syzdek.net>2022-03-17 00:13:25 -0800
commit1fc1c6a6963fa20af8a9314f822071e28bb9a318 (patch)
tree9b47abe843b053746c22a7f6e4431318688519d8
parent7b39a8de72a20215e9285d824059fa843ae19aed (diff)
downloadtinyrad-1fc1c6a6963fa20af8a9314f822071e28bb9a318.tar.gz
tinyrad-1fc1c6a6963fa20af8a9314f822071e28bb9a318.tar.bz2
tinyrad-1fc1c6a6963fa20af8a9314f822071e28bb9a318.tar.xz
tinyrad-1fc1c6a6963fa20af8a9314f822071e28bb9a318.zip
libtinyrad: updating tinyrad_strexpand() to return modified buffer
-rw-r--r--include/tinyrad_internal.h2
-rw-r--r--lib/libtinyrad/lstrings.c11
-rw-r--r--tests/test-str-expand.c11
3 files changed, 12 insertions, 12 deletions
diff --git a/include/tinyrad_internal.h b/include/tinyrad_internal.h
index 42e647d..b9585bf 100644
--- a/include/tinyrad_internal.h
+++ b/include/tinyrad_internal.h
@@ -215,7 +215,7 @@ tinyrad_strdup(
215 const char * s1 ); 215 const char * s1 );
216 216
217 217
218_TINYRAD_F int 218_TINYRAD_F char *
219tinyrad_strexpand( 219tinyrad_strexpand(
220 char * dst, 220 char * dst,
221 const char * restrict src, 221 const char * restrict src,
diff --git a/lib/libtinyrad/lstrings.c b/lib/libtinyrad/lstrings.c
index ffce9d1..f05efac 100644
--- a/lib/libtinyrad/lstrings.c
+++ b/lib/libtinyrad/lstrings.c
@@ -106,7 +106,7 @@ tinyrad_strdup(
106} 106}
107 107
108 108
109int 109char *
110tinyrad_strexpand( 110tinyrad_strexpand(
111 char * dst, 111 char * dst,
112 const char * restrict src, 112 const char * restrict src,
@@ -126,9 +126,10 @@ tinyrad_strexpand(
126 126
127 127
128 assert(dst != NULL); 128 assert(dst != NULL);
129 assert(src != NULL);
130 assert(len > 0); 129 assert(len > 0);
131 130
131 if (!(src))
132 return(NULL);
132 133
133 // expand escapes in buffer 134 // expand escapes in buffer
134 offset = 0; 135 offset = 0;
@@ -160,7 +161,7 @@ tinyrad_strexpand(
160 { 161 {
161 case 'D': // domain name 162 case 'D': // domain name
162 if (uname(&unam) == -1) 163 if (uname(&unam) == -1)
163 return(TRAD_EUNKNOWN); 164 return(NULL);
164 strncpy(buff, unam.nodename, sizeof(buff)); 165 strncpy(buff, unam.nodename, sizeof(buff));
165 if ((ptr = strchr(buff, '.')) == NULL) 166 if ((ptr = strchr(buff, '.')) == NULL)
166 buff[0] = '\0'; 167 buff[0] = '\0';
@@ -312,11 +313,11 @@ tinyrad_strexpand(
312 if (offset >= len) 313 if (offset >= len)
313 { 314 {
314 dst[len-1] = '\0'; 315 dst[len-1] = '\0';
315 return(TRAD_ENOBUFS); 316 return(NULL);
316 }; 317 };
317 dst[offset] = '\0'; 318 dst[offset] = '\0';
318 319
319 return(TRAD_SUCCESS); 320 return(dst);
320} 321}
321 322
322 323
diff --git a/tests/test-str-expand.c b/tests/test-str-expand.c
index 0a5eb74..44c4816 100644
--- a/tests/test-str-expand.c
+++ b/tests/test-str-expand.c
@@ -133,11 +133,10 @@ main(
133{ 133{
134 int opt; 134 int opt;
135 int c; 135 int c;
136 int rc;
137 int opt_index; 136 int opt_index;
138 size_t pos; 137 size_t pos;
139 unsigned opts; 138 unsigned opts;
140 char buff[256]; 139 char buff[TRAD_LINE_MAX_LEN];
141 const MyTestStr * test_str; 140 const MyTestStr * test_str;
142 141
143 // getopt options 142 // getopt options
@@ -219,9 +218,9 @@ main(
219 while (optind < argc) 218 while (optind < argc)
220 { 219 {
221 trutils_verbose(opts, "test string: %s", argv[optind]); 220 trutils_verbose(opts, "test string: %s", argv[optind]);
222 if ((rc = tinyrad_strexpand(buff, argv[optind], sizeof(buff), (((opts&TEST_OPT_FORCE)) ? TRAD_YES : TRAD_NO))) != TRAD_SUCCESS) 221 if (!(tinyrad_strexpand(buff, argv[optind], sizeof(buff), (((opts&TEST_OPT_FORCE)) ? TRAD_YES : TRAD_NO))))
223 { 222 {
224 trutils_error(opts, NULL, "tinyrad_strexpand(): %s", tinyrad_strerror(rc)); 223 trutils_error(opts, NULL, "tinyrad_strexpand(): error occurred");
225 return(1); 224 return(1);
226 }; 225 };
227 buff[sizeof(buff)-1] = '\0'; 226 buff[sizeof(buff)-1] = '\0';
@@ -240,9 +239,9 @@ main(
240 { 239 {
241 test_str = &test_strings[pos]; 240 test_str = &test_strings[pos];
242 trutils_verbose(opts, "test string: %s", test_strings[pos].origin); 241 trutils_verbose(opts, "test string: %s", test_strings[pos].origin);
243 if ((rc = tinyrad_strexpand(buff, test_str->origin, sizeof(buff), (int)test_str->force)) != TRAD_SUCCESS) 242 if (!(tinyrad_strexpand(buff, test_str->origin, sizeof(buff), (int)test_str->force)))
244 { 243 {
245 trutils_error(opts, NULL, "tinyrad_strexpand(): %s", tinyrad_strerror(rc)); 244 trutils_error(opts, NULL, "tinyrad_strexpand(): error occurred");
246 return(1); 245 return(1);
247 }; 246 };
248 buff[sizeof(buff)-1] = '\0'; 247 buff[sizeof(buff)-1] = '\0';