You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>tmpnam (The Red Hat newlib C Library)</title>
  7. <meta name="description" content="tmpnam (The Red Hat newlib C Library)">
  8. <meta name="keywords" content="tmpnam (The Red Hat newlib C Library)">
  9. <meta name="resource-type" content="document">
  10. <meta name="distribution" content="global">
  11. <meta name="Generator" content="makeinfo">
  12. <link href="index.html#Top" rel="start" title="Top">
  13. <link href="Document-Index.html#Document-Index" rel="index" title="Document Index">
  14. <link href="Document-Index.html#SEC_Contents" rel="contents" title="Table of Contents">
  15. <link href="Stdio.html#Stdio" rel="up" title="Stdio">
  16. <link href="ungetc.html#ungetc" rel="next" title="ungetc">
  17. <link href="tmpfile.html#tmpfile" rel="prev" title="tmpfile">
  18. <style type="text/css">
  19. <!--
  20. a.summary-letter {text-decoration: none}
  21. blockquote.indentedblock {margin-right: 0em}
  22. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  23. blockquote.smallquotation {font-size: smaller}
  24. div.display {margin-left: 3.2em}
  25. div.example {margin-left: 3.2em}
  26. div.lisp {margin-left: 3.2em}
  27. div.smalldisplay {margin-left: 3.2em}
  28. div.smallexample {margin-left: 3.2em}
  29. div.smalllisp {margin-left: 3.2em}
  30. kbd {font-style: oblique}
  31. pre.display {font-family: inherit}
  32. pre.format {font-family: inherit}
  33. pre.menu-comment {font-family: serif}
  34. pre.menu-preformatted {font-family: serif}
  35. pre.smalldisplay {font-family: inherit; font-size: smaller}
  36. pre.smallexample {font-size: smaller}
  37. pre.smallformat {font-family: inherit; font-size: smaller}
  38. pre.smalllisp {font-size: smaller}
  39. span.nolinebreak {white-space: nowrap}
  40. span.roman {font-family: initial; font-weight: normal}
  41. span.sansserif {font-family: sans-serif; font-weight: normal}
  42. ul.no-bullet {list-style: none}
  43. -->
  44. </style>
  45. </head>
  46. <body lang="en">
  47. <a name="tmpnam"></a>
  48. <div class="header">
  49. <p>
  50. Next: <a href="ungetc.html#ungetc" accesskey="n" rel="next">ungetc</a>, Previous: <a href="tmpfile.html#tmpfile" accesskey="p" rel="prev">tmpfile</a>, Up: <a href="Stdio.html#Stdio" accesskey="u" rel="up">Stdio</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  51. </div>
  52. <hr>
  53. <a name="tmpnam_002c-tempnam_002d_002d_002dname-for-a-temporary-file"></a>
  54. <h3 class="section">4.67 <code>tmpnam</code>, <code>tempnam</code>&mdash;name for a temporary file</h3>
  55. <a name="index-tmpnam"></a>
  56. <a name="index-tempnam"></a>
  57. <a name="index-_005ftmpnam_005fr"></a>
  58. <a name="index-_005ftempnam_005fr"></a>
  59. <p><strong>Synopsis</strong>
  60. </p><div class="example">
  61. <pre class="example">#include &lt;stdio.h&gt;
  62. char *tmpnam(char *<var>s</var>);
  63. char *tempnam(char *<var>dir</var>, char *<var>pfx</var>);
  64. char *_tmpnam_r(struct _reent *<var>reent</var>, char *<var>s</var>);
  65. char *_tempnam_r(struct _reent *<var>reent</var>, char *<var>dir</var>, char *<var>pfx</var>);
  66. </pre></div>
  67. <p><strong>Description</strong><br>
  68. Use either of these functions to generate a name for a temporary file.
  69. The generated name is guaranteed to avoid collision with other files
  70. (for up to <code>TMP_MAX</code> calls of either function).
  71. </p>
  72. <p><code>tmpnam</code> generates file names with the value of <code>P_tmpdir</code>
  73. (defined in &lsquo;<code>stdio.h</code>&rsquo;) as the leading directory component of the path.
  74. </p>
  75. <p>You can use the <code>tmpnam</code> argument <var>s</var> to specify a suitable area
  76. of memory for the generated filename; otherwise, you can call
  77. <code>tmpnam(NULL)</code> to use an internal static buffer.
  78. </p>
  79. <p><code>tempnam</code> allows you more control over the generated filename: you
  80. can use the argument <var>dir</var> to specify the path to a directory for
  81. temporary files, and you can use the argument <var>pfx</var> to specify a
  82. prefix for the base filename.
  83. </p>
  84. <p>If <var>dir</var> is <code>NULL</code>, <code>tempnam</code> will attempt to use the value of
  85. environment variable <code>TMPDIR</code> instead; if there is no such value,
  86. <code>tempnam</code> uses the value of <code>P_tmpdir</code> (defined in &lsquo;<code>stdio.h</code>&rsquo;).
  87. </p>
  88. <p>If you don&rsquo;t need any particular prefix to the basename of temporary
  89. files, you can pass <code>NULL</code> as the <var>pfx</var> argument to <code>tempnam</code>.
  90. </p>
  91. <p><code>_tmpnam_r</code> and <code>_tempnam_r</code> are reentrant versions of <code>tmpnam</code>
  92. and <code>tempnam</code> respectively. The extra argument <var>reent</var> is a
  93. pointer to a reentrancy structure.
  94. </p>
  95. <br>
  96. <p><strong>Warnings</strong><br>
  97. The generated filenames are suitable for temporary files, but do not
  98. in themselves make files temporary. Files with these names must still
  99. be explicitly removed when you no longer want them.
  100. </p>
  101. <p>If you supply your own data area <var>s</var> for <code>tmpnam</code>, you must ensure
  102. that it has room for at least <code>L_tmpnam</code> elements of type <code>char</code>.
  103. </p>
  104. <br>
  105. <p><strong>Returns</strong><br>
  106. Both <code>tmpnam</code> and <code>tempnam</code> return a pointer to the newly
  107. generated filename.
  108. </p>
  109. <br>
  110. <p><strong>Portability</strong><br>
  111. ANSI C requires <code>tmpnam</code>, but does not specify the use of
  112. <code>P_tmpdir</code>. The System V Interface Definition (Issue 2) requires
  113. both <code>tmpnam</code> and <code>tempnam</code>.
  114. </p>
  115. <p>Supporting OS subroutines required: <code>close</code>, <code>fstat</code>, <code>getpid</code>,
  116. <code>isatty</code>, <code>lseek</code>, <code>open</code>, <code>read</code>, <code>sbrk</code>, <code>write</code>.
  117. </p>
  118. <p>The global pointer <code>environ</code> is also required.
  119. </p>
  120. <br>
  121. <hr>
  122. <div class="header">
  123. <p>
  124. Next: <a href="ungetc.html#ungetc" accesskey="n" rel="next">ungetc</a>, Previous: <a href="tmpfile.html#tmpfile" accesskey="p" rel="prev">tmpfile</a>, Up: <a href="Stdio.html#Stdio" accesskey="u" rel="up">Stdio</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  125. </div>
  126. </body>
  127. </html>