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

mkdtemp.3p (6513B)


  1. '\" et
  2. .TH MKDTEMP "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. mkdtemp, mkstemp
  12. \(em create a unique directory or file
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <stdlib.h>
  17. .P
  18. char *mkdtemp(char *\fItemplate\fP);
  19. int mkstemp(char *\fItemplate\fP);
  20. .fi
  21. .SH DESCRIPTION
  22. The
  23. \fImkdtemp\fR()
  24. function shall create a directory with a unique name derived from
  25. .IR template .
  26. The application shall ensure that the string provided in
  27. .IR template
  28. is a pathname ending with at least six trailing
  29. .BR 'X'
  30. characters. The
  31. \fImkdtemp\fR()
  32. function shall modify the contents of
  33. .IR template
  34. by replacing six or more
  35. .BR 'X'
  36. characters at the end of the pathname with the same number of
  37. characters from the portable filename character set. The characters
  38. shall be chosen such that the resulting pathname does not duplicate
  39. the name of an existing file at the time of the call to
  40. \fImkdtemp\fR().
  41. The
  42. \fImkdtemp\fR()
  43. function shall use the resulting pathname to create the new directory
  44. as if by a call to:
  45. .sp
  46. .RS 4
  47. .nf
  48. mkdir(pathname, S_IRWXU)
  49. .fi
  50. .P
  51. .RE
  52. .P
  53. The
  54. \fImkstemp\fR()
  55. function shall create a regular file with a unique name derived from
  56. .IR template
  57. and return a file descriptor for the file open for reading and
  58. writing. The application shall ensure that the string provided in
  59. .IR template
  60. is a pathname ending with at least six trailing
  61. .BR 'X'
  62. characters. The
  63. \fImkstemp\fR()
  64. function shall modify the contents of
  65. .IR template
  66. by replacing six or more
  67. .BR 'X'
  68. characters at the end of the pathname with the same number of
  69. characters from the portable filename character set. The characters
  70. shall be chosen such that the resulting pathname does not duplicate
  71. the name of an existing file at the time of the call to
  72. \fImkstemp\fR().
  73. The
  74. \fImkstemp\fR()
  75. function shall use the resulting pathname to create the file, and
  76. obtain a file descriptor for it, as if by a call to:
  77. .sp
  78. .RS 4
  79. .nf
  80. open(pathname, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR)
  81. .fi
  82. .P
  83. .RE
  84. .P
  85. By behaving as if the O_EXCL flag for
  86. \fIopen\fR()
  87. is set, the function prevents any possible race condition between
  88. testing whether the file exists and opening it for use.
  89. .SH "RETURN VALUE"
  90. Upon successful completion, the
  91. \fImkdtemp\fR()
  92. function shall return the value of
  93. .IR template .
  94. Otherwise, it shall return a null pointer and shall set
  95. .IR errno
  96. to indicate the error.
  97. .P
  98. Upon successful completion, the
  99. \fImkstemp\fR()
  100. function shall return an open file descriptor. Otherwise, it shall
  101. return \-1 and shall set
  102. .IR errno
  103. to indicate the error.
  104. .SH ERRORS
  105. The
  106. \fImkdtemp\fR()
  107. function shall fail if:
  108. .TP
  109. .BR EACCES
  110. Search permission is denied on a component of the path prefix, or write
  111. permission is denied on the parent directory of the directory to be
  112. created.
  113. .TP
  114. .BR EINVAL
  115. The string pointed to by
  116. .IR template
  117. does not end in
  118. .BR \(dqXXXXXX\(dq .
  119. .TP
  120. .BR ELOOP
  121. A loop exists in symbolic links encountered during resolution of the
  122. path of the directory to be created.
  123. .TP
  124. .BR EMLINK
  125. The link count of the parent directory would exceed
  126. {LINK_MAX}.
  127. .TP
  128. .BR ENAMETOOLONG
  129. .br
  130. The length of a component of a pathname is longer than
  131. {NAME_MAX}.
  132. .TP
  133. .BR ENOENT
  134. A component of the path prefix specified by the
  135. .IR template
  136. argument does not name an existing directory.
  137. .TP
  138. .BR ENOSPC
  139. The file system does not contain enough space to hold the contents of
  140. the new directory or to extend the parent directory of the new
  141. directory.
  142. .TP
  143. .BR ENOTDIR
  144. A component of the path prefix names an existing file that is neither
  145. a directory nor a symbolic link to a directory.
  146. .TP
  147. .BR EROFS
  148. The parent directory resides on a read-only file system.
  149. .P
  150. The
  151. \fImkdtemp\fR()
  152. function may fail if:
  153. .TP
  154. .BR ELOOP
  155. More than
  156. {SYMLOOP_MAX}
  157. symbolic links were encountered during resolution of the path of the
  158. directory to be created.
  159. .TP
  160. .BR ENAMETOOLONG
  161. .br
  162. The length of a pathname exceeds
  163. {PATH_MAX},
  164. or pathname resolution of a symbolic link produced an intermediate
  165. result with a length that exceeds
  166. {PATH_MAX}.
  167. .P
  168. The error conditions for the
  169. \fImkstemp\fR()
  170. function are defined in
  171. .IR "\fIopen\fR\^(\|)".
  172. .LP
  173. .IR "The following sections are informative."
  174. .SH EXAMPLES
  175. .SS "Generating a Pathname"
  176. .P
  177. The following example creates a file with a 10-character name beginning
  178. with the characters
  179. .BR \(dqfile\(dq
  180. and opens the file for reading and writing. The value returned as the
  181. value of
  182. .IR fd
  183. is a file descriptor that identifies the file.
  184. .sp
  185. .RS 4
  186. .nf
  187. #include <stdlib.h>
  188. \&...
  189. char template[] = "/tmp/fileXXXXXX";
  190. int fd;
  191. .P
  192. fd = mkstemp(template);
  193. .fi
  194. .P
  195. .RE
  196. .SH "APPLICATION USAGE"
  197. It is possible to run out of letters.
  198. .P
  199. Portable applications should pass exactly six trailing
  200. .BR 'X' s
  201. in the template and no more; implementations may treat any additional
  202. trailing
  203. .BR 'X' s
  204. as either a fixed or replaceable part of the template. To be sure of
  205. only passing six, a fixed string of at least one non-\c
  206. .BR 'X'
  207. character should precede the six
  208. .BR 'X' s.
  209. .P
  210. Since
  211. .BR 'X'
  212. is in the portable filename character set, some of the replacement
  213. characters can be
  214. .BR 'X' s,
  215. leaving part (or even all) of the template effectively unchanged.
  216. .SH RATIONALE
  217. None.
  218. .SH "FUTURE DIRECTIONS"
  219. None.
  220. .SH "SEE ALSO"
  221. .IR "\fIgetpid\fR\^(\|)",
  222. .IR "\fImkdir\fR\^(\|)",
  223. .IR "\fIopen\fR\^(\|)",
  224. .IR "\fItmpfile\fR\^(\|)",
  225. .IR "\fItmpnam\fR\^(\|)"
  226. .P
  227. The Base Definitions volume of POSIX.1\(hy2017,
  228. .IR "\fB<stdlib.h>\fP"
  229. .\"
  230. .SH COPYRIGHT
  231. Portions of this text are reprinted and reproduced in electronic form
  232. from IEEE Std 1003.1-2017, Standard for Information Technology
  233. -- Portable Operating System Interface (POSIX), The Open Group Base
  234. Specifications Issue 7, 2018 Edition,
  235. Copyright (C) 2018 by the Institute of
  236. Electrical and Electronics Engineers, Inc and The Open Group.
  237. In the event of any discrepancy between this version and the original IEEE and
  238. The Open Group Standard, the original IEEE and The Open Group Standard
  239. is the referee document. The original Standard can be obtained online at
  240. http://www.opengroup.org/unix/online.html .
  241. .PP
  242. Any typographical or formatting errors that appear
  243. in this page are most likely
  244. to have been introduced during the conversion of the source files to
  245. man page format. To report such errors, see
  246. https://www.kernel.org/doc/man-pages/reporting_bugs.html .