]> sigrok.org Git - libsigrok.git/blame - strutil.c
strutil: Now using base 10 in sr_atol(), sr_atoi() for compatibility to atoi(), atol...
[libsigrok.git] / strutil.c
CommitLineData
25e7d9b1 1/*
50985c20 2 * This file is part of the libsigrok project.
25e7d9b1
UH
3 *
4 * Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <stdint.h>
22#include <stdlib.h>
23#include <string.h>
9e4f8cf9 24#include <errno.h>
45c59c8b
BV
25#include "libsigrok.h"
26#include "libsigrok-internal.h"
25e7d9b1 27
2ad1deb8 28/** @cond PRIVATE */
3544f848 29#define LOG_PREFIX "strutil"
2ad1deb8 30/** @endcond */
a885ce3e 31
393fb9cb
UH
32/**
33 * @file
34 *
35 * Helper functions for handling or converting libsigrok-related strings.
36 */
37
7b870c38
UH
38/**
39 * @defgroup grp_strutil String utilities
40 *
41 * Helper functions for handling or converting libsigrok-related strings.
42 *
43 * @{
44 */
45
9e4f8cf9 46/**
df823ac4
UH
47 * @private
48 *
1ba4a1cf 49 * Convert a string representation of a numeric value (base 10) to a long integer. The
9e4f8cf9
DJ
50 * conversion is strict and will fail if the complete string does not represent
51 * a valid long integer. The function sets errno according to the details of the
52 * failure.
53 *
54 * @param str The string representation to convert.
55 * @param ret Pointer to long where the result of the conversion will be stored.
56 *
1ba4a1cf
MH
57 * @retval SR_OK Conversion successful.
58 * @retval SR_ERR Failure.
9e4f8cf9
DJ
59 *
60 * @since 0.3.0
61 */
8d558c7a 62SR_PRIV int sr_atol(const char *str, long *ret)
9e4f8cf9
DJ
63{
64 long tmp;
65 char *endptr = NULL;
66
67 errno = 0;
1ba4a1cf 68 tmp = strtol(str, &endptr, 10);
9e4f8cf9
DJ
69
70 if (!endptr || *endptr || errno) {
71 if (!errno)
72 errno = EINVAL;
73 return SR_ERR;
74 }
75
76 *ret = tmp;
77 return SR_OK;
78}
79
80/**
df823ac4
UH
81 * @private
82 *
1ba4a1cf 83 * Convert a string representation of a numeric value (base 10) to an integer. The
9e4f8cf9
DJ
84 * conversion is strict and will fail if the complete string does not represent
85 * a valid integer. The function sets errno according to the details of the
86 * failure.
87 *
88 * @param str The string representation to convert.
89 * @param ret Pointer to int where the result of the conversion will be stored.
90 *
1ba4a1cf
MH
91 * @retval SR_OK Conversion successful.
92 * @retval SR_ERR Failure.
9e4f8cf9
DJ
93 *
94 * @since 0.3.0
95 */
8d558c7a 96SR_PRIV int sr_atoi(const char *str, int *ret)
9e4f8cf9
DJ
97{
98 long tmp;
99
100 if (sr_atol(str, &tmp) != SR_OK)
101 return SR_ERR;
102
103 if ((int) tmp != tmp) {
104 errno = ERANGE;
105 return SR_ERR;
106 }
107
108 *ret = (int) tmp;
109 return SR_OK;
110}
111
112/**
df823ac4
UH
113 * @private
114 *
9e4f8cf9
DJ
115 * Convert a string representation of a numeric value to a double. The
116 * conversion is strict and will fail if the complete string does not represent
117 * a valid double. The function sets errno according to the details of the
118 * failure.
119 *
120 * @param str The string representation to convert.
121 * @param ret Pointer to double where the result of the conversion will be stored.
122 *
1ba4a1cf
MH
123 * @retval SR_OK Conversion successful.
124 * @retval SR_ERR Failure.
9e4f8cf9
DJ
125 *
126 * @since 0.3.0
127 */
8d558c7a 128SR_PRIV int sr_atod(const char *str, double *ret)
9e4f8cf9
DJ
129{
130 double tmp;
131 char *endptr = NULL;
132
133 errno = 0;
134 tmp = strtof(str, &endptr);
135
136 if (!endptr || *endptr || errno) {
137 if (!errno)
138 errno = EINVAL;
139 return SR_ERR;
140 }
141
142 *ret = tmp;
143 return SR_OK;
144}
145
146/**
df823ac4
UH
147 * @private
148 *
9e4f8cf9
DJ
149 * Convert a string representation of a numeric value to a float. The
150 * conversion is strict and will fail if the complete string does not represent
151 * a valid float. The function sets errno according to the details of the
152 * failure.
153 *
154 * @param str The string representation to convert.
155 * @param ret Pointer to float where the result of the conversion will be stored.
156 *
1ba4a1cf
MH
157 * @retval SR_OK Conversion successful.
158 * @retval SR_ERR Failure.
9e4f8cf9
DJ
159 *
160 * @since 0.3.0
161 */
8d558c7a 162SR_PRIV int sr_atof(const char *str, float *ret)
9e4f8cf9
DJ
163{
164 double tmp;
165
166 if (sr_atod(str, &tmp) != SR_OK)
167 return SR_ERR;
168
169 if ((float) tmp != tmp) {
170 errno = ERANGE;
171 return SR_ERR;
172 }
173
174 *ret = (float) tmp;
175 return SR_OK;
176}
177
9806c2d5
DJ
178/**
179 * @private
180 *
181 * Convert a string representation of a numeric value to a float. The
182 * conversion is strict and will fail if the complete string does not represent
183 * a valid float. The function sets errno according to the details of the
184 * failure. This version ignores the locale.
185 *
186 * @param str The string representation to convert.
187 * @param ret Pointer to float where the result of the conversion will be stored.
188 *
1ba4a1cf
MH
189 * @retval SR_OK Conversion successful.
190 * @retval SR_ERR Failure.
9806c2d5
DJ
191 *
192 * @since 0.3.0
193 */
194SR_PRIV int sr_atof_ascii(const char *str, float *ret)
195{
196 double tmp;
197 char *endptr = NULL;
198
199 errno = 0;
200 tmp = g_ascii_strtod(str, &endptr);
201
202 if (!endptr || *endptr || errno) {
203 if (!errno)
204 errno = EINVAL;
205 return SR_ERR;
206 }
207
208 /* FIXME This fails unexpectedly. Some other method to safel downcast
209 * needs to be found. Checking against FLT_MAX doesn't work as well. */
210 /*
211 if ((float) tmp != tmp) {
212 errno = ERANGE;
213 sr_dbg("ERANGEEEE %e != %e", (float) tmp, tmp);
214 return SR_ERR;
215 }
216 */
217
218 *ret = (float) tmp;
219 return SR_OK;
220}
221
25e7d9b1 222/**
b07b42f3
UH
223 * Convert a numeric value value to its "natural" string representation
224 * in SI units.
25e7d9b1 225 *
4cc9aea1
JH
226 * E.g. a value of 3000000, with units set to "W", would be converted
227 * to "3 MW", 20000 to "20 kW", 31500 would become "31.5 kW".
25e7d9b1 228 *
4cc9aea1
JH
229 * @param x The value to convert.
230 * @param unit The unit to append to the string, or NULL if the string
231 * has no units.
44dae539 232 *
133a37bf
UH
233 * @return A g_try_malloc()ed string representation of the samplerate value,
234 * or NULL upon errors. The caller is responsible to g_free() the
235 * memory.
47117241
UH
236 *
237 * @since 0.2.0
25e7d9b1 238 */
4cc9aea1 239SR_API char *sr_si_string_u64(uint64_t x, const char *unit)
25e7d9b1 240{
094e6b81
PS
241 uint8_t i;
242 uint64_t quot, divisor[] = {
b07b42f3
UH
243 SR_HZ(1), SR_KHZ(1), SR_MHZ(1), SR_GHZ(1),
244 SR_GHZ(1000), SR_GHZ(1000 * 1000), SR_GHZ(1000 * 1000 * 1000),
094e6b81
PS
245 };
246 const char *p, prefix[] = "\0kMGTPE";
69d83be9 247 char fmt[16], fract[20] = "", *f;
094e6b81 248
a885ce3e 249 if (unit == NULL)
4cc9aea1 250 unit = "";
25e7d9b1 251
094e6b81
PS
252 for (i = 0; (quot = x / divisor[i]) >= 1000; i++);
253
254 if (i) {
69d83be9 255 sprintf(fmt, ".%%0%d"PRIu64, i * 3);
094e6b81
PS
256 f = fract + sprintf(fract, fmt, x % divisor[i]) - 1;
257
258 while (f >= fract && strchr("0.", *f))
259 *f-- = 0;
133a37bf 260 }
25e7d9b1 261
094e6b81
PS
262 p = prefix + i;
263
264 return g_strdup_printf("%" PRIu64 "%s %.1s%s", quot, fract, p, unit);
4cc9aea1 265}
25e7d9b1 266
4cc9aea1
JH
267/**
268 * Convert a numeric samplerate value to its "natural" string representation.
269 *
270 * E.g. a value of 3000000 would be converted to "3 MHz", 20000 to "20 kHz",
271 * 31500 would become "31.5 kHz".
272 *
273 * @param samplerate The samplerate in Hz.
274 *
275 * @return A g_try_malloc()ed string representation of the samplerate value,
276 * or NULL upon errors. The caller is responsible to g_free() the
277 * memory.
47117241
UH
278 *
279 * @since 0.1.0
4cc9aea1
JH
280 */
281SR_API char *sr_samplerate_string(uint64_t samplerate)
282{
283 return sr_si_string_u64(samplerate, "Hz");
25e7d9b1 284}
2a3f9541 285
2a3f9541 286/**
dfcc0bf9 287 * Convert a numeric frequency value to the "natural" string representation
2a3f9541
BV
288 * of its period.
289 *
2507648e 290 * E.g. a value of 3000000 would be converted to "3 us", 20000 to "50 ms".
2a3f9541
BV
291 *
292 * @param frequency The frequency in Hz.
44dae539 293 *
133a37bf
UH
294 * @return A g_try_malloc()ed string representation of the frequency value,
295 * or NULL upon errors. The caller is responsible to g_free() the
296 * memory.
47117241
UH
297 *
298 * @since 0.1.0
2a3f9541 299 */
1a081ca6 300SR_API char *sr_period_string(uint64_t frequency)
2a3f9541
BV
301{
302 char *o;
303 int r;
304
133a37bf
UH
305 /* Allocate enough for a uint64_t as string + " ms". */
306 if (!(o = g_try_malloc0(30 + 1))) {
a885ce3e 307 sr_err("%s: o malloc failed", __func__);
2a3f9541 308 return NULL;
133a37bf 309 }
2a3f9541 310
59df0c77 311 if (frequency >= SR_GHZ(1))
2a3f9541 312 r = snprintf(o, 30, "%" PRIu64 " ns", frequency / 1000000000);
59df0c77 313 else if (frequency >= SR_MHZ(1))
2507648e 314 r = snprintf(o, 30, "%" PRIu64 " us", frequency / 1000000);
59df0c77 315 else if (frequency >= SR_KHZ(1))
2a3f9541
BV
316 r = snprintf(o, 30, "%" PRIu64 " ms", frequency / 1000);
317 else
318 r = snprintf(o, 30, "%" PRIu64 " s", frequency);
319
320 if (r < 0) {
321 /* Something went wrong... */
133a37bf 322 g_free(o);
2a3f9541
BV
323 return NULL;
324 }
325
326 return o;
327}
40f5ddac 328
79afc8ca 329/**
e0e15067
BV
330 * Convert a numeric voltage value to the "natural" string representation
331 * of its voltage value. The voltage is specified as a rational number's
332 * numerator and denominator.
79afc8ca
BV
333 *
334 * E.g. a value of 300000 would be converted to "300mV", 2 to "2V".
335 *
e0e15067
BV
336 * @param v_p The voltage numerator.
337 * @param v_q The voltage denominator.
79afc8ca
BV
338 *
339 * @return A g_try_malloc()ed string representation of the voltage value,
340 * or NULL upon errors. The caller is responsible to g_free() the
341 * memory.
47117241
UH
342 *
343 * @since 0.2.0
79afc8ca 344 */
e0e15067 345SR_API char *sr_voltage_string(uint64_t v_p, uint64_t v_q)
79afc8ca 346{
79afc8ca 347 int r;
d5a669a9 348 char *o;
79afc8ca
BV
349
350 if (!(o = g_try_malloc0(30 + 1))) {
a885ce3e 351 sr_err("%s: o malloc failed", __func__);
79afc8ca
BV
352 return NULL;
353 }
354
e0e15067
BV
355 if (v_q == 1000)
356 r = snprintf(o, 30, "%" PRIu64 "mV", v_p);
357 else if (v_q == 1)
358 r = snprintf(o, 30, "%" PRIu64 "V", v_p);
79afc8ca 359 else
e0e15067 360 r = snprintf(o, 30, "%gV", (float)v_p / (float)v_q);
79afc8ca
BV
361
362 if (r < 0) {
363 /* Something went wrong... */
364 g_free(o);
365 return NULL;
366 }
367
368 return o;
369}
370
dfcc0bf9 371/**
bf978d35 372 * Parse a trigger specification string.
dfcc0bf9 373 *
9c5332d2
UH
374 * @param sdi The device instance for which the trigger specification is
375 * intended. Must not be NULL. Also, sdi->driver and
376 * sdi->driver->info_get must not be NULL.
bf978d35 377 * @param triggerstring The string containing the trigger specification for
ba7dd8bb 378 * one or more channels of this device. Entries for multiple channels are
bf978d35 379 * comma-separated. Triggers are specified in the form key=value,
ba7dd8bb 380 * where the key is a channel number (or channel name) and the value is
bf978d35
UH
381 * the requested trigger type. Valid trigger types currently
382 * include 'r' (rising edge), 'f' (falling edge), 'c' (any pin value
383 * change), '0' (low value), or '1' (high value).
384 * Example: "1=r,sck=f,miso=0,7=c"
44dae539 385 *
bf978d35
UH
386 * @return Pointer to a list of trigger types (strings), or NULL upon errors.
387 * The pointer list (if non-NULL) has as many entries as the
ba7dd8bb 388 * respective device has channels (all physically available channels,
bf978d35
UH
389 * not just enabled ones). Entries of the list which don't have
390 * a trigger value set in 'triggerstring' are NULL, the other entries
391 * contain the respective trigger type which is requested for the
ba7dd8bb 392 * respective channel (e.g. "r", "c", and so on).
47117241
UH
393 *
394 * @since 0.2.0
dfcc0bf9 395 */
92ae7984 396SR_API char **sr_parse_triggerstring(const struct sr_dev_inst *sdi,
1a081ca6 397 const char *triggerstring)
40f5ddac
BV
398{
399 GSList *l;
003595ac 400 GVariant *gvar;
ba7dd8bb
UH
401 struct sr_channel *ch;
402 int max_channels, channelnum, i;
b7f578be
JH
403 char **tokens, **triggerlist, *trigger, *tc;
404 const char *trigger_types;
40f5ddac
BV
405 gboolean error;
406
ba7dd8bb 407 max_channels = g_slist_length(sdi->channels);
40f5ddac 408 error = FALSE;
b53738ba 409
ba7dd8bb 410 if (!(triggerlist = g_try_malloc0(max_channels * sizeof(char *)))) {
a885ce3e 411 sr_err("%s: triggerlist malloc failed", __func__);
b53738ba
UH
412 return NULL;
413 }
414
8f996b89
ML
415 if (sdi->driver->config_list(SR_CONF_TRIGGER_TYPE,
416 &gvar, sdi, NULL) != SR_OK) {
a885ce3e 417 sr_err("%s: Device doesn't support any triggers.", __func__);
40f5ddac 418 return NULL;
bf978d35 419 }
003595ac 420 trigger_types = g_variant_get_string(gvar, NULL);
40f5ddac 421
ba7dd8bb 422 tokens = g_strsplit(triggerstring, ",", max_channels);
40f5ddac 423 for (i = 0; tokens[i]; i++) {
ba7dd8bb
UH
424 channelnum = -1;
425 for (l = sdi->channels; l; l = l->next) {
426 ch = (struct sr_channel *)l->data;
427 if (ch->enabled
428 && !strncmp(ch->name, tokens[i],
429 strlen(ch->name))) {
430 channelnum = ch->index;
17ff1124 431 break;
40f5ddac 432 }
40f5ddac
BV
433 }
434
ba7dd8bb
UH
435 if (channelnum < 0 || channelnum >= max_channels) {
436 sr_err("Invalid channel.");
40f5ddac
BV
437 error = TRUE;
438 break;
439 }
440
441 if ((trigger = strchr(tokens[i], '='))) {
442 for (tc = ++trigger; *tc; tc++) {
443 if (strchr(trigger_types, *tc) == NULL) {
a885ce3e 444 sr_err("Unsupported trigger "
0aeb0ccd 445 "type '%c'.", *tc);
40f5ddac
BV
446 error = TRUE;
447 break;
448 }
449 }
450 if (!error)
ba7dd8bb 451 triggerlist[channelnum] = g_strdup(trigger);
40f5ddac
BV
452 }
453 }
454 g_strfreev(tokens);
003595ac 455 g_variant_unref(gvar);
40f5ddac
BV
456
457 if (error) {
ba7dd8bb 458 for (i = 0; i < max_channels; i++)
66410a86 459 g_free(triggerlist[i]);
40f5ddac
BV
460 g_free(triggerlist);
461 triggerlist = NULL;
462 }
463
464 return triggerlist;
465}
466
dfcc0bf9
UH
467/**
468 * Convert a "natural" string representation of a size value to uint64_t.
469 *
470 * E.g. a value of "3k" or "3 K" would be converted to 3000, a value
471 * of "15M" would be converted to 15000000.
472 *
473 * Value representations other than decimal (such as hex or octal) are not
474 * supported. Only 'k' (kilo), 'm' (mega), 'g' (giga) suffixes are supported.
475 * Spaces (but not other whitespace) between value and suffix are allowed.
476 *
477 * @param sizestring A string containing a (decimal) size value.
f64c1414 478 * @param size Pointer to uint64_t which will contain the string's size value.
dfcc0bf9 479 *
44dae539 480 * @return SR_OK upon success, SR_ERR upon errors.
47117241
UH
481 *
482 * @since 0.1.0
dfcc0bf9 483 */
1a081ca6 484SR_API int sr_parse_sizestring(const char *sizestring, uint64_t *size)
40f5ddac 485{
f64c1414 486 int multiplier, done;
580f3099 487 double frac_part;
40f5ddac
BV
488 char *s;
489
f64c1414 490 *size = strtoull(sizestring, &s, 10);
40f5ddac 491 multiplier = 0;
580f3099 492 frac_part = 0;
f64c1414
BV
493 done = FALSE;
494 while (s && *s && multiplier == 0 && !done) {
40f5ddac
BV
495 switch (*s) {
496 case ' ':
497 break;
580f3099
DJ
498 case '.':
499 frac_part = g_ascii_strtod(s, &s);
500 break;
40f5ddac
BV
501 case 'k':
502 case 'K':
59df0c77 503 multiplier = SR_KHZ(1);
40f5ddac
BV
504 break;
505 case 'm':
506 case 'M':
59df0c77 507 multiplier = SR_MHZ(1);
40f5ddac
BV
508 break;
509 case 'g':
510 case 'G':
59df0c77 511 multiplier = SR_GHZ(1);
40f5ddac
BV
512 break;
513 default:
f64c1414
BV
514 done = TRUE;
515 s--;
40f5ddac
BV
516 }
517 s++;
518 }
580f3099 519 if (multiplier > 0) {
f64c1414 520 *size *= multiplier;
580f3099
DJ
521 *size += frac_part * multiplier;
522 } else
523 *size += frac_part;
40f5ddac 524
f64c1414
BV
525 if (*s && strcasecmp(s, "Hz"))
526 return SR_ERR;
527
528 return SR_OK;
40f5ddac
BV
529}
530
dfcc0bf9
UH
531/**
532 * Convert a "natural" string representation of a time value to an
533 * uint64_t value in milliseconds.
534 *
535 * E.g. a value of "3s" or "3 s" would be converted to 3000, a value
536 * of "15ms" would be converted to 15.
537 *
538 * Value representations other than decimal (such as hex or octal) are not
539 * supported. Only lower-case "s" and "ms" time suffixes are supported.
540 * Spaces (but not other whitespace) between value and suffix are allowed.
541 *
542 * @param timestring A string containing a (decimal) time value.
543 * @return The string's time value as uint64_t, in milliseconds.
544 *
6b2d8d3e
UH
545 * @todo Add support for "m" (minutes) and others.
546 * @todo Add support for picoseconds?
547 * @todo Allow both lower-case and upper-case? If no, document it.
47117241
UH
548 *
549 * @since 0.1.0
dfcc0bf9 550 */
1a081ca6 551SR_API uint64_t sr_parse_timestring(const char *timestring)
40f5ddac
BV
552{
553 uint64_t time_msec;
554 char *s;
555
6b2d8d3e
UH
556 /* TODO: Error handling, logging. */
557
40f5ddac
BV
558 time_msec = strtoull(timestring, &s, 10);
559 if (time_msec == 0 && s == timestring)
560 return 0;
561
562 if (s && *s) {
563 while (*s == ' ')
564 s++;
565 if (!strcmp(s, "s"))
566 time_msec *= 1000;
567 else if (!strcmp(s, "ms"))
568 ; /* redundant */
569 else
570 return 0;
571 }
572
573 return time_msec;
574}
4d436e71 575
47117241 576/** @since 0.1.0 */
1a081ca6 577SR_API gboolean sr_parse_boolstring(const char *boolstr)
4d436e71
GM
578{
579 if (!boolstr)
580 return FALSE;
581
993526f8
BV
582 if (!g_ascii_strncasecmp(boolstr, "true", 4) ||
583 !g_ascii_strncasecmp(boolstr, "yes", 3) ||
584 !g_ascii_strncasecmp(boolstr, "on", 2) ||
585 !g_ascii_strncasecmp(boolstr, "1", 1))
4d436e71
GM
586 return TRUE;
587
588 return FALSE;
589}
76f4c610 590
47117241 591/** @since 0.2.0 */
76e107d6 592SR_API int sr_parse_period(const char *periodstr, uint64_t *p, uint64_t *q)
76f4c610
BV
593{
594 char *s;
595
76e107d6
BV
596 *p = strtoull(periodstr, &s, 10);
597 if (*p == 0 && s == periodstr)
76f4c610
BV
598 /* No digits found. */
599 return SR_ERR_ARG;
600
601 if (s && *s) {
602 while (*s == ' ')
603 s++;
8c012adb 604 if (!strcmp(s, "fs"))
76e107d6 605 *q = 1000000000000000ULL;
8c012adb 606 else if (!strcmp(s, "ps"))
76e107d6 607 *q = 1000000000000ULL;
8c012adb 608 else if (!strcmp(s, "ns"))
76e107d6 609 *q = 1000000000ULL;
76f4c610 610 else if (!strcmp(s, "us"))
76e107d6 611 *q = 1000000;
76f4c610 612 else if (!strcmp(s, "ms"))
76e107d6 613 *q = 1000;
76f4c610 614 else if (!strcmp(s, "s"))
76e107d6 615 *q = 1;
76f4c610
BV
616 else
617 /* Must have a time suffix. */
618 return SR_ERR_ARG;
619 }
620
621 return SR_OK;
622}
623
47117241 624/** @since 0.2.0 */
76e107d6 625SR_API int sr_parse_voltage(const char *voltstr, uint64_t *p, uint64_t *q)
79afc8ca
BV
626{
627 char *s;
628
76e107d6
BV
629 *p = strtoull(voltstr, &s, 10);
630 if (*p == 0 && s == voltstr)
79afc8ca
BV
631 /* No digits found. */
632 return SR_ERR_ARG;
633
634 if (s && *s) {
635 while (*s == ' ')
636 s++;
637 if (!strcasecmp(s, "mv"))
76e107d6 638 *q = 1000L;
79afc8ca 639 else if (!strcasecmp(s, "v"))
76e107d6 640 *q = 1;
79afc8ca
BV
641 else
642 /* Must have a base suffix. */
643 return SR_ERR_ARG;
644 }
645
646 return SR_OK;
647}
648
7b870c38 649/** @} */