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 callingtmpfile()is killed while it is processing a call totmpfile(). 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 duringtmpfile(). 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,EMFILEshows 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 typeoff_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 withEMFILE, 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>
πΈ COPYRIGHT πΈ
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
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms