logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

strcpy.3p (4414B)


  1. '\" et
  2. .TH STRCPY "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. stpcpy, strcpy
  12. \(em copy a string and return a pointer to the end of the result
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <string.h>
  17. .P
  18. char *stpcpy(char *restrict \fIs1\fP, const char *restrict \fIs2\fP);
  19. char *strcpy(char *restrict \fIs1\fP, const char *restrict \fIs2\fP);
  20. .fi
  21. .SH DESCRIPTION
  22. For
  23. \fIstrcpy\fR():
  24. The functionality described on this reference page is aligned with the
  25. ISO\ C standard. Any conflict between the requirements described here and the
  26. ISO\ C standard is unintentional. This volume of POSIX.1\(hy2017 defers to the ISO\ C standard.
  27. .P
  28. The
  29. \fIstpcpy\fR()
  30. and
  31. \fIstrcpy\fR()
  32. functions shall copy the string pointed to by
  33. .IR s2
  34. (including the terminating NUL character) into the array pointed to by
  35. .IR s1 .
  36. .P
  37. If copying takes place between objects that overlap, the behavior is
  38. undefined.
  39. .SH "RETURN VALUE"
  40. The
  41. \fIstpcpy\fR()
  42. function shall return a pointer to the terminating NUL character copied
  43. into the
  44. .IR s1
  45. buffer.
  46. .P
  47. The
  48. \fIstrcpy\fR()
  49. function shall return
  50. .IR s1 .
  51. .P
  52. No return values are reserved to indicate an error.
  53. .SH ERRORS
  54. No errors are defined.
  55. .LP
  56. .IR "The following sections are informative."
  57. .SH EXAMPLES
  58. .SS "Construction of a Multi-Part Message in a Single Buffer"
  59. .sp
  60. .RS 4
  61. .nf
  62. #include <string.h>
  63. #include <stdio.h>
  64. .P
  65. int
  66. main (void)
  67. {
  68. char buffer [10];
  69. char *name = buffer;
  70. .P
  71. name = stpcpy (stpcpy (stpcpy (name, "ice"),"-"), "cream");
  72. puts (buffer);
  73. return 0;
  74. }
  75. .fi
  76. .P
  77. .RE
  78. .SS "Initializing a String"
  79. .P
  80. The following example copies the string
  81. .BR \(dq----------\(dq
  82. into the
  83. .IR permstring
  84. variable.
  85. .sp
  86. .RS 4
  87. .nf
  88. #include <string.h>
  89. \&...
  90. static char permstring[11];
  91. \&...
  92. strcpy(permstring, "----------");
  93. \&...
  94. .fi
  95. .P
  96. .RE
  97. .SS "Storing a Key and Data"
  98. .P
  99. The following example allocates space for a key using
  100. \fImalloc\fR()
  101. then uses
  102. \fIstrcpy\fR()
  103. to place the key there. Then it allocates space for data using
  104. \fImalloc\fR(),
  105. and uses
  106. \fIstrcpy\fR()
  107. to place data there. (The user-defined function
  108. \fIdbfree\fR()
  109. frees memory previously allocated to an array of type
  110. .BR "struct element *" .)
  111. .sp
  112. .RS 4
  113. .nf
  114. #include <string.h>
  115. #include <stdlib.h>
  116. #include <stdio.h>
  117. \&...
  118. /* Structure used to read data and store it. */
  119. struct element {
  120. char *key;
  121. char *data;
  122. };
  123. .P
  124. struct element *tbl, *curtbl;
  125. char *key, *data;
  126. int count;
  127. \&...
  128. void dbfree(struct element *, int);
  129. \&...
  130. if ((curtbl->key = malloc(strlen(key) + 1)) == NULL) {
  131. perror("malloc"); dbfree(tbl, count); return NULL;
  132. }
  133. strcpy(curtbl->key, key);
  134. .P
  135. if ((curtbl->data = malloc(strlen(data) + 1)) == NULL) {
  136. perror("malloc"); free(curtbl->key); dbfree(tbl, count); return NULL;
  137. }
  138. strcpy(curtbl->data, data);
  139. \&...
  140. .fi
  141. .P
  142. .RE
  143. .SH "APPLICATION USAGE"
  144. Character movement is performed differently in different
  145. implementations. Thus, overlapping moves may yield surprises.
  146. .P
  147. This version is aligned with the ISO\ C standard; this does not affect
  148. compatibility with XPG3 applications. Reliable error detection by this
  149. function was never guaranteed.
  150. .SH RATIONALE
  151. None.
  152. .SH "FUTURE DIRECTIONS"
  153. None.
  154. .SH "SEE ALSO"
  155. .IR "\fIstrncpy\fR\^(\|)",
  156. .IR "\fIwcscpy\fR\^(\|)"
  157. .P
  158. The Base Definitions volume of POSIX.1\(hy2017,
  159. .IR "\fB<string.h>\fP"
  160. .\"
  161. .SH COPYRIGHT
  162. Portions of this text are reprinted and reproduced in electronic form
  163. from IEEE Std 1003.1-2017, Standard for Information Technology
  164. -- Portable Operating System Interface (POSIX), The Open Group Base
  165. Specifications Issue 7, 2018 Edition,
  166. Copyright (C) 2018 by the Institute of
  167. Electrical and Electronics Engineers, Inc and The Open Group.
  168. In the event of any discrepancy between this version and the original IEEE and
  169. The Open Group Standard, the original IEEE and The Open Group Standard
  170. is the referee document. The original Standard can be obtained online at
  171. http://www.opengroup.org/unix/online.html .
  172. .PP
  173. Any typographical or formatting errors that appear
  174. in this page are most likely
  175. to have been introduced during the conversion of the source files to
  176. man page format. To report such errors, see
  177. https://www.kernel.org/doc/man-pages/reporting_bugs.html .