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