LIBMAKETMPFILEFD(3)

πŸ“¦
version 11.13.03 Β· 3 versions
, in centos-stream 10, centos-stream 9, debian trixie, fedora 43, fedora 44, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ LIBMAKETMPFILEFD(3) ✨

okay bestie, we're in the Netpbm corner of the library functions manual, and today's main character is pm_make_tmpfile_fd() πŸŽ€ yes it's a library function, yes it lives in section 3, and yes it's about to be your new fave for making temp files. sit down, grab a strawberry πŸ“, let's go.


πŸ’– NAME πŸ’–

pm_make_tmpfile_fd() β€” create a temporary named file πŸ¦‹

literally that's the whole job. make a temp file. give it a name. slay.


🌸 SYNOPSIS 🌸

#include <netpbm/pm.h>

pm_make_tmpfile(int *         fdP,
                const char ** filenameP);

that's the whole vibe, no cap. 🫢


✨ EXAMPLE ✨

okay so 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 grep. iconic behaviour honestly πŸ’…

#include <netpbm/pm.h>

int fd;
const char * myfilename;

pm_make_tmpfile_fd(&fdP, &myfilename);

write(fd, "^account:\\s.*\n", 16);
fprintf(fd, "^name:\\s.*\n", 13);

close(fd);

asprintfN(&grepCommand, "grep --file='%s' /tmp/infile >/tmp/outfile");

system(grepCommand);

strfree(grepCommand);

unlink(myfilename);

strfree(myfilename);

not me reading this and being like "okay yes, clean up after yourself, queen" 🧹✨ unlink the file, strfree the name, periodt.


🌈 DESCRIPTION 🌈

so this library function is part of Netpbm(1). yes, that Netpbm. the whole family. πŸ’œ

pm_make_tmpfile_fd() is analogous to pm_make_tmpfile()(1). the only difference is that it opens the file as a low level file, the way open() would, rather than as a stream, the way fopen() would. that's it. that's the whole plot twist πŸ”₯

if you don't actually need to access the file by name, bestie, use pm_tmpfile_fd() instead, because it's cleaner. with pm_tmpfile_fd(), the operating system always deletes the temporary file when your program exits, even if your program failed to clean up after itself. main character energy from the OS fr fr πŸ‘‘

πŸ¦‹ HISTORY πŸ¦‹

pm_tmpfile() was introduced in Netpbm 10.42 (March 2008). so it's a little vintage, a little classic, still serving. ⭐


πŸŽ€ DOCUMENT SOURCE πŸŽ€

this manual page was generated by the Netpbm tool makeman from HTML source. the master documentation lives at:

http://netpbm.sourceforge.net/doc/libmaketmpfilefd.html

go peek if you want the source of truth, iykyk πŸ’–


and that's the whole page, bestie!! 🫢 brought to you by the netpbm documentation, dated 31 December 2007, closing out this Netpbm section 3 library function manual like the absolute icon it is. mwah πŸ’‹ ✨

πŸ“¦ where this page comes from