Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > M

mktemp(3C)

HP-UX 11i Version 3: February 2007
» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

NAME

mktemp(), mkstemp() — make a unique file name

SYNOPSIS

#include <stdlib.h>

char *mktemp(char *template);

int mkstemp(char *template);

Remarks

These functions are provided solely for backward compatibility and importability of applications, and are not recommended for new applications where portability is important. For portable applications, use tmpfile() instead (see tmpfile(3S)).

DESCRIPTION

mktemp() replaces the contents of the string pointed to by template by a unique file name, and returns the address of template. The string in template should look like a file name with six trailing Xs; mktemp() replaces each X with a single byte character from the portable filename character set. The letter is chosen such that the resulting name does not duplicate the name of an existing file.

mkstemp() makes the same replacement to the template, but also returns a file descriptor for the template file after opening the file for reading and writing. mkstemp() thus prevents any possible race condition between testing whether the file exists and opening it for use.

RETURN VALUE

mktemp() returns its argument except when it runs out of letters or an underlying service fails, in which case the result is a pointer to an empty string "".

mkstemp() returns an open file descriptor upon successful completion, or -1 if no suitable file could be created.

WARNINGS

It is possible to run out of letters.

mktemp() and mkstemp() do not check to determine whether the file name part of template exceeds the maximum allowable file name length.

Setting process_id_max kernel tunable to values greater than 99999 can have an effect on formation of temporary filenames in mktemp() and mkstemp().

Formation of temporary filenames using process ids may not be supported in future versions of mktemp() and mkstemp().

STANDARDS CONFORMANCE

mktemp(): SVID2, SVID3, XPG2

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.