TMPFILE(3P)

πŸ’– TMPFILE(3P) β€” the POSIX Programmer's Manual girlie πŸ’–

okay so bestie, this is tmpfile from the POSIX Programmer's Manual (3P section, we love her). come sit with me 🫢


✨ PROLOG ✨

okay so real talk first: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ β€” so if you're on Linux, pls go check the corresponding Linux manual page for the deets on Linux behavior. or, lowkey, the interface might not even be implemented on Linux at all. πŸ’€ just a heads up, no cap.


πŸŽ€ NAME πŸŽ€

tmpfile β€” create a temporary file. that's it. that's the whole vibe. a little guy that exists for a sec and then ✨vanishes✨.


🌸 SYNOPSIS 🌸

#include <stdio.h>

FILE *tmpfile(void);

she takes no arguments. she returns a FILE *. iconic behavior, honestly. πŸ‘‘


πŸ’… DESCRIPTION πŸ’…

so the functionality described on this reference page is aligned with the ISO C standard. and if there's any conflict between what's described here and the ISO C standard? that conflict is unintentional, bestie β€” this volume of POSIX.1‐2017 defers to the ISO C standard. periodt.

the tmpfile() function shall create a temporary file and open a corresponding stream. and here's the slay part: the file shall be automatically deleted when all references to the file are closed. it just peaces out. gone. no cleanup needed, we love a self-cleaning queen 🧚

the file shall be opened as in fopen() for update (wb+), EXCEPT that implementations may restrict the permissions β€” either by clearing the file mode bits or by setting them to the value S_IRUSR | S_IWUSR.

⚠️ heads up bestie: in some implementations, a permanent file may be left behind if the process calling tmpfile() is killed while it is processing a call to tmpfile(). so like… if someone yanks the plug mid-call, the file might just stay there forever. awkward. 😭

also, an error message may be written to standard error if the stream cannot be opened.


πŸ”₯ RETURN VALUE πŸ”₯

upon successful completion, tmpfile() shall return a pointer to the stream of the file that is created. πŸŽ‰

otherwise? it shall return a null pointer and set errno to indicate the error. sad girl hours.


πŸ’€ ERRORS πŸ’€

the tmpfile() function shall fail if:

  • EINTR β€” a signal was caught during tmpfile(). rude interruption tbh.
  • EMFILE β€” all file descriptors available to the process are currently open. you ran out, bestie.
  • EMFILE β€” {STREAM_MAX} streams are currently open in the calling process. (yes, EMFILE shows up twice with two different reasons, that's just how it is, we don't question the icon.)
  • ENFILE β€” the maximum allowable number of files is currently open in the system. the whole system is full, not just you.
  • ENOSPC β€” the directory or file system which would contain the new file cannot be expanded. no room, no vibes.
  • EOVERFLOW β€” the file is a regular file and the size of the file cannot be represented correctly in an object of type off_t. the number is too big for the lil box. πŸ’€

the tmpfile() function may fail if:

  • EMFILE β€” {FOPEN_MAX} streams are currently open in the calling process. (third time's the charm with EMFILE, she's everywhere.)
  • ENOMEM β€” insufficient storage space is available. out of memory, out of luck.

and just so you know: the following sections are informative. they're the vibes section, not the law section. 🌈


🌟 EXAMPLES 🌟

πŸ¦‹ Creating a Temporary File πŸ¦‹

this example creates a temporary file for update, and returns a pointer to a stream for the created file in the fp variable. look at her go:

#include <stdio.h>
...
FILE *fp;

fp = tmpfile ();

πŸ’œ APPLICATION USAGE πŸ’œ

it should be possible to open at least {TMP_MAX} temporary files during the lifetime of the program β€” and yes, that limit may be shared with tmpnam() β€” and there should be no limit on the number simultaneously open, other than this limit and any limit on the number of open file descriptors or streams ({OPEN_MAX}, {FOPEN_MAX}, {STREAM_MAX}).

so basically: go off, open as many as the system lets you. 🫢


πŸ“ RATIONALE πŸ“

None.

(genuinely nothing. the rationale section said "not me having nothing to say." πŸ’…)


⭐ FUTURE DIRECTIONS ⭐

None.

(she's perfect as she is, no notes, no future changes. main character energy.)


πŸ‘‘ SEE ALSO πŸ‘‘

  • Section 2.5, Standard I/O Streams
  • fopen()
  • mkdtemp()
  • tmpnam()
  • unlink()

and from the Base Definitions volume of POSIX.1‐2017: <stdio.h>


portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.

in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. (she's the final boss, no cap.)

the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


okay and that's the whole page bestie!! this one's brought to you by IEEE/The Open Group, 2017 β€” TMPFILE(3P), she's a legend, she's temporary, she's everything πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ«Ά

πŸ“¦ where this page comes from