1STRLEN(3P)                 POSIX Programmer's Manual                STRLEN(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       strlen, strnlen — get length of fixed size string
14

SYNOPSIS

16       #include <string.h>
17
18       size_t strlen(const char *s);
19       size_t strnlen(const char *s, size_t maxlen);
20

DESCRIPTION

22       For strlen(): The functionality described on  this  reference  page  is
23       aligned  with the ISO C standard. Any conflict between the requirements
24       described here and the ISO C standard is unintentional. This volume  of
25       POSIX.1‐2008 defers to the ISO C standard.
26
27       The  strlen()  function shall compute the number of bytes in the string
28       to which s points, not including the terminating NUL character.
29
30       The strnlen() function shall compute the smaller of the number of bytes
31       in the array to which s points, not including the terminating NUL char‐
32       acter, or the value of the  maxlen  argument.  The  strnlen()  function
33       shall  never  examine more than maxlen bytes of the array pointed to by
34       s.
35

RETURN VALUE

37       The strlen() function shall return the length of  s;  no  return  value
38       shall be reserved to indicate an error.
39
40       The  strnlen()  function shall return an integer containing the smaller
41       of either the length of the string pointed to by s or maxlen.
42

ERRORS

44       No errors are defined.
45
46       The following sections are informative.
47

EXAMPLES

49   Getting String Lengths
50       The following example sets the maximum length of key and data by  using
51       strlen() to get the lengths of those strings.
52
53           #include <string.h>
54           ...
55           struct element {
56               char *key;
57               char *data;
58           };
59           ...
60           char *key, *data;
61           int len;
62
63           *keylength = *datalength = 0;
64           ...
65           if ((len = strlen(key)) > *keylength)
66               *keylength = len;
67           if ((len = strlen(data)) > *datalength)
68               *datalength = len;
69           ...
70

APPLICATION USAGE

72       None.
73

RATIONALE

75       None.
76

FUTURE DIRECTIONS

78       None.
79

SEE ALSO

81       wcslen()
82
83       The Base Definitions volume of POSIX.1‐2008, <string.h>
84
86       Portions  of  this text are reprinted and reproduced in electronic form
87       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
88       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
89       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
90       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
91       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
92       event of any discrepancy between this version and the original IEEE and
93       The Open Group Standard, the original IEEE and The Open Group  Standard
94       is  the  referee document. The original Standard can be obtained online
95       at http://www.unix.org/online.html .
96
97       Any typographical or formatting errors that appear  in  this  page  are
98       most likely to have been introduced during the conversion of the source
99       files to man page format. To report such errors,  see  https://www.ker
100       nel.org/doc/man-pages/reporting_bugs.html .
101
102
103
104IEEE/The Open Group                  2013                           STRLEN(3P)
Impressum