TMPFILE(3POSIX)

πŸ’– TMPFILE(3POSIX) πŸ’–

okay so bestie, welcome to the POSIX Programmer's Manual ✨ this lil page is all about tmpfile, and it's giving temporary file realness. stay with me, it's gonna be cute AND useful, i promise 🫢


🌸 PROLOG 🌸

so, first things first β€” this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (bestie, pls consult the corresponding Linux manual page for the details of Linux behavior), or honestly?? the interface may not even be implemented on Linux at all. πŸ™ˆ


πŸ‘‘ NAME πŸ‘‘

tmpfile β€” create a temporary file πŸ’…


✨ SYNOPSIS ✨

#include <stdio.h>

FILE *tmpfile(void);

πŸ¦‹ DESCRIPTION πŸ¦‹

the functionality described on this reference page is aligned with the ISO C standard. and like, if there's any conflict between the requirements described here and the ISO C standard? that's 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. the file shall be automatically deleted when all references to the file are closed. no cleanup on your part, she handles herself. 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 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, don't get murked mid-call, okay?? 😭

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 fr fr.


πŸ’€ ERRORS πŸ’€

the tmpfile() function shall fail if:

  • EINTR β€” a signal was caught during tmpfile(). rude tbh.
  • EMFILE β€” all file descriptors available to the process are currently open.
  • EMFILE β€” {STREAM_MAX} streams are currently open in the calling process.
  • ENFILE β€” the maximum allowable number of files is currently open in the system.
  • ENOSPC β€” the directory or file system which would contain the new file cannot be expanded. no room bestie, the vibes are full. 😭
  • 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 tmpfile() function may fail if:

  • EMFILE β€” {FOPEN_MAX} streams are currently open in the calling process.
  • ENOMEM β€” insufficient storage space is available.

the following sections are informative.


🧚 EXAMPLES 🧚

πŸ“ Creating a Temporary File

the following example creates a temporary file for update, and returns a pointer to a stream for the created file in the fp variable. slay.

#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 (this 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 like, go off, open as many as you want (within reason, obviously). ✨


πŸ’œ RATIONALE πŸ’œ

None. (she's mysterious like that. no thoughts, head empty, iconic behavior.) πŸ™ˆ


⭐ FUTURE DIRECTIONS ⭐

None. (same energy. no notes. periodt.) πŸ‘‘


πŸ”₯ SEE ALSO πŸ”₯

  • Section 2.5, Standard I/O Streams, fopen(), mkdtemp(), tmpnam(), unlink()
  • 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. 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 bestie that's the whole page, and yes the whole thing is brought to you by IEEE/The Open Group, 2017 β€” TMPFILE(3POSIX) πŸ’– mwah, go make some temp files, drink water, and remember: close your streams. πŸŒΈβœ¨πŸ¦‹