'\" te .\" Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. .\" Portions Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at http://www.opengroup.org/bookstore/. .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html. This notice shall appear on any product containing this material. .TH mkstemp 3C "9 Jul 2012" "SunOS 5.11" "Standard C Library Functions" .SH NAME mkstemp, mkstemps \- make a unique file name from a template and open the file .SH SYNOPSIS .LP .nf #include \fBint\fR \fBmkstemp\fR(\fBchar *\fR\fItemplate\fR); .fi .LP .nf \fBint\fR \fBmkstemps\fR(\fBchar *\fR\fItemplate\fR, \fBint\fR \fIslen\fR); .fi .SH DESCRIPTION .sp .LP The \fBmkstemp()\fR function replaces the contents of the string pointed to by \fItemplate\fR by a unique file name, and returns a file descriptor for the file open for reading and writing. The function thus prevents any possible race condition between testing whether the file exists and opening it for use. The string in \fItemplate\fR should look like a file name with six trailing 'X's; \fBmkstemp()\fR replaces each 'X' with a character from the portable file name character set. The characters are chosen such that the resulting name does not duplicate the name of an existing file. .sp .LP The \fBmkstemps()\fR function behaves the same as \fBmkstemp()\fR, except it permits a suffix to exist in the template. The template should be of the form /\fBtmp\fR/\fBtmp\fR\fIXXXXXX\fR\fIsuffix\fR. The \fIslen\fR parameter specifies the length of the suffix string. .SH RETURN VALUES .sp .LP Upon successful completion, \fBmkstemp()\fR and \fBmkstemps()\fR return an open file descriptor. Otherwise \(mi1 is returned if no suitable file could be created. .SH ERRORS .sp .LP The \fBmkstemp()\fR and \fBmkstemps()\fR functions can set \fBerrno\fR to the same values as \fBlstat\fR(2) and \fBopen\fR(2). .SH USAGE .sp .LP It is possible to run out of letters. .sp .LP The \fBmkstemp()\fR function does not check to determine whether the file name part of \fItemplate\fR exceeds the maximum allowable file name length. .sp .LP The \fBmkstemp()\fR function is frequently used to create a temporary file that will be removed by the application before the application terminates. .sp .LP The \fBtmpfile\fR(3C) function is preferred over the \fBmkstemp()\fR function for creating temporary files when control over the path and name of the file is not needed. .sp .LP The \fBmkstemp()\fR function has a transitional interface for 64-bit file offsets. See \fBlf64\fR(5). .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS tab() box; lw(2.75i) |lw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPEATTRIBUTE VALUE _ Interface StabilityCommitted _ StandardFor \fBmkstemp()\fR, see \fBstandards\fR(5). .TE .SH SEE ALSO .sp .LP \fBgetpid\fR(2), \fBopen\fR(2), \fBtmpfile\fR(3C), \fBmktemp\fR(3C), \fBattributes\fR(5), \fBlf64\fR(5), \fBstandards\fR(5)