A NOTE has been added to this issue. 
====================================================================== 
https://www.austingroupbugs.net/view.php?id=1616 
====================================================================== 
Reported By:                illiliti
Assigned To:                
====================================================================== 
Project:                    Issue 8 drafts
Issue ID:                   1616
Category:                   Shell and Utilities
Type:                       Enhancement Request
Severity:                   Editorial
Priority:                   normal
Status:                     New
Name:                       Mark Lundblad 
Organization:                
User Reference:              
Section:                    Shell and Utilities 
Page Number:                - 
Line Number:                - 
Final Accepted Text:         
====================================================================== 
Date Submitted:             2022-11-08 23:03 UTC
Last Modified:              2025-03-06 11:09 UTC
====================================================================== 
Summary:                    Standardize mktemp utility
====================================================================== 

---------------------------------------------------------------------- 
 (0007093) geoffclare (manager) - 2025-03-06 11:09
 https://www.austingroupbugs.net/view.php?id=1616#c7093 
---------------------------------------------------------------------- 
This is a copy of https://www.austingroupbugs.net/view.php?id=1616#c7089 with
some wording tweaks.

Before page 3178 (XCU more), insert new page(s) containing the following:

<b>NAME</b>
<blockquote>mktemp - create temporary unique regular file or
directory</blockquote>

<b>SYNOPSIS</b>
<blockquote>mktemp [-dq] [-p <i>directory</i>] [<i>template</i>]</blockquote>

<b>DESCRIPTION</b>
<blockquote>The <i>mktemp</i> utility shall create a temporary regular file or
directory based on a <i>template</i>, as if by calling <i>mkstemp</i>( ) or
<i>mkdtemp</i>( ), respectively.

<b>OPTIONS</b>
<blockquote>
-d <blockquote>Create a directory, as if by calling <i>mkdtemp</i>( ). If the
<b>-d</b> option is not specified, a regular file shall be created as if by
calling <i>mkstemp</i>( ).</blockquote>
-p <i>directory</i> <blockquote>Specify the directory where the temporary file
is to be created; if this option is specified, the behavior is
unspecified if <i>template</i> contains any <tt>'/'</tt> characters.  The
behavior is unspecified if <i>directory</i> is an empty string.</blockquote>
-q <blockquote>Suppress output to the standard error if an error
occurs.</blockquote>

<b>OPERANDS</b>
<blockquote>The following operand shall be supported:

<i>template</i> <blockquote>Specify a template to use in creating the temporary
file or directory; the behavior is unspecified if <i>template</i> does not end
in at least six trailing <tt>'X'</tt> characters.  If <i>template</i> is
omitted, an implementation-defined default template shall be used.  If
<i>template</i> is a relative pathname, and the <b>-p</b> option was not
provided, it is
unspecified whether it is treated as relative to the current working directory
or to the directory named by the <i>TMPDIR</i> environment
variable.</blockquote>

<b>STDIN</b>
<blockquote>Not used.</blockquote>

<b>INPUT FILES</b>
<blockquote>None.</blockquote>

<b>ENVIRONMENT VARIABLES</b>
<blockquote>The following environment variables shall affect the execution of
<i>mktemp</i>:
<i>LANG</i> <blockquote>Provide a default value for the internationalization
variables that are unset or null. (See XBD Section 8.2 (on page 169) for the
precedence of internationalization variables used to determine the values of
locale categories.)</blockquote>
<i>LC_ALL</i> <blockquote>If set to a non-empty string value, override the
values of all the other internationalization variables.</blockquote>
<i>LC_CTYPE</i> <blockquote>Determine the locale for the interpretation of
sequences of bytes of text data as characters (for example, single-byte as
opposed to multi-byte characters in arguments).</blockquote>
<i>LC_MESSAGES</i> <blockquote>Determine the locale that should be used to
affect the format and contents of diagnostic messages written to standard
error.</blockquote>
[XSI]<i>NLSPATH</i> <blockquote>Determine the location of messages objects and
message catalogs.</blockquote>[/XSI]
<i>TMPDIR</i> <blockquote>The pathname of an existing directory designed to hold
temporary files created by the current user.</blockquote></blockquote>

<b>ASYNCHRONOUS EVENTS</b>
<blockquote>Default.</blockquote>

<b>STDOUT</b>
<blockquote>The <i>mktemp</i> utility shall write a line to the stdandard output
in the following format:
<tt>"%s\n", <<i>absolute path to resulting file</i>></tt></blockquote>

<b>STDERR</b>
<blockquote>The standard error shall be used only for diagnostic
messages.</blockquote>

<b>OUTPUT FILES</b>
<blockquote>None.</blockquote>

<b>EXTENDED DESCRIPTION</b>
<blockquote>None.</blockquote>

<b>EXIT STATUS</b>
<blockquote>The following exit values shall be returned:
0 Successful completion.
>0 An error occurred.</blockquote>

<b>CONSEQUENCES OF ERRORS</b>
<blockquote>Default.</blockquote>

<b>APPLICATION USAGE</b>
<blockquote>Historical implementations differ on what happens if the
<i>template</i> contains a <slash> character, and on whether the current working
directory or the environment variable <i>TMPDIR</i> takes precedence when the
<b>-p</b> option is not supplied.  In order for an application to control the
directory that contains the resulting temporary file, the most portable way to
do so is with the <b>-p</b> option.

All known historical implementations support the use of <i>mktemp</i> without an
explicit <i>template</i> operand; however, the implementation's default template
need not comply with the requirement that an explicit template must end in at
least 6 <tt>'X'</tt> bytes.</blockquote>

<b>EXAMPLES</b>
<blockquote>
1. Create and use a temporary regular file, with no error message on failure.
<pre>file=$(mktemp -q file.XXXXXX) && {
  echo ... > "$file"    # Use $file within this block
  rm "$file"
}</pre>

2. Create a secure FIFO within a temporary directory under /tmp.
<pre>dir=$(mktemp -d -p /tmp dir.XXXXXX) || exit 1
fifo=$dir/fifo
mkfifo "$fifo" || { rmdir "$dir"; exit 1; }</tt></blockquote>

<b>RATIONALE</b>
<blockquote>Several implementations provide a <b>-u</b> option to immediately
unlink the temporary file after it is created, which roughly behaves as a way to
generate a random file name that does not exist at the time it was written. 
However, this mode suffers from the same safety problems as <i>mktemp</i>( ) in
introducing a race between time of check and time of use, so the standard
developers did not choose to standardize the option.

Older versions of the standard provide other means to safely generate a secure
file name, such as the use of the <b>mkstemp</b> macro of the <i>m4</i> utility,
or by open-coding a shell loop with <tt>set -C</tt> that tries various candidate
names.  However, the convenience and conciseness of the <i>mktemp</i> utility,
along with a large number of fairly similar implementations, was sufficient to
include the utility in this version of the standard.</blockquote>

<b>FUTURE DIRECTIONS</b>
<blockquote>None.</blockquote>

<b>SEE ALSO</b>
<blockquote><i>m4</i></blockquote>
<blockquote>XSH <i>mkdtemp</i>( ), <i>mkstemp</i>( )</blockquote>

<b>CHANGE HISTORY</b>
<blockquote>First released in Issue 9.</blockquote> 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2022-11-08 23:03 illiliti       New Issue                                    
2022-11-08 23:03 illiliti       Name                      => Mark Lundblad   
2022-11-08 23:03 illiliti       Section                   => Shell and Utilities
2022-11-08 23:03 illiliti       Page Number               => -               
2022-11-08 23:03 illiliti       Line Number               => -               
2022-11-08 23:30 steffen        Note Added: 0006038                          
2022-11-09 13:18 illiliti       Note Added: 0006041                          
2023-02-22 13:30 ormaaj         Note Added: 0006166                          
2023-02-22 19:10 ormaaj         Note Edited: 0006166                         
2025-02-28 18:37 eblake         Note Added: 0007089                          
2025-03-06 11:09 geoffclare     Note Added: 0007093                          
======================================================================


  • [Issue 8 d... Austin Group Bug Tracker via austin-group-l at The Open Group
    • [Issu... Austin Group Issue Tracker via austin-group-l at The Open Group
    • [Issu... Austin Group Issue Tracker via austin-group-l at The Open Group
    • [Issu... Austin Group Issue Tracker via austin-group-l at The Open Group
      • R... Alejandro C via austin-group-l at The Open Group
        • ... Eric Blake via austin-group-l at The Open Group
          • ... Alejandro Colomar via austin-group-l at The Open Group
            • ... Haelwenn lanodan Monnier via austin-group-l at The Open Group
              • ... Alejandro Colomar via austin-group-l at The Open Group
                • ... Haelwenn lanodan Monnier via austin-group-l at The Open Group
                • ... Alejandro Colomar via austin-group-l at The Open Group
                • ... Haelwenn Monnier via austin-group-l at The Open Group
                • ... Alejandro Colomar via austin-group-l at The Open Group

Reply via email to