aboutsummaryrefslogtreecommitdiff
path: root/src/util/strings.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/strings.c')
-rw-r--r--src/util/strings.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/util/strings.c b/src/util/strings.c
index 70986a978..4cef5b6fd 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -216,21 +216,33 @@ convert_with_table (const char *input,
216 in = GNUNET_strdup (input); 216 in = GNUNET_strdup (input);
217 for (tok = strtok (in, " "); tok != NULL; tok = strtok (NULL, " ")) 217 for (tok = strtok (in, " "); tok != NULL; tok = strtok (NULL, " "))
218 { 218 {
219 i = 0; 219 do
220 while ((table[i].name != NULL) && (0 != strcasecmp (table[i].name, tok)))
221 i++;
222 if (table[i].name != NULL)
223 last *= table[i].value;
224 else
225 { 220 {
226 ret += last; 221 i = 0;
227 last = 0; 222 while ((table[i].name != NULL) && (0 != strcasecmp (table[i].name, tok)))
228 if (1 != SSCANF (tok, "%llu", &last)) 223 i++;
224 if (table[i].name != NULL)
229 { 225 {
230 GNUNET_free (in); 226 last *= table[i].value;
231 return GNUNET_SYSERR; /* expected number */ 227 break; /* next tok */
232 } 228 }
233 } 229 else
230 {
231 char *endptr;
232 ret += last;
233 errno = 0;
234 last = strtoull (tok, &endptr, 10);
235 if ((0 != errno) || (endptr == tok))
236 {
237 GNUNET_free (in);
238 return GNUNET_SYSERR; /* expected number */
239 }
240 if ('\0' == endptr[0])
241 break; /* next tok */
242 else
243 tok = endptr; /* and re-check (handles times like "10s") */
244 }
245 } while (GNUNET_YES);
234 } 246 }
235 ret += last; 247 ret += last;
236 *output = ret; 248 *output = ret;