Blob


1 .TH OPENTEMP 3
2 .SH NAME
3 opentemp \- create and open a uniquely-named file
4 .SH SYNOPSIS
5 .B #include <u.h>
6 .br
7 .B #include <libc.h>
8 .PP
9 .B
10 int opentemp(char *template, int mode)
11 .SH DESCRIPTION
12 .I Opentemp
13 replaces
14 .I template
15 by a unique file name, and returns the
16 address of the template.
17 The template should look like a file name with eleven trailing
18 .LR X s.
19 The
20 .LR X s
21 are replaced by a letter followed by the current process id.
22 Letters from
23 .L a
24 to
25 .L z
26 are tried until the name of a file that does not yet exist
27 (see
28 .MR access (2) )
29 is generated.
30 .I Opentemp
31 then opens the file for the given
32 .I mode
33 and returns the file descriptor.
34 Most calls should use a mode
35 of
36 .BR ORDWR|ORCLOSE .
37 .PP
38 If no such name can be generated,
39 .I opentemp
40 returns \-1.
41 .PP
42 .I Opentemp
43 avoids races.
44 Two simultaneous calls to
45 .I opentemp
46 will never return the same name.
47 .SH SOURCE
48 .B \*9/src/lib9/opentemp.c
49 .SH "SEE ALSO
50 .I create
51 in
52 .MR open (3)