tempnam

Generates a pathname for a temporary file.

Library:LibC
Classification:POSIX
Service:File and Directory I/O

Syntax

  #include <stdio.h> 
   
  char *tempnam (
     const char  *dirpath,
     const char  *prefix);
  

Parameters

dirpath

(IN) Points to the directory where the temporary file is to be created. It can also have the following values:

  • NULL, which causes the filename to be generated without a path.

  • P_tmpdir, which defines a default path of "sys:/tmp". If the TMPDIR environment variable is set and the NLM is compiled with POSIX semantics, the TMPDIR value overrides the default path.

prefix

(IN) Points to the string, of no more than 5 bytes, for the initial letter sequence of the filename. This parameter is optional and can be a NULL pointer.

Return Values

If successful, allocates memory for the path and filename and returns a pointer to the string. This memory needs to be freed with a subsequent call to free, using the returned pointer.

If unsuccessful, returns a NULL pointer and sets errno to the following:

Decimal

Constant

Description

5

ENOMEM

Insufficient memory for the filename.

See Also

tmpnam