Debian Codegraph @

upstream/debian-trixie/man3/strnlen.3

raw
1 '\" t
2 .\" Copyright (c) Bruno Haible <[email protected]>
3 .\"
4 .\" SPDX-License-Identifier: GPL-2.0-or-later
5 .\"
6 .\" References consulted:
7 .\" GNU glibc-2 source code and manual
8 .\"
9 .TH strnlen 3 2024-06-15 "Linux man-pages 6.9.1"
10 .SH NAME
11 strnlen \- determine the length of a fixed-size string
12 .SH LIBRARY
13 Standard C library
14 .RI ( libc ", " \-lc )
15 .SH SYNOPSIS
16 .nf
17 .B #include <string.h>
18 .P
19 .BI "size_t strnlen(const char " s [. maxlen "], size_t " maxlen );
20 .fi
21 .P
22 .RS -4
23 Feature Test Macro Requirements for glibc (see
24 .BR feature_test_macros (7)):
25 .RE
26 .P
27 .BR strnlen ():
28 .nf
29 Since glibc 2.10:
30 _POSIX_C_SOURCE >= 200809L
31 Before glibc 2.10:
32 _GNU_SOURCE
33 .fi
34 .SH DESCRIPTION
35 The
36 .BR strnlen ()
37 function returns the number of bytes in the string
38 pointed to by
39 .IR s ,
40 excluding the terminating null byte (\[aq]\[rs]0\[aq]),
41 but at most
42 .IR maxlen .
43 In doing this,
44 .BR strnlen ()
45 looks only at the first
46 .I maxlen
47 characters in the string pointed to by
48 .I s
49 and never beyond
50 .IR s[maxlen\-1] .
51 .SH RETURN VALUE
52 The
53 .BR strnlen ()
54 function returns
55 .IR strlen(s) ,
56 if that is less than
57 .IR maxlen ,
58 or
59 .I maxlen
60 if there is no null terminating (\[aq]\[rs]0\[aq]) among the first
61 .I maxlen
62 characters pointed to by
63 .IR s .
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 strnlen ()
76 T} Thread safety MT-Safe
77 .TE
78 .SH STANDARDS
79 POSIX.1-2008.
80 .SH HISTORY
81 POSIX.1-2008.
82 .SH SEE ALSO
83 .BR strlen (3)