diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-02-08 18:42:39 -0500 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-02-08 18:42:39 -0500 |
commit | 7ef8a7379f7f7d09e71ccae2a0b688c3cd80423f (patch) | |
tree | 092ab0aed1769117fd7b28b8592f6f96b0e0d5af /src/stdio/fopen.c | |
parent | 6acf19370e8adff79cd83b257d3f04aeaf2a59dd (diff) |
merge sources into single tree
Diffstat (limited to 'src/stdio/fopen.c')
-rw-r--r-- | src/stdio/fopen.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/stdio/fopen.c b/src/stdio/fopen.c new file mode 100644 index 00000000..935885d9 --- /dev/null +++ b/src/stdio/fopen.c @@ -0,0 +1,59 @@ +#include <stdio.h> +#include "stdlib.h" +#include "nonstd/internal.h" +#include "nonstd/io.h" + +/** open a file stream **/ +FILE * fopen(const char * restrict filename, const char * restrict mode) +{ + FILE *f = calloc(1, sizeof(*f)); + f->fd = -1; + if (freopen(filename, mode, f) == NULL) { + free(f); + return NULL; + } + + if (__libc(FILE_TAIL)) { + f->prev = __libc(FILE_TAIL); + f->prev->next = f; + } + + /* __libc(FILE_TAIL) = f; */ + + /* + RETURN_SUCCESS(a pointer to the new file stream); + RETURN_FAILURE(CONSTANT(NULL)); + */ + return f; +} + +/*** +opens a file stream associated with the file ARGUMENT(filename). + +The type of file and allowed operations are determined by ARGUMENT(mode): + +FLAG(LITERAL(r), text file; read-only) +FLAG(LITERAL(w), text file; write-only; truncate to 0 bytes) +FLAG(LITERAL(a), text file; append) +FLAG(LITERAL(rb), binary file; read-only) +FLAG(LITERAL(wb), binary file; write-only; truncate to 0 bytes) +FLAG(LITERAL(ab), binary file; append) +FLAG(LITERAL(r+), text file; update (read and write)) +FLAG(LITERAL(w+), text file; update (read and write); truncate to 0 bytes) +FLAG(LITERAL(a+), text file; update (read and write); append data to end of file) +FLAG(LITERAL(r+b), binary file; update (read and write)) +FLAG(LITERAL(rb+), binary file; update (read and write)) +FLAG(LITERAL(w+b), binary file; update (read and write); truncate to 0 bytes) +FLAG(LITERAL(wb+), binary file; update (read and write); truncate to 0 bytes) +FLAG(LITERAL(a+b), binary file; update (read and write); append data to end of file) +FLAG(LITERAL(ab+), binary file; update (read and write); append data to end of file) + +File streams are opened in fully buffered mode if and only if +ARGUMENT(filename) is not an interactive device. + +The error and end-of-file indicators are cleared. +***/ + +/* +STDC(1) +*/ |