1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
  
     | 
    
      <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.3//EN">
<html> <head>
<title>Netpbm subroutine library: pm_make_tmpfile() function</title>
<meta name="manual_section" content="3">
</head>
<body>
<h1>pm_make_tmpfile()</h1>
Updated: 10 November 2007
<br>
<h2>NAME</h2>
pm_make_tmpfile() - create a temporary named file
<h2>SYNOPSIS</h2>
<pre>
#include <netpbm/pm.h>
pm_make_tmpfile(FILE **       fileP,
                const char ** filenameP);
</pre>
<h2>EXAMPLE</h2>
<p>This simple example creates a temporary file, writes "hello
world" to it, then writes some search patterns to it, then uses
it as input to <b>grep</b>:
<pre>
#include <netpbm/pm.h>
FILE * myfileP;
const char * myfilename;
pm_make_tmpfile(&myfileP, &myfilename);
fprintf(myfile, "^account:\\s.*\n");
fprintf(myfile, "^name:\\s.*\n");
fclose(myFileP);
asprintfN(&grepCommand, "grep --file='%s' /tmp/infile >/tmp/outfile");
system(grepCommand);
strfree(grepCommand);
unlink(myfilename);
strfree(myfilename);
</pre>
<h2>DESCRIPTION</h2>
<p>This library function is part of <a href="index.html">Netpbm</a>.
<p><b>pm_make_tmpfile()</b> creates and opens a temporary file, returning
to you a stream file handle for it and its name.
<b>pm_make_tmpfile()</b> chooses a file name that is not already in use,
with proper interlocking to make sure that it actually creates a file
and opens the new file, as opposed to merely opening an existing file.
<p>If you don't need to access the file by name, use
<b>pm_tmpfile()</b> instead, because it's cleaner.  With
<b>pm_tmpfile()</b>, the operating system always deletes the temporary
file when your program exits, if the program failed to clean up after
itself.
<p>The temporary file goes in the directory named by the
<b>TMPFILE</b> environment variable.  If <b>TMPFILE</b> is not set or
is set to something unusable (e.g.  too long), <b>pm_tmpfile()</b>
falls back to the value of the standard C library symbol
<b>P_tmpdir</b> (like the standard C library's <b>tmpfile()</b>).
<p>The name of the file within that directory is like
<b>myprog_blrfx</b>, where <b>myprog</b> is the name of your program
(arg 0) and the rest is an arbitrary discriminator.
<p>If <b>pm_make_tmpfile()</b> is unable to create a temporary file,
it issues a message to Standard Error and aborts the program.
<h2>HISTORY</h2>
<p><b>pm_tmpfile()</b> was introduced in Netpbm 10.27 (March 2005).
</body>
</html>
 
     |