1 /* $NetBSD: trimblanks.c,v 1.2 2017/02/14 01:16:49 christos Exp $ */ 2 3 /*++ 4 /* NAME 5 /* trimblanks 3 6 /* SUMMARY 7 /* skip leading whitespace 8 /* SYNOPSIS 9 /* #include <stringops.h> 10 /* 11 /* char *trimblanks(string, len) 12 /* char *string; 13 /* ssize_t len; 14 /* DESCRIPTION 15 /* trimblanks() returns a pointer to the beginning of the trailing 16 /* whitespace in \fIstring\fR, or a pointer to the string terminator 17 /* when the string contains no trailing whitespace. 18 /* The \fIlen\fR argument is either zero or the string length. 19 /* LICENSE 20 /* .ad 21 /* .fi 22 /* The Secure Mailer license must be distributed with this software. 23 /* AUTHOR(S) 24 /* Wietse Venema 25 /* IBM T.J. Watson Research 26 /* P.O. Box 704 27 /* Yorktown Heights, NY 10598, USA 28 /*--*/ 29 30 /* System library. */ 31 32 #include "sys_defs.h" 33 #include <ctype.h> 34 35 /* Utility library. */ 36 37 #include "stringops.h" 38 39 char *trimblanks(char *string, ssize_t len) 40 { 41 char *curr; 42 43 if (len) { 44 curr = string + len; 45 } else { 46 for (curr = string; *curr != 0; curr++) 47 /* void */ ; 48 } 49 while (curr > string && ISSPACE(curr[-1])) 50 curr -= 1; 51 return (curr); 52 } 53