/src/ntp-dev/ntpd/rc_cmdlength.c
Line | Count | Source (jump to first uncovered line) |
1 | | #include <config.h> |
2 | | #include <rc_cmdlength.h> |
3 | | |
4 | | #if HAVE_UNISTD_H |
5 | | # include <unistd.h> |
6 | | #endif |
7 | | |
8 | | // XXX: Move to header. |
9 | | size_t remoteconfig_cmdlength( const char *, const char *); |
10 | | |
11 | | /* Bug 2853 */ |
12 | | /* evaluate the length of the command sequence. This breaks at the first |
13 | | * char that is not >= SPACE and <= 127 after trimming from the right. |
14 | | */ |
15 | | size_t |
16 | | remoteconfig_cmdlength( |
17 | | const char *src_buf, |
18 | | const char *src_end |
19 | | ) |
20 | 0 | { |
21 | 0 | const char *scan; |
22 | 0 | unsigned char ch; |
23 | | |
24 | | /* trim whitespace & garbage from the right */ |
25 | 0 | while (src_end != src_buf) { |
26 | 0 | ch = src_end[-1]; |
27 | 0 | if (ch > ' ' && ch < 128) |
28 | 0 | break; |
29 | 0 | --src_end; |
30 | 0 | } |
31 | | /* now do a forward scan */ |
32 | 0 | for (scan = src_buf; scan != src_end; ++scan) { |
33 | 0 | ch = scan[0]; |
34 | 0 | if ((ch < ' ' || ch >= 128) && ch != '\t') |
35 | 0 | break; |
36 | 0 | } |
37 | 0 | return (size_t)(scan - src_buf); |
38 | 0 | } |