1STRCPY(3P)                 POSIX Programmer's Manual                STRCPY(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       stpcpy, strcpy — copy a string and return a pointer to the end  of  the
14       result
15

SYNOPSIS

17       #include <string.h>
18
19       char *stpcpy(char *restrict s1, const char *restrict s2);
20       char *strcpy(char *restrict s1, const char *restrict s2);
21

DESCRIPTION

23       For  strcpy():  The  functionality  described on this reference page is
24       aligned with the ISO C standard. Any conflict between the  requirements
25       described  here and the ISO C standard is unintentional. This volume of
26       POSIX.1‐2008 defers to the ISO C standard.
27
28       The stpcpy() and strcpy() functions shall copy the string pointed to by
29       s2  (including the terminating NUL character) into the array pointed to
30       by s1.
31
32       If copying takes place between objects that overlap,  the  behavior  is
33       undefined.
34

RETURN VALUE

36       The  stpcpy()  function  shall  return a pointer to the terminating NUL
37       character copied into the s1 buffer.
38
39       The strcpy() function shall return s1.
40
41       No return values are reserved to indicate an error.
42

ERRORS

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

EXAMPLES

49   Construction of a Multi-Part Message in a Single Buffer
50           #include <string.h>
51           #include <stdio.h>
52
53           int
54           main (void)
55           {
56               char buffer [10];
57               char *name = buffer;
58
59               name = stpcpy (stpcpy (stpcpy (name, "ice"),"-"), "cream");
60               puts (buffer);
61               return 0;
62           }
63
64   Initializing a String
65       The  following  example  copies  the  string  "----------"   into   the
66       permstring variable.
67
68           #include <string.h>
69           ...
70           static char permstring[11];
71           ...
72           strcpy(permstring, "----------");
73           ...
74
75   Storing a Key and Data
76       The  following  example  allocates  space for a key using malloc() then
77       uses strcpy() to place the key there. Then it allocates space for  data
78       using  malloc(),  and  uses  strcpy()  to  place data there. (The user-
79       defined function dbfree() frees memory previously allocated to an array
80       of type struct element *.)
81
82           #include <string.h>
83           #include <stdlib.h>
84           #include <stdio.h>
85           ...
86           /* Structure used to read data and store it. */
87           struct element {
88               char *key;
89               char *data;
90           };
91
92           struct element *tbl, *curtbl;
93           char *key, *data;
94           int count;
95           ...
96           void dbfree(struct element *, int);
97           ...
98           if ((curtbl->key = malloc(strlen(key) + 1)) == NULL) {
99               perror("malloc"); dbfree(tbl, count); return NULL;
100           }
101           strcpy(curtbl->key, key);
102
103           if ((curtbl->data = malloc(strlen(data) + 1)) == NULL) {
104               perror("malloc"); free(curtbl->key); dbfree(tbl, count); return NULL;
105           }
106           strcpy(curtbl->data, data);
107           ...
108

APPLICATION USAGE

110       Character  movement  is  performed differently in different implementa‐
111       tions. Thus, overlapping moves may yield surprises.
112
113       This version is aligned with the ISO C standard; this does  not  affect
114       compatibility  with XPG3 applications. Reliable error detection by this
115       function was never guaranteed.
116

RATIONALE

118       None.
119

FUTURE DIRECTIONS

121       None.
122

SEE ALSO

124       strncpy(), wcscpy()
125
126       The Base Definitions volume of POSIX.1‐2008, <string.h>
127
129       Portions of this text are reprinted and reproduced in  electronic  form
130       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
131       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
132       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
133       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
134       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
135       event of any discrepancy between this version and the original IEEE and
136       The  Open Group Standard, the original IEEE and The Open Group Standard
137       is the referee document. The original Standard can be  obtained  online
138       at http://www.unix.org/online.html .
139
140       Any  typographical  or  formatting  errors that appear in this page are
141       most likely to have been introduced during the conversion of the source
142       files  to  man page format. To report such errors, see https://www.ker
143       nel.org/doc/man-pages/reporting_bugs.html .
144
145
146
147IEEE/The Open Group                  2013                           STRCPY(3P)
Impressum