summaryrefslogtreecommitdiff
path: root/src/stdio/freopen.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-02-08 18:42:39 -0500
committerJakob Kaivo <jkk@ung.org>2019-02-08 18:42:39 -0500
commit7ef8a7379f7f7d09e71ccae2a0b688c3cd80423f (patch)
tree092ab0aed1769117fd7b28b8592f6f96b0e0d5af /src/stdio/freopen.c
parent6acf19370e8adff79cd83b257d3f04aeaf2a59dd (diff)
merge sources into single tree
Diffstat (limited to 'src/stdio/freopen.c')
-rw-r--r--src/stdio/freopen.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/stdio/freopen.c b/src/stdio/freopen.c
new file mode 100644
index 00000000..cddf296a
--- /dev/null
+++ b/src/stdio/freopen.c
@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include "errno.h"
+#include "nonstd/io.h"
+
+#ifdef _POSIX_SOURCE
+#include "fcntl.h"
+#else
+#define open(fname, flags, mode) (filename ? -1 : -1)
+#endif
+
+/** reopen a file stream with a new file **/
+FILE * freopen(const char * restrict filename, const char * restrict mode, FILE * restrict stream)
+{
+ flockfile(stream);
+ (void)mode;
+
+ int openmode = 0; /* modetoflag(mode); */
+ if (openmode == 0) {
+ #ifdef EINVAL
+ errno = EINVAL;
+ #endif
+ return NULL;
+ }
+
+ int fd = open(filename, openmode, 0);
+ if (fd == -1) {
+ /* set errno */
+ return NULL;
+ }
+
+ stream->fd = fd;
+ stream->nlocks = 0;
+
+ /*
+ RETURN_SUCCESS(ARGUMENT(stream));
+ RETURN_FAILURE(CONSTANT(NULL));
+ */
+ return stream;
+}
+
+/***
+changes the file associated with ARGUMENT(stream) to
+ARGUMENT(filename). The meaning of ARGUMENT(mode) is the same as with
+FUNCTION(fopen).
+
+Whatever file is currently associated with ARGUMENT(stream) is closed,
+ignoring any errors.
+
+The error and end-of-file indicators are cleared.
+***/
+/*
+STDC(1)
+*/