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

strdup.3p (3655B)


  1. '\" et
  2. .TH STRDUP "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. strdup, strndup
  12. \(em duplicate a specific number of bytes from a string
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <string.h>
  17. .P
  18. char *strdup(const char *\fIs\fP);
  19. char *strndup(const char *\fIs\fP, size_t \fIsize\fP);
  20. .fi
  21. .SH DESCRIPTION
  22. The
  23. \fIstrdup\fR()
  24. function shall return a pointer to a new string, which is a duplicate
  25. of the string pointed to by
  26. .IR s .
  27. The returned pointer can be passed to
  28. \fIfree\fR().
  29. A null pointer is returned if the new string cannot be created.
  30. .P
  31. The
  32. \fIstrndup\fR()
  33. function shall be equivalent to the
  34. \fIstrdup\fR()
  35. function, duplicating the provided
  36. .IR s
  37. in a new block of memory allocated as if by using
  38. \fImalloc\fR(),
  39. with the exception being that
  40. \fIstrndup\fR()
  41. copies at most
  42. .IR size
  43. plus one bytes into the newly allocated memory, terminating the new
  44. string with a NUL character. If the length of
  45. .IR s
  46. is larger than
  47. .IR size ,
  48. only
  49. .IR size
  50. bytes shall be duplicated. If
  51. .IR size
  52. is larger than the length of
  53. .IR s ,
  54. all bytes in
  55. .IR s
  56. shall be copied into the new memory buffer, including the terminating
  57. NUL character. The newly created string shall always be properly
  58. terminated.
  59. .SH "RETURN VALUE"
  60. The
  61. \fIstrdup\fR()
  62. function shall return a pointer to a new string on success. Otherwise,
  63. it shall return a null pointer and set
  64. .IR errno
  65. to indicate the error.
  66. .P
  67. Upon successful completion, the
  68. \fIstrndup\fR()
  69. function shall return a pointer to the newly allocated memory
  70. containing the duplicated string. Otherwise, it shall return a null
  71. pointer and set
  72. .IR errno
  73. to indicate the error.
  74. .SH ERRORS
  75. These functions shall fail if:
  76. .TP
  77. .BR ENOMEM
  78. Storage space available is insufficient.
  79. .LP
  80. .IR "The following sections are informative."
  81. .SH EXAMPLES
  82. None.
  83. .SH "APPLICATION USAGE"
  84. For functions that allocate memory as if by
  85. \fImalloc\fR(),
  86. the application should release such memory when it is no longer
  87. required by a call to
  88. \fIfree\fR().
  89. For
  90. \fIstrdup\fR()
  91. and
  92. \fIstrndup\fR(),
  93. this is the return value.
  94. .P
  95. Implementations are free to
  96. \fImalloc\fR()
  97. a buffer containing either (\c
  98. .IR size
  99. + 1) bytes or (\c
  100. .IR strnlen (
  101. .IR s ,
  102. .IR size )
  103. + 1) bytes. Applications should not assume that
  104. \fIstrndup\fR()
  105. will allocate (\c
  106. .IR size
  107. + 1) bytes when
  108. .IR strlen (
  109. .IR s )
  110. is smaller than
  111. .IR size .
  112. .SH RATIONALE
  113. None.
  114. .SH "FUTURE DIRECTIONS"
  115. None.
  116. .SH "SEE ALSO"
  117. .IR "\fIfree\fR\^(\|)",
  118. .IR "\fIwcsdup\fR\^(\|)"
  119. .P
  120. The Base Definitions volume of POSIX.1\(hy2017,
  121. .IR "\fB<string.h>\fP"
  122. .\"
  123. .SH COPYRIGHT
  124. Portions of this text are reprinted and reproduced in electronic form
  125. from IEEE Std 1003.1-2017, Standard for Information Technology
  126. -- Portable Operating System Interface (POSIX), The Open Group Base
  127. Specifications Issue 7, 2018 Edition,
  128. Copyright (C) 2018 by the Institute of
  129. Electrical and Electronics Engineers, Inc and The Open Group.
  130. In the event of any discrepancy between this version and the original IEEE and
  131. The Open Group Standard, the original IEEE and The Open Group Standard
  132. is the referee document. The original Standard can be obtained online at
  133. http://www.opengroup.org/unix/online.html .
  134. .PP
  135. Any typographical or formatting errors that appear
  136. in this page are most likely
  137. to have been introduced during the conversion of the source files to
  138. man page format. To report such errors, see
  139. https://www.kernel.org/doc/man-pages/reporting_bugs.html .