Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

getpid(2)

open(2)

tmpfile(3S)

tmpnam(3S)



mkstemp(3)             C LIBRARY FUNCTIONS             mkstemp(3)



NAME
     mkstemp - make a unique file name

SYNOPSIS
     cc [ flag... ] file ... -lucb
     mkstemp(template)
     char *template;

DESCRIPTION
     mkstemp creates a unique file name, typically in a temporary
     filesystem,  by  replacing template with a unique file name,
     and returns a file descriptor for the template file open for
     reading  and writing.  The string in template should contain
     a file name with six trailing Xs; mkstemp  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  avoids  the  race between testing
     whether the file exists and opening it for use.

SEE ALSO
     getpid(2),   open(2),   tmpfile(3S),   tmpnam(3S)   in   the
     Programmer's Reference Manual.

RETURN VALUE
     mkstemp returns -1 if no suitable file could be created.

NOTES
     It is possible to run out of letters.

     mkstemp actually changes 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.

     When mkstemp is creating a new unique filename it checks 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 mkstemp.
















             Last change: BSD Compatibility Package             1



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026