Debian Codegraph @

upstream/mageia-cauldron/man3/strnlen.3

raw
1 '\" t
2 .\" Copyright, Bruno Haible <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: GPL-2.0-or-later
6 .\"
7 .TH strnlen 3 2026-02-08 "Linux man-pages 6.17"
8 .SH NAME
9 strnlen \- determine the length of a fixed-size string
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .B #include <string.h>
16 .P
17 .BR "size_t strnlen(const char " s "[], size_t " maxlen );
18 .fi
19 .P
20 .RS -4
21 Feature Test Macro Requirements for glibc (see
22 .BR feature_test_macros (7)):
23 .RE
24 .P
25 .BR strnlen ():
26 .nf
27 Since glibc 2.10:
28 _POSIX_C_SOURCE >= 200809L
29 Before glibc 2.10:
30 _GNU_SOURCE
31 .fi
32 .SH DESCRIPTION
33 The
34 .BR strnlen ()
35 function returns the number of bytes in the string
36 pointed to by
37 .IR s ,
38 excluding the terminating null byte (\[aq]\[rs]0\[aq]),
39 but at most
40 .IR maxlen .
41 In doing this,
42 .BR strnlen ()
43 looks only at the first
44 .I maxlen
45 characters in the string pointed to by
46 .I s
47 and never beyond
48 .IR s[maxlen\-1] .
49 .SH RETURN VALUE
50 The
51 .BR strnlen ()
52 function returns
53 .IR strlen(s) ,
54 if that is less than
55 .IR maxlen ,
56 or
57 .I maxlen
58 if there is no null terminating (\[aq]\[rs]0\[aq]) among the first
59 .I maxlen
60 characters pointed to by
61 .IR s .
62 .SH ATTRIBUTES
63 For an explanation of the terms used in this section, see
64 .BR attributes (7).
65 .TS
66 allbox;
67 lbx lb lb
68 l l l.
69 Interface Attribute Value
70 T{
71 .na
72 .nh
73 .BR strnlen ()
74 T} Thread safety MT-Safe
75 .TE
76 .SH STANDARDS
77 POSIX.1-2008.
78 .SH HISTORY
79 POSIX.1-2008.
80 .SH SEE ALSO
81 .BR strlen (3)