1284990Scy#include <config.h>
2289764Sglebius#include <rc_cmdlength.h>
3284990Scy
4284990Scy#if HAVE_UNISTD_H
5284990Scy# include <unistd.h>
6284990Scy#endif
7284990Scy
8338530Sdelphij// XXX: Move to header.
9338530Sdelphijsize_t remoteconfig_cmdlength( const char *, const char *);
10284990Scy
11284990Scy/* Bug 2853 */
12284990Scy/* evaluate the length of the command sequence. This breaks at the first
13284990Scy * char that is not >= SPACE and <= 127 after trimming from the right.
14284990Scy */
15284990Scysize_t
16284990Scyremoteconfig_cmdlength(
17284990Scy	const char *src_buf,
18284990Scy	const char *src_end
19284990Scy	)
20284990Scy{
21284990Scy	const char *scan;
22284990Scy	unsigned char ch;
23284990Scy
24284990Scy	/* trim whitespace & garbage from the right */
25284990Scy	while (src_end != src_buf) {
26284990Scy		ch = src_end[-1];
27284990Scy		if (ch > ' ' && ch < 128)
28284990Scy			break;
29284990Scy		--src_end;
30284990Scy	}
31284990Scy	/* now do a forward scan */
32284990Scy	for (scan = src_buf; scan != src_end; ++scan) {
33284990Scy		ch = scan[0];
34284990Scy		if ((ch < ' ' || ch >= 128) && ch != '\t')
35284990Scy			break;
36284990Scy	}
37284990Scy	return (size_t)(scan - src_buf);
38284990Scy}
39