1STRNCPY(3P)                POSIX Programmer's Manual               STRNCPY(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

NAME

12       stpncpy, strncpy — copy fixed length string, returning a pointer to the
13       array end
14

SYNOPSIS

16       #include <string.h>
17
18       char *stpncpy(char *restrict s1, const char *restrict s2, size_t n);
19       char *strncpy(char *restrict s1, const char *restrict s2, size_t n);
20

DESCRIPTION

22       For  strncpy():  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‐2017 defers to the ISO C standard.
26
27       The stpncpy() and strncpy() functions shall copy not more than n  bytes
28       (bytes  that  follow  a  NUL  character  are not copied) from the array
29       pointed to by s2 to the array pointed to by s1.
30
31       If the array pointed to by s2 is a string that is shorter than n bytes,
32       NUL characters shall be appended to the copy in the array pointed to by
33       s1, until n bytes in all are written.
34
35       If copying takes place between objects that overlap,  the  behavior  is
36       undefined.
37

RETURN VALUE

39       If  a  NUL character is written to the destination, the stpncpy() func‐
40       tion shall return the address of the first such NUL character.   Other‐
41       wise, it shall return &s1[n].
42
43       The strncpy() function shall return s1.
44
45       No return values are reserved to indicate an error.
46

ERRORS

48       No errors are defined.
49
50       The following sections are informative.
51

EXAMPLES

53       None.
54

APPLICATION USAGE

56       Applications  must provide the space in s1 for the n bytes to be trans‐
57       ferred, as well as ensure that the s2 and s1 arrays do not overlap.
58
59       Character movement is performed differently  in  different  implementa‐
60       tions. Thus, overlapping moves may yield surprises.
61
62       If  there  is  no  NUL character byte in the first n bytes of the array
63       pointed to by s2, the result is not null-terminated.
64

RATIONALE

66       None.
67

FUTURE DIRECTIONS

69       None.
70

SEE ALSO

72       strcpy(), wcsncpy()
73
74       The Base Definitions volume of POSIX.1‐2017, <string.h>
75
77       Portions of this text are reprinted and reproduced in  electronic  form
78       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
79       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
80       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
81       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
82       event of any discrepancy between this version and the original IEEE and
83       The Open Group Standard, the original IEEE and The Open Group  Standard
84       is  the  referee document. The original Standard can be obtained online
85       at http://www.opengroup.org/unix/online.html .
86
87       Any typographical or formatting errors that appear  in  this  page  are
88       most likely to have been introduced during the conversion of the source
89       files to man page format. To report such errors,  see  https://www.ker
90       nel.org/doc/man-pages/reporting_bugs.html .
91
92
93
94IEEE/The Open Group                  2017                          STRNCPY(3P)
Impressum