STRLEN(3P)
π STRLEN(3P) β POSIX Programmer's Manual π
okay so bestie, this is strlen and strnlen, and they're literally just here to tell you how long your strings are. no drama, no cap. but FIRST, a lil heads up π
πΈ PROLOG πΈ
so like, this manual page is part of the POSIX Programmer's Manual. meaning: the Linux implementation of this interface may differ (so pls go check the corresponding Linux manual page for details on Linux behavior), or honestly the interface might not even be implemented on Linux at all. π just a vibe check before we go any further.
β¨ NAME β¨
strlen, strnlen β get length of fixed size string π
π SYNOPSIS π
#include <string.h>
size_t strlen(const char *s);
size_t strnlen(const char *s, size_t maxlen);
π¦ DESCRIPTION π¦
okay so for strlen(): the functionality described on this reference page is aligned with the ISO C standard. if there's any conflict between what's written here and the ISO C standard, that conflict is unintentional β no bad blood. this volume of POSIX.1β2017 defers to the ISO C standard, periodt.
the strlen() function shall compute the number of bytes in the string to which s points, not including the terminating NUL character. that's it. that's the whole job. iconic behavior honestly π
the strnlen() function shall compute the smaller of:
- the number of bytes in the array to which
spoints, not including any terminating NUL character, or - the value of the
maxlenargument.
and the strnlen() function shall never examine more than maxlen bytes of the array pointed to by s. she knows her limits, and she respects them. π§
π RETURN VALUE π
strlen() shall return the length of s. and listen β no return value shall be reserved to indicate an error. so if something's wrong, she's not telling you. she simply does not do error reports. π
strnlen() shall return the number of bytes preceding the first null byte in the array to which s points, if s contains a null byte within the first maxlen bytes; otherwise, it shall return maxlen. simple as that fr fr.
π ERRORS π
No errors are defined. literally none. she's unbothered. unproblematic. β¨
also the following sections are informative (iykyk, they're the bonus lore):
π EXAMPLES π
πΈ Getting String Lengths πΈ
the following example sets the maximum length of key and data by using strlen() to get the lengths of those strings. look at her go:
#include <string.h>
...
struct element {
char *key;
char *data;
};
...
char *key, *data;
int len;
*keylength = *datalength = 0;
...
if ((len = strlen(key)) > *keylength)
*keylength = len;
if ((len = strlen(data)) > *datalength)
*datalength = len;
...
β APPLICATION USAGE β
None. nothing to add, bestie. we said what we said. π
π«Ά RATIONALE π«Ά
None. no reasoning needed when you're simply correct. π
π§ FUTURE DIRECTIONS π§
None. the future is bright and this function is not changing. slay.
π₯ SEE ALSO π₯
wcslen()- the Base Definitions volume of POSIX.1β2017,
<string.h>
π COPYRIGHT π
portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.
in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. so like, if they disagree, the original wins, no arguments. π«‘ the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
aaaand that's the whole page bestie!! brought to you by IEEE/The Open Group, dated 2017, living under the nameSTRLEN(3P). go measure some strings, stay safe, and remember:strnlenwill literally never look pastmaxlenbytes. obsessed with her boundaries fr. πβ¨π
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms