summaryrefslogtreecommitdiff
path: root/libc/stdio/tmpfile.c
diff options
context:
space:
mode:
authorMarcus Huderle <huderlem@gmail.com>2017-12-27 16:22:00 -0600
committerGitHub <noreply@github.com>2017-12-27 16:22:00 -0600
commit6b611a3046a694d3972f2aa4df90d3ef78801217 (patch)
tree05f295c00cbbc1d5987a05da37e746fb841d4d83 /libc/stdio/tmpfile.c
parent58c860d6c48324eba66dd19540db5584d832cf58 (diff)
parentd88495e3f4061a411e654c7307aa94ac8a98c94b (diff)
Merge pull request #13 from ProjectRevoTPP/libc
add libc building to agbcc.
Diffstat (limited to 'libc/stdio/tmpfile.c')
-rw-r--r--libc/stdio/tmpfile.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/libc/stdio/tmpfile.c b/libc/stdio/tmpfile.c
new file mode 100644
index 0000000..4b31396
--- /dev/null
+++ b/libc/stdio/tmpfile.c
@@ -0,0 +1,77 @@
+/*
+FUNCTION
+<<tmpfile>>---create a temporary file
+
+INDEX
+ tmpfile
+INDEX
+ _tmpfile_r
+
+ANSI_SYNOPSIS
+ #include <stdio.h>
+ FILE *tmpfile(void);
+
+ FILE *_tmpfile_r(void *<[reent]>);
+
+TRAD_SYNOPSIS
+ #include <stdio.h>
+ FILE *tmpfile();
+
+ FILE *_tmpfile_r(<[reent]>)
+ char *<[reent]>;
+
+DESCRIPTION
+Create a temporary file (a file which will be deleted automatically),
+using a name generated by <<tmpnam>>. The temporary file is opened with
+the mode <<"wb+">>, permitting you to read and write anywhere in it
+as a binary file (without any data transformations the host system may
+perform for text files).
+
+The alternate function <<_tmpfile_r>> is a reentrant version. The
+argument <[reent]> is a pointer to a reentrancy structure.
+
+RETURNS
+<<tmpfile>> normally returns a pointer to the temporary file. If no
+temporary file could be created, the result is NULL, and <<errno>>
+records the reason for failure.
+
+PORTABILITY
+Both ANSI C and the System V Interface Definition (Issue 2) require
+<<tmpfile>>.
+
+Supporting OS subroutines required: <<close>>, <<fstat>>, <<getpid>>,
+<<isatty>>, <<lseek>>, <<open>>, <<read>>, <<sbrk>>, <<write>>.
+
+<<tmpfile>> also requires the global pointer <<environ>>.
+*/
+
+#include <stdio.h>
+#include <errno.h>
+
+FILE *
+_DEFUN (_tmpfile_r, (ptr),
+ struct _reent *ptr)
+{
+ FILE *fp;
+ int e;
+ char *f;
+ char buf[L_tmpnam];
+
+ if ((f = _tmpnam_r (ptr, buf)) == NULL)
+ return NULL;
+ fp = fopen (f, "wb+");
+ e = ptr->_errno;
+ _CAST_VOID remove (f);
+ ptr->_errno = e;
+ return fp;
+}
+
+#ifndef _REENT_ONLY
+
+FILE *
+_DEFUN_VOID (tmpfile)
+{
+ return _tmpfile_r (_REENT);
+}
+
+#endif