unixdev.net


Switch to SpeakEasy.net DSL

The Modular Manual Browser

Home Page
Manual: (SunOS-4.1.3)
Page:
Section:
Apropos / Subsearch:
optional field

MKTEMP(3)                  Library Functions Manual                  MKTEMP(3)



NAME
       mktemp, mkstemp - make a unique file name

SYNOPSIS
       char *mktemp(template)
       char *template;

       mkstemp(template)
       char *template;

DESCRIPTION
       mktemp()  creates a unique file name, typically in a temporary filesys-
       tem, by replacing template with a unique file  name,  and  returns  the
       address of template.  The string in template should contain a file name
       with six trailing Xs; mktemp() replaces the Xs with a  letter  and  the
       current  process  ID.   The letter will be chosen so that the resulting
       name does not duplicate an existing file.   mkstemp()  makes  the  same
       replacement  to the template but returns a file descriptor for the tem-
       plate file open for reading and writing.   mkstemp()  avoids  the  race
       between testing whether the file exists and opening it for use.

       Notes:

       o mktemp()  and mkstemp() actually change the template string which you
         pass; this means that you cannot use the same  template  string  more
         than once -- you need a fresh template for every unique file you want
         to open.

       o When mktemp() or mkstemp() are creating a new  unique  filename  they
         check  for  the prior existence of a file with that name.  This means
         that if you are creating more than one unique  filename,  it  is  bad
         practice  to  use  the same root template for multiple invocations of
         mktemp() or mkstemp().

SEE ALSO
       getpid(2V), open(2V), tmpfile(3S), tmpnam(3S)

DIAGNOSTICS
       mkstemp() returns an open file descriptor upon success.  It returns  -1
       if no suitable file could be created.

       mktemp()  assigns  the  null string to template when it cannot create a
       unique name.

BUGS
       It is possible to run out of letters.



                               6 September 1989                      MKTEMP(3)