summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorray <>2007-08-08 07:20:45 +0000
committerray <>2007-08-08 07:20:45 +0000
commit802dd8da00080309633c1595570521a4b19ea938 (patch)
tree6f00e1081a6628431f6f354c9a2fd53425a7cfba /src/lib
parent066678a9abd4d902e555bec4e2e68192b477baba (diff)
downloadopenbsd-802dd8da00080309633c1595570521a4b19ea938.tar.gz
openbsd-802dd8da00080309633c1595570521a4b19ea938.tar.bz2
openbsd-802dd8da00080309633c1595570521a4b19ea938.zip
Show how to use strcspn(3) to trim newlines.
OK jmc and millert.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libc/string/strcspn.316
1 files changed, 14 insertions, 2 deletions
diff --git a/src/lib/libc/string/strcspn.3 b/src/lib/libc/string/strcspn.3
index c5d9e562d2..21c727344d 100644
--- a/src/lib/libc/string/strcspn.3
+++ b/src/lib/libc/string/strcspn.3
@@ -29,9 +29,9 @@
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE. 30.\" SUCH DAMAGE.
31.\" 31.\"
32.\" $OpenBSD: strcspn.3,v 1.8 2007/05/31 19:19:32 jmc Exp $ 32.\" $OpenBSD: strcspn.3,v 1.9 2007/08/08 07:20:45 ray Exp $
33.\" 33.\"
34.Dd $Mdocdate: May 31 2007 $ 34.Dd $Mdocdate: August 8 2007 $
35.Dt STRCSPN 3 35.Dt STRCSPN 3
36.Os 36.Os
37.Sh NAME 37.Sh NAME
@@ -72,6 +72,18 @@ size_t span;
72 72
73span = strcspn(s, charset); 73span = strcspn(s, charset);
74.Ed 74.Ed
75.Pp
76The following removes the first (if any) newline character from string
77.Fa line .
78This is useful for trimming the newline after a
79.Xr fgets 3
80call.
81.Bd -literal -offset indent
82char line[BUFSIZ];
83
84if (fgets(line, sizeof(line), fp) != NULL)
85 line[strcspn(line, "\en")] = '\e0';
86.Ed
75.Sh SEE ALSO 87.Sh SEE ALSO
76.Xr memchr 3 , 88.Xr memchr 3 ,
77.Xr strchr 3 , 89.Xr strchr 3 ,