diff options
| author | Jakob Kaivo <jkk@ung.org> | 2020-08-16 14:00:51 -0400 |
|---|---|---|
| committer | Jakob Kaivo <jkk@ung.org> | 2020-08-16 14:00:51 -0400 |
| commit | 896e28812c51b9ffdf3efc00c7d7ef699e380a58 (patch) | |
| tree | aaa25e093fb4a2ac4c57609e1f745e5ac0734ca8 /src/stdio | |
| parent | 0b0d1fe1d4fbf8560577d81e5af0549683eac8ba (diff) | |
formatting
Diffstat (limited to 'src/stdio')
57 files changed, 132 insertions, 102 deletions
diff --git a/src/stdio/BUFSIZ.c b/src/stdio/BUFSIZ.c index c1b315c4..c59a3851 100644 --- a/src/stdio/BUFSIZ.c +++ b/src/stdio/BUFSIZ.c @@ -1,4 +1,3 @@ -#include <stdio.h> #define BUFSIZ (4096) /** default buffer size **/ @@ -9,7 +8,5 @@ is the buffer size used when buffering is adjusted with FUNCTION(setbuf). /* VALUE_MIN(256) -*/ -/* STDC(1) */ diff --git a/src/stdio/EOF.c b/src/stdio/EOF.c index 84f560a1..2cf3ce60 100644 --- a/src/stdio/EOF.c +++ b/src/stdio/EOF.c @@ -1,4 +1,3 @@ -#include <stdio.h> #define EOF (-1) /** end-of-file **/ @@ -7,6 +6,7 @@ is a sentinal value used to indicated that a TYPEDEF(FILE) stream has reached the end of file. ***/ + /* STDC(1) */ diff --git a/src/stdio/FILE.c b/src/stdio/FILE.c index 854bbcee..d3a29447 100644 --- a/src/stdio/FILE.c +++ b/src/stdio/FILE.c @@ -1,5 +1,5 @@ -#include <stdio.h> -typedef struct __FILE FILE; +typedef struct __FILE + FILE; /** buffered I/O stream **/ @@ -10,6 +10,7 @@ a pointer to its buffer, an error indicator, and an end-of-file indicator. No standard defines the members of THIS(). User programs should not attempt to access or modify its members directly. ***/ + /* STDC(1) */ diff --git a/src/stdio/FILENAME_MAX.c b/src/stdio/FILENAME_MAX.c index 4acdbcfb..1bb13b85 100644 --- a/src/stdio/FILENAME_MAX.c +++ b/src/stdio/FILENAME_MAX.c @@ -1,4 +1,3 @@ -#include <stdio.h> #define FILENAME_MAX (255) /** maximum filename length **/ @@ -7,6 +6,7 @@ is size of the longest array of TYPE(char) that the implementation guarantees can be used as a file name. ***/ + /* STDC(1) */ diff --git a/src/stdio/FOPEN_MAX.c b/src/stdio/FOPEN_MAX.c index 2cfc1fb0..548db477 100644 --- a/src/stdio/FOPEN_MAX.c +++ b/src/stdio/FOPEN_MAX.c @@ -1,4 +1,3 @@ -#include <stdio.h> #define FOPEN_MAX (8) /** maximum open FILE streams **/ @@ -10,7 +9,5 @@ guarantees can be opened at the same time. /* VALUE_MIN(8) -*/ -/* STDC(1) */ diff --git a/src/stdio/L_tmpnam.c b/src/stdio/L_tmpnam.c index d35cb988..8467199a 100644 --- a/src/stdio/L_tmpnam.c +++ b/src/stdio/L_tmpnam.c @@ -1,4 +1,3 @@ -#include <stdio.h> #define L_tmpnam (255) /** temporary file name length **/ @@ -6,6 +5,7 @@ /*** is the maximum length of a temporary filename returned by FUNCTION(tmpnam). ***/ + /* STDC(1) */ diff --git a/src/stdio/NULL.ref b/src/stdio/NULL.ref index d1bb9ab5..b247705b 100644 --- a/src/stdio/NULL.ref +++ b/src/stdio/NULL.ref @@ -1,3 +1,2 @@ -#include <stdio.h> REFERENCE(stddef/NULL.c) STDC(1) diff --git a/src/stdio/SEEK_CUR.c b/src/stdio/SEEK_CUR.c index 558d57ef..efa117f8 100644 --- a/src/stdio/SEEK_CUR.c +++ b/src/stdio/SEEK_CUR.c @@ -1,4 +1,3 @@ -#include <stdio.h> #define SEEK_CUR (1) /** seek forward **/ @@ -7,6 +6,7 @@ is used as the ARGUMENT(whence) argument to FUNCTION(fseek) to indicate that seeking should begin at the current file position and move forward. ***/ + /* STDC(1) */ diff --git a/src/stdio/SEEK_END.c b/src/stdio/SEEK_END.c index 856d2074..15a56439 100644 --- a/src/stdio/SEEK_END.c +++ b/src/stdio/SEEK_END.c @@ -1,4 +1,3 @@ -#include <stdio.h> #define SEEK_END (2) /** seek from end **/ @@ -7,6 +6,7 @@ is used as the ARGUMENT(whence) argument to FUNCTION(fseek) to indicate that seeking should begin at the end of the file and move backward. ***/ + /* STDC(1) */ diff --git a/src/stdio/SEEK_SET.c b/src/stdio/SEEK_SET.c index 213c3c33..d9ce4b88 100644 --- a/src/stdio/SEEK_SET.c +++ b/src/stdio/SEEK_SET.c @@ -1,4 +1,3 @@ -#include <stdio.h> #define SEEK_SET (3) /** seek from beginning **/ @@ -7,6 +6,7 @@ is used as the ARGUMENT(whence) argument to FUNCTION(fseek) to indicate that seeking should begin at the start of the file and move forward. ***/ + /* STDC(1) */ diff --git a/src/stdio/TMP_MAX.c b/src/stdio/TMP_MAX.c index af429fd3..8cedfc60 100644 --- a/src/stdio/TMP_MAX.c +++ b/src/stdio/TMP_MAX.c @@ -1,4 +1,3 @@ -#include <stdio.h> #define TMP_MAX (10000) /** maximum temporary file names **/ @@ -7,6 +6,7 @@ is the minimum number of unique file names FUNCTION(tmpnam) is guaranteed to be able to generate. ***/ + /* STDC(1) */ diff --git a/src/stdio/_IOFBF.c b/src/stdio/_IOFBF.c index 659b787d..3f0714ff 100644 --- a/src/stdio/_IOFBF.c +++ b/src/stdio/_IOFBF.c @@ -1,4 +1,3 @@ -#include <stdio.h> #define _IOFBF (1) /** full buffering **/ @@ -7,6 +6,7 @@ is used as the ARGUMENT(mode) in calls to FUNCTION(setvbuf) to indicate that a stream should be fully buffered. ***/ + /* STDC(1) */ diff --git a/src/stdio/_IOLBF.c b/src/stdio/_IOLBF.c index 8f84ae97..e11fe4fc 100644 --- a/src/stdio/_IOLBF.c +++ b/src/stdio/_IOLBF.c @@ -1,4 +1,3 @@ -#include <stdio.h> #define _IOLBF (2) /** line buffering **/ @@ -7,6 +6,7 @@ is used as the ARGUMENT(mode) in calls to FUNCTION(setvbuf) to indicate that a stream should be line buffered. ***/ + /* STDC(1) */ diff --git a/src/stdio/_IONBF.c b/src/stdio/_IONBF.c index aa88cb9b..215bf26b 100644 --- a/src/stdio/_IONBF.c +++ b/src/stdio/_IONBF.c @@ -1,4 +1,3 @@ -#include <stdio.h> #define _IONBF (3) /** no buffering **/ @@ -7,6 +6,7 @@ is used as the ARGUMENT(mode) in calls to FUNCTION(setvbuf) to indicate that a stream should be unbuffered. ***/ + /* STDC(1) */ diff --git a/src/stdio/clearerr.c b/src/stdio/clearerr.c index b15ba362..44510744 100644 --- a/src/stdio/clearerr.c +++ b/src/stdio/clearerr.c @@ -2,6 +2,7 @@ #include "_stdio.h" /** reset file stream error indicator **/ + void clearerr(FILE * stream) { flockfile(stream); @@ -15,6 +16,7 @@ void clearerr(FILE * stream) /*** clears the error and end-of-file indicators of ARGUMENT(stream). ***/ + /* STDC(1) */ diff --git a/src/stdio/fclose.c b/src/stdio/fclose.c index 1e55a0f0..cc02f5ff 100644 --- a/src/stdio/fclose.c +++ b/src/stdio/fclose.c @@ -1,13 +1,18 @@ +#ifndef _POSIX_SOURCE +#define _POSIX_SOURCE +#define POSIX_FORCED +#endif + #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "_stdio.h" - -#if defined _POSIX_SOURCE || defined _POSIX_C_SOURCE || defined _XOPEN_SOURCE #include <sys/types.h> #include <unistd.h> -#else -#define close(fd) -1 +#include "_stdio.h" + +#ifdef POSIX_FORCED +#include "_syscall.h" +#define close(_fd) __scall1(close, _fd) #endif /** close a file stream **/ @@ -47,6 +52,7 @@ function closes ARGUMENT(stream) and its associated file. Any unwritten data is flushed before closing. Any unread data is discarded. If the buffer was automatically allocated, it is freed. ***/ + /* STDC(1) */ diff --git a/src/stdio/feof.c b/src/stdio/feof.c index 80f4ddca..94531fcf 100644 --- a/src/stdio/feof.c +++ b/src/stdio/feof.c @@ -1,8 +1,9 @@ #include <stdio.h> -#include "_stdio.h" #include "_assert.h" +#include "_stdio.h" /** test for end-of-file **/ + int feof(FILE *stream) { ASSERT_NONNULL(stream); @@ -24,6 +25,7 @@ int feof(FILE *stream) /*** tests for the end-of-file indicator of ARGUMENT(stream). ***/ + /* STDC(1) */ diff --git a/src/stdio/ferror.c b/src/stdio/ferror.c index 66f76a67..b5a4a085 100644 --- a/src/stdio/ferror.c +++ b/src/stdio/ferror.c @@ -3,6 +3,7 @@ #include "_stdio.h" /** tests the file stream error indicator **/ + int ferror(FILE *stream) { ASSERT_NONNULL(stream); @@ -16,6 +17,7 @@ int ferror(FILE *stream) /*** tests the error indicator of ARGUMENT(stream). ***/ + /* STDC(1) */ diff --git a/src/stdio/fflush.c b/src/stdio/fflush.c index 19096714..e6108fbd 100644 --- a/src/stdio/fflush.c +++ b/src/stdio/fflush.c @@ -1,12 +1,16 @@ -#include <stdio.h> -#include "_stdio.h" +#ifndef _POSIX_SOURCE +#define _POSIX_SOURCE +#define POSIX_FORCED +#endif -#ifdef _POSIX_SOURCE +#include <stdio.h> #include <sys/types.h> #include <unistd.h> -#else +#include "_stdio.h" + +#ifdef POSIX_FORCED #include "_syscall.h" -#define write(_fd, _buf, _size) __syscall(__syscall_lookup(write), _fd, _buf, _size) +#define write(_fd, _buf, _size) __scall3(write, _fd, _buf, _size) #endif /** flush buffered writes **/ @@ -51,7 +55,5 @@ If ARGUMENT(stream) is CONSTANT(NULL), THIS() will flush all open streams. /* UNDEFINED(ARGUMENT(stream) is not an output stream) UNDEFINED(ARGUMENT(stream) is an update stream in which the most recent operation was input) -*/ -/* STDC(1) */ diff --git a/src/stdio/fgetc.c b/src/stdio/fgetc.c index 56f1a348..a49a3ce8 100644 --- a/src/stdio/fgetc.c +++ b/src/stdio/fgetc.c @@ -8,6 +8,7 @@ #else /** read a character from a file stream **/ + int fgetc(FILE *stream) { flockfile(stream); @@ -27,6 +28,7 @@ reads the next character from ARGUMENT(stream) as an TYPE(unsigned char) converted to an TYPE(int). The file position indicator of ARGUMENT(stream) is advanced. ***/ + /* STDC(1) */ diff --git a/src/stdio/fgetpos.c b/src/stdio/fgetpos.c index aee57181..04241e79 100644 --- a/src/stdio/fgetpos.c +++ b/src/stdio/fgetpos.c @@ -2,6 +2,7 @@ #include "_stdio.h" /** get the file stream position indicator **/ + int fgetpos(FILE * restrict stream, fpos_t * restrict pos) { flockfile(stream); @@ -17,7 +18,5 @@ for ARGUMENT(stream) into the TYPEDEF(fpos_t) at ARGUMENT(pos). /* UNSPECIFIED(The information stored in TYPEDEF(fpos_t)) -*/ -/* STDC(1) */ diff --git a/src/stdio/fgets.c b/src/stdio/fgets.c index cae9c887..558c2fdc 100644 --- a/src/stdio/fgets.c +++ b/src/stdio/fgets.c @@ -2,6 +2,7 @@ #include "_stdio.h" /** read a string of characters from a file stream **/ + char * fgets(char * restrict s, int n, FILE * restrict stream) { int i = 0; diff --git a/src/stdio/fpos_t.c b/src/stdio/fpos_t.c index 40d304cf..fe55a7af 100644 --- a/src/stdio/fpos_t.c +++ b/src/stdio/fpos_t.c @@ -1,5 +1,5 @@ -#include <stdio.h> -typedef struct __fpos_t * fpos_t; +typedef struct __fpos_t * + fpos_t; /** file position **/ @@ -7,6 +7,7 @@ typedef struct __fpos_t * fpos_t; is used to record information about individual positions within a TYPEDEF(FILE) stream. ***/ + /* STDC(1) */ diff --git a/src/stdio/fprintf.c b/src/stdio/fprintf.c index 40a2d42d..0e6509f8 100644 --- a/src/stdio/fprintf.c +++ b/src/stdio/fprintf.c @@ -1,8 +1,9 @@ +#include <stdarg.h> #include <stdio.h> -#include "stdarg.h" #include "_stdio.h" /** write formatted output to a file stream **/ + int fprintf(FILE * restrict stream, const char * restrict format, ...) { int ret = 0; @@ -24,6 +25,7 @@ int fprintf(FILE * restrict stream, const char * restrict format, ...) writes a formatted string to ARGUMENT(stream). The format of ARGUMENT(format) and the variadic arguments is the same as that for FUNCTION(printf). ***/ + /* STDC(1) */ diff --git a/src/stdio/fputs.c b/src/stdio/fputs.c index 22ee7d28..4f5cea8d 100644 --- a/src/stdio/fputs.c +++ b/src/stdio/fputs.c @@ -2,6 +2,7 @@ #include "_stdio.h" /** write a string to a file stream **/ + int fputs(const char * restrict s, FILE * restrict stream) { flockfile(stream); @@ -23,6 +24,7 @@ int fputs(const char * restrict s, FILE * restrict stream) writes the string ARGUMENT(s) to ARGUMENT(stream), not including the terminating CHAR(\0) character. ***/ + /* STDC(1) */ diff --git a/src/stdio/fread.c b/src/stdio/fread.c index 7929d495..bf8c5fd2 100644 --- a/src/stdio/fread.c +++ b/src/stdio/fread.c @@ -2,6 +2,7 @@ #include "_stdio.h" /** read directly from a file stream **/ + size_t fread(void * restrict ptr, size_t size, size_t nmemb, FILE * restrict stream) { unsigned char *buf = ptr; @@ -34,6 +35,7 @@ from ARGUMENT(stream) into the array at ARGUMENT(ptr). The file position indicate is advanced by the number of bytes read. ***/ + /* STDC(1) */ diff --git a/src/stdio/freopen.c b/src/stdio/freopen.c index 516684b4..0afec064 100644 --- a/src/stdio/freopen.c +++ b/src/stdio/freopen.c @@ -3,19 +3,19 @@ #define POSIX_FORCED #endif -#include <stdio.h> -#include <string.h> -#include <errno.h> #include <sys/types.h> +#include <errno.h> #include <fcntl.h> +#include <stdio.h> +#include <string.h> #include <unistd.h> #include "_stdio.h" #ifdef POSIX_FORCED #include "termios/_termios.h" #include "_syscall.h" -#define open(fname, flags, mode) __scall3(open, fname, flags, mode) -#define isatty(fd) ioctl(fd, TCFLSH, 0) +#define open(_p, _f, _m) __scall3(open, _p, _f, _m) +#define isatty(_fd) ioctl(_fd, TCFLSH, 0) #endif /** reopen a file stream with a new file **/ @@ -102,6 +102,7 @@ ignoring any errors. The error and end-of-file indicators are cleared. ***/ + /* STDC(1) */ diff --git a/src/stdio/fscanf.c b/src/stdio/fscanf.c index 05ec5ed8..81279d46 100644 --- a/src/stdio/fscanf.c +++ b/src/stdio/fscanf.c @@ -1,8 +1,9 @@ +#include <stdarg.h> #include <stdio.h> -#include "stdarg.h" #include "_stdio.h" /** read formatted input from a file stream **/ + int fscanf(FILE * restrict stream, const char * restrict format, ...) { int ret = 0; @@ -24,6 +25,7 @@ int fscanf(FILE * restrict stream, const char * restrict format, ...) reads formatted input from ARGUMENT(stream). The format of ARGUMENT(format) at the variadic arguments is the same as that for FUNCTION(scanf). ***/ + /* STDC(1) */ diff --git a/src/stdio/fseek.c b/src/stdio/fseek.c index 2cee57a1..42fb0d9f 100644 --- a/src/stdio/fseek.c +++ b/src/stdio/fseek.c @@ -1,6 +1,7 @@ #include <stdio.h> /** set the file position indicator **/ + int fseek(FILE *stream, long int offset, int whence) { (void)stream; (void)offset; @@ -29,7 +30,5 @@ any characters pushed with fn(ungetc). /* UNDEFINED(Specifying CONSTANT(SEEK_END) for ARGUMENT(whence) on a binary file) UNDEFINED(Specifying a value for ARGUMENT(offset) other than 0 or a previous return value of FUNCTION(ftell) on a text file) -*/ -/* STDC(1) */ diff --git a/src/stdio/fsetpos.c b/src/stdio/fsetpos.c index 8ec7cdd8..33c055ea 100644 --- a/src/stdio/fsetpos.c +++ b/src/stdio/fsetpos.c @@ -1,6 +1,7 @@ #include <stdio.h> /** set the file position indicator **/ + int fsetpos(FILE *stream, const fpos_t *pos) { (void)stream; (void)pos; @@ -16,6 +17,7 @@ FUNCTION(fgetpos). A successful call to THIS() clears the end-of-file indicator and discards any characters pushed back with FUNCTION(ungetc). ***/ + /* STDC(1) */ diff --git a/src/stdio/ftell.c b/src/stdio/ftell.c index 796a468c..f1fab68a 100644 --- a/src/stdio/ftell.c +++ b/src/stdio/ftell.c @@ -1,6 +1,7 @@ #include <stdio.h> /** get the file position indicator **/ + long int ftell(FILE *stream) { (void)stream; @@ -20,7 +21,5 @@ For binary streams, the indicator is the current byte position. /* UNSPECIFIED(The meaning of the file position indicator for text streams) -*/ -/* STDC(1) */ diff --git a/src/stdio/fwrite.c b/src/stdio/fwrite.c index 047ee892..f7fe07f9 100644 --- a/src/stdio/fwrite.c +++ b/src/stdio/fwrite.c @@ -1,6 +1,7 @@ #include <stdio.h> /** write directly to a file stream **/ + size_t fwrite(const void * restrict ptr, size_t size, size_t nmemb, FILE * restrict stream) { unsigned char *buf = (unsigned char *)ptr; @@ -31,6 +32,7 @@ the array ARGUMENT(ptr) to ARGUMENT(stream). The file position inidicate is advanced by the number of bytes successfully written. ***/ + /* STDC(1) */ diff --git a/src/stdio/getc.c b/src/stdio/getc.c index 11a75d4e..f176ef5b 100644 --- a/src/stdio/getc.c +++ b/src/stdio/getc.c @@ -1,6 +1,7 @@ #include <stdio.h> /** read a character from a file stream **/ + int getc(FILE *stream) { /* @@ -14,6 +15,7 @@ int getc(FILE *stream) is the equivalent of FUNCTION(fgetc) except that if it is defined as a macro, it may evaluate ARGUMENT(stream) more than once. ***/ + /* STDC(1) */ diff --git a/src/stdio/getchar.c b/src/stdio/getchar.c index 3bd12654..d09bbdfc 100644 --- a/src/stdio/getchar.c +++ b/src/stdio/getchar.c @@ -1,6 +1,7 @@ #include <stdio.h> /** read a character from stdin **/ + int getchar(void) { /* @@ -13,6 +14,7 @@ int getchar(void) /*** reads the next character from ARGUMENT(stdin). ***/ + /* STDC(1) */ diff --git a/src/stdio/gets.c b/src/stdio/gets.c index fbe16cd2..8ad0998a 100644 --- a/src/stdio/gets.c +++ b/src/stdio/gets.c @@ -2,6 +2,7 @@ #include "limits.h" /** read a line from stdin **/ + char * gets(char *s) { /* @@ -23,6 +24,7 @@ after the last character read into the array. If end-of-file is reached before any characters are read, the contents of ARGUMENT(s) remain unchanged. ***/ + /* STDC(1,201112) */ diff --git a/src/stdio/perror.c b/src/stdio/perror.c index 2aae8470..788bb4fc 100644 --- a/src/stdio/perror.c +++ b/src/stdio/perror.c @@ -1,8 +1,9 @@ +#include <errno.h> #include <stdio.h> -#include "string.h" -#include "errno.h" +#include <string.h> /** print an error message **/ + void perror(const char *s) { if (s != NULL && *s != '\0') { @@ -23,7 +24,5 @@ pointed to by ARGUMENT(s), a colon (CHAR(:)), and a space. /* POSIX_(L_C_MESSAGES) -*/ -/* STDC(1) */ diff --git a/src/stdio/printf.c b/src/stdio/printf.c index 1dedbbea..bc90c766 100644 --- a/src/stdio/printf.c +++ b/src/stdio/printf.c @@ -1,8 +1,9 @@ +#include <stdarg.h> #include <stdio.h> -#include "stdarg.h" #include "_stdio.h" /** write formatted output **/ + int printf(const char *format, ...) { int ret = 0; @@ -103,7 +104,5 @@ FLAG(CHAR(%), `Outputs a literal CHAR(%).') IMPLEMENTATION(`The format of CHAR(p) conversions', `STRING(0x%0ARGUMENT(n)x), where ARGUMENT(n) is the number of hexadecimal digits in a canonical address on the platform of execution.') UNDEFINED(`Precision with a conversion specifier other than CHAR(d), CHAR(i), CHAR(o), CHAR(u), CHAR(x), CHAR(X), CHAR(e), CHAR(E), CHAR(f), CHAR(g), CHAR(G), or CHAR(s)') UNDEFINED(TODO: Using h or l for !(diouxXn) or L for !(eEfgG)) -*/ -/* STDC(1) */ diff --git a/src/stdio/putc.c b/src/stdio/putc.c index c3509ee2..48e11719 100644 --- a/src/stdio/putc.c +++ b/src/stdio/putc.c @@ -1,6 +1,7 @@ #include <stdio.h> /** write a character to a file stream **/ + int putc(int c, FILE *stream) { /* @@ -14,6 +15,7 @@ int putc(int c, FILE *stream) is equivalent of FUNCTION(fputc), except that if it is defined as a macro, it may evaluate ARGUMENT(stream) more than once. ***/ + /* STDC(1) */ diff --git a/src/stdio/putchar.c b/src/stdio/putchar.c index cb12ec0c..992d2f1e 100644 --- a/src/stdio/putchar.c +++ b/src/stdio/putchar.c @@ -1,6 +1,7 @@ #include <stdio.h> /** write a character to stdout **/ + int putchar(int c) { /* @@ -14,6 +15,7 @@ int putchar(int c) writes the character ARGUMENT(c) (converted to an TYPE(unsigned char)) to IDENTIFIER(stdout). ***/ + /* STDC(1) */ diff --git a/src/stdio/puts.c b/src/stdio/puts.c index 9e6c4c5b..93b98c3f 100644 --- a/src/stdio/puts.c +++ b/src/stdio/puts.c @@ -2,6 +2,7 @@ #include "_stdio.h" /** write a string to stoud **/ + int puts(const char *s) { int ret = 1; @@ -34,6 +35,7 @@ int puts(const char *s) function writes the string pointed to by ARGUMENT(s) to IDENTIFIER(stdout), followed by a newline. The terminated CHAR(\0) is not written. ***/ + /* STDC(1) */ diff --git a/src/stdio/remove.c b/src/stdio/remove.c index 2a10e443..39b5a74c 100644 --- a/src/stdio/remove.c +++ b/src/stdio/remove.c @@ -1,15 +1,18 @@ +#ifndef _POSIX_SOURCE +#define _POSIX_SOURCE +#define POSIX_FORCED +#endif + #include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> -#ifdef _POSIX_SOURCE -#include "sys/types.h" -#include "sys/stat.h" -#include "unistd.h" -#else - struct stat { int st_mode; }; -#define stat(f, b) (void)f -#define S_ISDIR(m) (m = 0) -#define rmdir(f) (-1) -#define unlink(f) (-1) +#ifdef POSIX_FORCED +#include "_syscall.h" +#define stat(_f, _b) __scall2(stat, _f, _b) +#define rmdir(_f) __scall1(rmdir, _f) +#define unlink(_f) __scall1(unlink, _f) #endif /** delete a file **/ @@ -31,7 +34,5 @@ open that file will fail unless creating a new file. /* IMPLEMENTATION(Whether the file is removed if it is open) -*/ -/* STDC(1) */ diff --git a/src/stdio/rename.c b/src/stdio/rename.c index 589b3690..ad1be639 100644 --- a/src/stdio/rename.c +++ b/src/stdio/rename.c @@ -1,20 +1,12 @@ +#include <errno.h> #include <stdio.h> -#include "errno.h" #include "_syscall.h" /** rename a file **/ + int rename(const char *old, const char *new) { - SYSCALL_NUMBER(sc, rename, -1); - int err = 0; - - err = __syscall(sc, old, new); - if (err < 0) { - errno = -err; - return -1; - } - - return 0; + SYSCALL(rename, int, -1, old, new, 0, 0, 0, 0); } /*** @@ -24,7 +16,5 @@ ARGUMENT(new). /* IMPLEMENTATION(Behavior if ARGUMENT(new) exists prior to THIS() being called) -*/ -/* STDC(1) */ diff --git a/src/stdio/rewind.c b/src/stdio/rewind.c index 73be1f57..94694edb 100644 --- a/src/stdio/rewind.c +++ b/src/stdio/rewind.c @@ -1,6 +1,7 @@ #include <stdio.h> /** reset file position indicator **/ + void rewind(FILE *stream) { fseek(stream, 0L, SEEK_SET); @@ -11,6 +12,7 @@ void rewind(FILE *stream) sets the file position indicator of ARGUMENT(stream) to the beginning of the file. The error indicator will be cleared. ***/ + /* STDC(1) */ diff --git a/src/stdio/scanf.c b/src/stdio/scanf.c index efec61d8..23e82417 100644 --- a/src/stdio/scanf.c +++ b/src/stdio/scanf.c @@ -1,8 +1,9 @@ +#include <stdarg.h> #include <stdio.h> -#include "stdarg.h" #include "_stdio.h" /** read formatted input **/ + int scanf(const char * restrict format, ...) { int ret = 0; @@ -25,6 +26,7 @@ reads formatted input from macro(stdin). FIXME: scanf format goes here ***/ + /* STDC(1) */ diff --git a/src/stdio/setbuf.c b/src/stdio/setbuf.c index 351db3d3..1efa8ea1 100644 --- a/src/stdio/setbuf.c +++ b/src/stdio/setbuf.c @@ -1,6 +1,7 @@ #include <stdio.h> /** specify file stream buffer **/ + void setbuf(FILE * restrict stream, char * restrict buf) { if (buf) { @@ -19,6 +20,7 @@ If ARGUMENT(buf) is CONSTANT(NULL), ARGUMENT(stream) will become unbuffered. It equivalent of: LITERAL(setvbuf(stream, NULL, _IONBF, 0);) ***/ + /* STDC(1) */ diff --git a/src/stdio/setvbuf.c b/src/stdio/setvbuf.c index c3aed354..2edfdaea 100644 --- a/src/stdio/setvbuf.c +++ b/src/stdio/setvbuf.c @@ -1,5 +1,5 @@ -#include <stdio.h> #include <errno.h> +#include <stdio.h> #include <stdlib.h> #include "_stdio.h" @@ -72,6 +72,7 @@ an array of at least ARGUMENT(size) characters. The ARGUMENT(size) argument specifies the size of the buffer. ***/ + /* STDC(1) */ diff --git a/src/stdio/size_t.ref b/src/stdio/size_t.ref index 5b9b0797..fc611c25 100644 --- a/src/stdio/size_t.ref +++ b/src/stdio/size_t.ref @@ -1,3 +1,2 @@ -#include <stdio.h> REFERENCE(stddef/size_t.c) STDC(1) diff --git a/src/stdio/sprintf.c b/src/stdio/sprintf.c index 9e651adb..d6776fe4 100644 --- a/src/stdio/sprintf.c +++ b/src/stdio/sprintf.c @@ -1,15 +1,9 @@ +#include <stdarg.h> #include <stdio.h> -#include "stdarg.h" #include "_stdio.h" -#if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ -#include "stdint.h" -#else -#include "limits.h" -#define SIZE_MAX INT_MAX -#endif - /** write formatted output to a string **/ + int sprintf(char * restrict s, const char * restrict format, ...) { int ret = 0; @@ -17,7 +11,7 @@ int sprintf(char * restrict s, const char * restrict format, ...) struct io_options opt = {0}; opt.fnname = "sprintf"; opt.string = s; - opt.maxlen = SIZE_MAX; + opt.maxlen = (size_t)-1; va_start(ap, format); ret = __printf(&opt, format, ap); va_end(ap); @@ -32,6 +26,7 @@ writes a formatted string to the buffer at ARGUMENT(s). The format of ARGUMENT(format) and the variadic arguments is the same as that for FUNCTION(printf). ***/ + /* STDC(1) */ diff --git a/src/stdio/sscanf.c b/src/stdio/sscanf.c index 10a08447..e8ccaf9e 100644 --- a/src/stdio/sscanf.c +++ b/src/stdio/sscanf.c @@ -1,8 +1,9 @@ +#include <stdarg.h> #include <stdio.h> -#include "stdarg.h" #include "_stdio.h" /** read formatted input from a string **/ + int sscanf(const char * restrict s, const char * restrict format, ...) { int ret = 0; @@ -25,6 +26,7 @@ reads formatted input from the string ARGUMENT(s). The format of ARGUMENT(format) at the variadic arguments is the same as that for FUNCTION(scanf). ***/ + /* STDC(1) */ diff --git a/src/stdio/stderr.c b/src/stdio/stderr.c index f2841f0d..8ec8a9aa 100644 --- a/src/stdio/stderr.c +++ b/src/stdio/stderr.c @@ -1,4 +1,3 @@ -#include <stdio.h> #define stderr __stderr /** standard error **/ @@ -6,6 +5,7 @@ /*** is the standard error stream. ***/ + /* STDC(1) */ diff --git a/src/stdio/stdin.c b/src/stdio/stdin.c index 329d6d23..5fb14c70 100644 --- a/src/stdio/stdin.c +++ b/src/stdio/stdin.c @@ -1,4 +1,3 @@ -#include <stdio.h> #define stdin __stdin /** standard input **/ @@ -6,6 +5,7 @@ /*** is the standard input stream. ***/ + /* STDC(1) */ diff --git a/src/stdio/stdout.c b/src/stdio/stdout.c index 08aefa24..7c62dfa0 100644 --- a/src/stdio/stdout.c +++ b/src/stdio/stdout.c @@ -1,4 +1,3 @@ -#include <stdio.h> #define stdout __stdout /** standard output **/ @@ -6,6 +5,7 @@ /*** is the standard output stream. ***/ + /* STDC(1) */ diff --git a/src/stdio/tmpfile.c b/src/stdio/tmpfile.c index 7143b491..06662dd7 100644 --- a/src/stdio/tmpfile.c +++ b/src/stdio/tmpfile.c @@ -1,6 +1,7 @@ #include <stdio.h> -/* open a temporary file stream */ +/** open a temporary file stream **/ + FILE * tmpfile(void) { char *path = "FIXME: A temporary file name *not* calling tmpnam()"; @@ -27,7 +28,5 @@ or when the program exits. /* IMPLEMENTATION(Whether the temporary file is removed if the program terminates abnormally) -*/ -/* STDC(1) */ diff --git a/src/stdio/tmpnam.c b/src/stdio/tmpnam.c index b4b5d932..f5e79c55 100644 --- a/src/stdio/tmpnam.c +++ b/src/stdio/tmpnam.c @@ -1,6 +1,7 @@ #include <stdio.h> /** generate a temporary file name **/ + char * tmpnam(char *s) { static int ntimescalled = 0; @@ -37,7 +38,5 @@ this array. /* IMPLEMENTATION(Behavior if THIS() is called more than CONSTANT(TMP_MAX) times) -*/ -/* STDC(1) */ diff --git a/src/stdio/ungetc.c b/src/stdio/ungetc.c index 5629679a..c34f4d20 100644 --- a/src/stdio/ungetc.c +++ b/src/stdio/ungetc.c @@ -2,6 +2,7 @@ #include "_stdio.h" /** push a character back into an input stream **/ + int ungetc(int c, FILE *stream) { (void)c; (void)stream; @@ -32,6 +33,7 @@ position indicator is decremented. Calling THIS() on a binary stream when the file position indicator is zero is obsolete in ISO/IEC 9899:1999. ***/ + /* STDC(1) */ diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c index 55a9a140..db60a8fd 100644 --- a/src/stdio/vfprintf.c +++ b/src/stdio/vfprintf.c @@ -1,8 +1,9 @@ +#include <stdarg.h> #include <stdio.h> -#include "stdarg.h" #include "_stdio.h" /** write formatted output to a file stream **/ + int vfprintf(FILE * restrict stream, const char * restrict format, va_list arg) { int ret = 0; @@ -24,6 +25,7 @@ initialized with FUNCTION(va_start) prior to calling THIS(). The THIS() function does not call FUNCTION(va_end), so the calling function is responsible for this. ***/ + /* STDC(1) */ diff --git a/src/stdio/vsprintf.c b/src/stdio/vsprintf.c index 14c7f7fb..8ddc4642 100644 --- a/src/stdio/vsprintf.c +++ b/src/stdio/vsprintf.c @@ -1,8 +1,9 @@ +#include <stdarg.h> #include <stdio.h> -#include "stdarg.h" #include "_stdio.h" /** write formatted output to a string **/ + int vsprintf(char *s, const char *format, va_list arg) { int ret = 0; @@ -24,6 +25,7 @@ initialized with FUNCTION(va_start) prior to calling THIS(). The THIS() function does not call FUNCTION(va_end), so the calling function is responsible for this. ***/ + /* STDC(1) */ |
