| 1 |
'\" t |
| 2 |
.\" Copyright 1993, David Metcalfe <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 6 |
.\" |
| 7 |
.TH strspn 3 2026-02-25 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
strspn, strcspn \- get length of a prefix substring |
| 10 |
.SH LIBRARY |
| 11 |
Standard C library |
| 12 |
.RI ( libc ,\~ \-lc ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B #include <string.h> |
| 16 |
.P |
| 17 |
.BI "size_t strspn(const char *" s ", const char *" accept ); |
| 18 |
.BI "size_t strcspn(const char *" s ", const char *" reject ); |
| 19 |
.fi |
| 20 |
.SH DESCRIPTION |
| 21 |
.TP |
| 22 |
.BR strspn () |
| 23 |
The |
| 24 |
.BR strspn () |
| 25 |
function calculates the length (in bytes) of the initial |
| 26 |
segment of |
| 27 |
.I s |
| 28 |
which consists entirely of bytes in |
| 29 |
.IR accept . |
| 30 |
.TP |
| 31 |
.BR strcspn () |
| 32 |
The |
| 33 |
.BR strcspn () |
| 34 |
function calculates the length of the initial |
| 35 |
segment of |
| 36 |
.I s |
| 37 |
which consists entirely of bytes not in |
| 38 |
.IR reject . |
| 39 |
.IP |
| 40 |
It is equivalent to |
| 41 |
.IP |
| 42 |
.in +4n |
| 43 |
.EX |
| 44 |
(strpbrk(s, reject) ?: strnul(s)) - s |
| 45 |
.EE |
| 46 |
.in |
| 47 |
.SH RETURN VALUE |
| 48 |
The |
| 49 |
.BR strspn () |
| 50 |
function returns the number of bytes in |
| 51 |
the initial segment of |
| 52 |
.I s |
| 53 |
which consist only of bytes |
| 54 |
from |
| 55 |
.IR accept . |
| 56 |
.P |
| 57 |
The |
| 58 |
.BR strcspn () |
| 59 |
function returns the number of bytes in |
| 60 |
the initial segment of |
| 61 |
.I s |
| 62 |
which are not in the string |
| 63 |
.IR reject . |
| 64 |
.SH ATTRIBUTES |
| 65 |
For an explanation of the terms used in this section, see |
| 66 |
.BR attributes (7). |
| 67 |
.TS |
| 68 |
allbox; |
| 69 |
lbx lb lb |
| 70 |
l l l. |
| 71 |
Interface Attribute Value |
| 72 |
T{ |
| 73 |
.na |
| 74 |
.nh |
| 75 |
.BR strspn (), |
| 76 |
.BR strcspn () |
| 77 |
T} Thread safety MT-Safe |
| 78 |
.TE |
| 79 |
.SH STANDARDS |
| 80 |
C11, POSIX.1-2008. |
| 81 |
.SH HISTORY |
| 82 |
POSIX.1-2001, C89, SVr4, 4.3BSD. |
| 83 |
.SH SEE ALSO |
| 84 |
.BR memchr (3), |
| 85 |
.BR strchr (3), |
| 86 |
.BR string (3), |
| 87 |
.BR strpbrk (3), |
| 88 |
.BR strsep (3), |
| 89 |
.BR strstr (3), |
| 90 |
.BR strtok (3), |
| 91 |
.BR wcscspn (3), |
| 92 |
.BR wcsspn (3) |