1Netpbm subroutine libraNreyt:pbpLmmi_bsmruaabkrreyo_utFtmuipnnfceitlileoi(nb)srafMruaynn:cutapilmo_nm(a3k)e_tmpfile() function(3)
2
3
4
6 pm_make_tmpfile() - create a temporary named file
7
8
10 #include <netpbm/pm.h>
11
12 pm_make_tmpfile(FILE ** fileP,
13 const char ** filenameP);
14
15
17 This simple example creates a temporary file, writes 'hello world' to
18 it, then writes some search patterns to it, then uses it as input to
19 grep:
20
21 #include <netpbm/pm.h>
22
23 FILE * myfileP;
24 const char * myfilename;
25
26 pm_make_tmpfile(&myfileP, &myfilename);
27
28 fprintf(myfile, '^account:\\s.*\n');
29 fprintf(myfile, '^name:\\s.*\n');
30
31 fclose(myFileP);
32
33 asprintfN(&grepCommand, 'grep --file='%s' /tmp/infile >/tmp/outfile');
34
35 system(grepCommand);
36
37 strfree(grepCommand);
38
39 unlink(myfilename);
40
41 strfree(myfilename);
42
43
44
46 This library function is part of Netpbm(1).
47
48 pm_make_tmpfile() creates and opens a temporary file, returning to you
49 a stream file handle for it and its name.
50
51 pm_make_tmpfile() chooses a file name that is not already in use, with
52 proper interlocking to make sure that it actually creates a file and
53 opens the new file, as opposed to merely opening an existing file.
54
55 If you don't need to access the file by name, use pm_tmpfile() instead,
56 because it's cleaner. With pm_tmpfile(), the operating system always
57 deletes the temporary file when your program exits, if the program
58 failed to clean up after itself.
59
60 The temporary file goes in the directory named by the TMPFILE environā
61 ment variable. If TMPFILE is not set or is set to something unusable
62 (e.g. too long), pm_tmpfile() falls back to the value of the standard
63 C library symbol P_tmpdir (like the standard C library's tmpfile()).
64
65 The name of the file within that directory is like myprog_blrfx, where
66 myprog is the name of your program (arg 0) and the rest is an arbitrary
67 discriminator.
68
69 If pm_make_tmpfile() is unable to create a temporary file, it issues a
70 message to Standard Error and aborts the program.
71
72
73
75 pm_tmpfile() was introduced in Netpbm 10.27 (March 2005).
76
77
78
79netpbm documentation Netpbm su1b0roNuotvienmebelrib2r0a0r7y: pm_make_tmpfile() function(3)