]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/ntpd/rc_cmdlength.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / ntp / ntpd / rc_cmdlength.c
1 #include <config.h>
2
3 #if HAVE_UNISTD_H
4 # include <unistd.h>
5 #endif
6
7
8 /* Bug 2853 */
9 /* evaluate the length of the command sequence. This breaks at the first
10  * char that is not >= SPACE and <= 127 after trimming from the right.
11  */
12 size_t
13 remoteconfig_cmdlength(
14         const char *src_buf,
15         const char *src_end
16         )
17 {
18         const char *scan;
19         unsigned char ch;
20
21         /* trim whitespace & garbage from the right */
22         while (src_end != src_buf) {
23                 ch = src_end[-1];
24                 if (ch > ' ' && ch < 128)
25                         break;
26                 --src_end;
27         }
28         /* now do a forward scan */
29         for (scan = src_buf; scan != src_end; ++scan) {
30                 ch = scan[0];
31                 if ((ch < ' ' || ch >= 128) && ch != '\t')
32                         break;
33         }
34         return (size_t)(scan - src_buf);
35 }