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

tempnam.3p (4220B)


  1. '\" et
  2. .TH TEMPNAM "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. tempnam
  12. \(em create a name for a temporary file
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <stdio.h>
  17. .P
  18. char *tempnam(const char *\fIdir\fP, const char *\fIpfx\fP);
  19. .fi
  20. .SH DESCRIPTION
  21. The
  22. \fItempnam\fR()
  23. function shall generate a pathname that may be used for a temporary
  24. file.
  25. .P
  26. The
  27. \fItempnam\fR()
  28. function allows the user to control the choice of a directory. The
  29. .IR dir
  30. argument points to the name of the directory in which the file is to be
  31. created. If
  32. .IR dir
  33. is a null pointer or points to a string which is not a name for an
  34. appropriate directory, the path prefix defined as P_tmpdir in the
  35. .IR <stdio.h>
  36. header shall be used. If that directory is not accessible, an
  37. implementation-defined directory may be used.
  38. .P
  39. Many applications prefer their temporary files to have certain initial
  40. letter sequences in their names. The
  41. .IR pfx
  42. argument should be used for this. This argument may be a null pointer
  43. or point to a string of up to five bytes to be used as the beginning of
  44. the filename.
  45. .P
  46. Some implementations of
  47. \fItempnam\fR()
  48. may use
  49. \fItmpnam\fR()
  50. internally. On such implementations, if called more than
  51. {TMP_MAX}
  52. times in a single process, the behavior is implementation-defined.
  53. .SH "RETURN VALUE"
  54. Upon successful completion,
  55. \fItempnam\fR()
  56. shall allocate space for a string, put the generated pathname in that
  57. space, and return a pointer to it. The pointer shall be suitable for
  58. use in a subsequent call to
  59. \fIfree\fR().
  60. Otherwise, it shall return a null pointer and set
  61. .IR errno
  62. to indicate the error.
  63. .SH ERRORS
  64. The
  65. \fItempnam\fR()
  66. function shall fail if:
  67. .TP
  68. .BR ENOMEM
  69. Insufficient storage space is available.
  70. .LP
  71. .IR "The following sections are informative."
  72. .SH EXAMPLES
  73. .SS "Generating a Pathname"
  74. .P
  75. The following example generates a pathname for a temporary file in
  76. directory
  77. .BR /tmp ,
  78. with the prefix
  79. .IR file .
  80. After the pathname has been created, the call to
  81. \fIfree\fR()
  82. deallocates the space used to store the pathname.
  83. .sp
  84. .RS 4
  85. .nf
  86. #include <stdio.h>
  87. #include <stdlib.h>
  88. \&...
  89. const char *directory = "/tmp";
  90. const char *fileprefix = "file";
  91. char *file;
  92. .P
  93. file = tempnam(directory, fileprefix);
  94. free(file);
  95. .fi
  96. .P
  97. .RE
  98. .SH "APPLICATION USAGE"
  99. This function only creates pathnames. It is the application's
  100. responsibility to create and remove the files. Between the time a
  101. pathname is created and the file is opened, it is possible for some
  102. other process to create a file with the same name. Applications may
  103. find
  104. \fItmpfile\fR()
  105. more useful.
  106. .P
  107. Applications should use the
  108. \fItmpfile\fR(),
  109. \fImkdtemp\fR(),
  110. or
  111. \fImkstemp\fR()
  112. functions instead of the obsolescent
  113. \fItempnam\fR()
  114. function.
  115. .SH RATIONALE
  116. None.
  117. .SH "FUTURE DIRECTIONS"
  118. The
  119. \fItempnam\fR()
  120. function may be removed in a future version.
  121. .SH "SEE ALSO"
  122. .IR "\fIfopen\fR\^(\|)",
  123. .IR "\fIfree\fR\^(\|)",
  124. .IR "\fImkdtemp\fR\^(\|)",
  125. .IR "\fIopen\fR\^(\|)",
  126. .IR "\fItmpfile\fR\^(\|)",
  127. .IR "\fItmpnam\fR\^(\|)",
  128. .IR "\fIunlink\fR\^(\|)"
  129. .P
  130. The Base Definitions volume of POSIX.1\(hy2017,
  131. .IR "\fB<stdio.h>\fP"
  132. .\"
  133. .SH COPYRIGHT
  134. Portions of this text are reprinted and reproduced in electronic form
  135. from IEEE Std 1003.1-2017, Standard for Information Technology
  136. -- Portable Operating System Interface (POSIX), The Open Group Base
  137. Specifications Issue 7, 2018 Edition,
  138. Copyright (C) 2018 by the Institute of
  139. Electrical and Electronics Engineers, Inc and The Open Group.
  140. In the event of any discrepancy between this version and the original IEEE and
  141. The Open Group Standard, the original IEEE and The Open Group Standard
  142. is the referee document. The original Standard can be obtained online at
  143. http://www.opengroup.org/unix/online.html .
  144. .PP
  145. Any typographical or formatting errors that appear
  146. in this page are most likely
  147. to have been introduced during the conversion of the source files to
  148. man page format. To report such errors, see
  149. https://www.kernel.org/doc/man-pages/reporting_bugs.html .