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