|
|
1.1 root 1: .\" Copyright (c) 1989 The Regents of the University of California.
2: .\" All rights reserved.
3: .\"
4: .\" Redistribution and use in source and binary forms are permitted provided
5: .\" that: (1) source distributions retain this entire copyright notice and
6: .\" comment, and (2) distributions including binaries display the following
7: .\" acknowledgement: ``This product includes software developed by the
8: .\" University of California, Berkeley and its contributors'' in the
9: .\" documentation or other materials provided with the distribution and in
10: .\" all advertising materials mentioning features or use of this software.
11: .\" Neither the name of the University nor the names of its contributors may
12: .\" be used to endorse or promote products derived from this software without
13: .\" specific prior written permission.
14: .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
15: .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
16: .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17: .\"
18: .\" @(#)mktemp.3 6.7 (Berkeley) 6/23/90
19: .\"
20: .TH MKTEMP 3 "June 23, 1990"
21: .AT 3
22: .SH NAME
23: mktemp \- create a unique file name
24: .SH SYNOPSIS
25: .nf
26: .ft B
27: char *
28: mktemp(template)
29: char *template;
30: .sp
31: mkstemp(template)
32: char *template;
33: .ft R
34: .fi
35: .SH DESCRIPTION
36: .I Mktemp
37: takes a file name template and overwrites it to create a unique file
38: name for use by the application.
39: The template may be any file name with some number of X's appended
40: to it, for example ``/tmp/temp.XXXX''.
41: The trailing X's are replaced with the current process number and/or a
42: unique letter combination.
43: The number of unique file names
44: .I mktemp
45: can return depends on the number of X's provided; six X's will
46: result in
47: .I mktemp
48: testing roughly 26 ** 6 combinations.
49: .PP
50: .I Mkstemp
51: makes the same replacement to the template and creates the template file,
52: mode 0600, returning a file descriptor opened for reading and writing.
53: This avoids the race between testing for a file's existence and opening it
54: for use.
55: .SH "RETURN VALUE"
56: .I Mktemp
57: returns a pointer to the template on success and NULL on failure.
58: .I Mkstemp
59: returns -1 if no suitable file could be created.
60: If either call fails an error code is placed in the global location
61: .IR errno .
62: .SH ERRORS
63: .I Mktemp
64: and
65: .I mkstemp
66: may set
67: .I errno
68: to one of the following values:
69: .TP
70: [ENOTDIR]
71: The pathname portion of the template is not an existing directory.
72: .PP
73: .I Mktemp
74: and
75: .I mkstemp
76: may also set
77: .I errno
78: to any value specified by the
79: .IR stat (2)
80: function.
81: .I Mkstemp
82: may also set
83: .I errno
84: to any value specified by the
85: .IR open (2)
86: function.
87: .SH "SEE ALSO"
88: chmod(2), getpid(2), open(2), stat(2)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.