'\" t .\" Copyright, Bruno Haible .\" Copyright, the authors of the Linux man-pages project .\" .\" SPDX-License-Identifier: GPL-2.0-or-later .\" .TH strnlen 3 2026-08-10 "Linux man-pages 6.19" .SH NAME strnlen \- nonstring length .SH LIBRARY Standard C library .RI ( libc ,\~ \-lc ) .SH SYNOPSIS .nf .BR #include\~ " // see memory.h(3head)" .P .BR "size_t strnlen(const char " strn "[], size_t " n ); .fi .P .RS -4 Feature Test Macro Requirements for glibc (see .BR feature_test_macros (7)): .RE .P .BR strnlen (): .nf Since glibc 2.10: _POSIX_C_SOURCE >= 200809L Before glibc 2.10: _GNU_SOURCE .fi .SH DESCRIPTION This function determines the length of the character sequence contained in the array pointed to by .IR strn . .P If .I strn contains a string, the array can have less than .I n elements. .P It is equivalent to .P .in +4n .EX (memchr(strn, \[aq]\[rs]0\[aq], n) ?: strn + n) - strn .EE .in .SH RETURN VALUE The .BR strnlen () function returns the number of nonnull characters in .IR strn . .SH ATTRIBUTES For an explanation of the terms used in this section, see .BR attributes (7). .TS allbox; lbx lb lb l l l. Interface Attribute Value T{ .na .nh .BR strnlen () T} Thread safety MT-Safe .TE .SH STANDARDS POSIX.1-2008. .SH HISTORY POSIX.1-2008. .SH SEE ALSO .BR memory.h (3head)