From 6e42995388b49a24c2b0f717ed68a3520752ffdd Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Sun, 13 Jun 2021 17:26:32 +0200 Subject: [PATCH] stdio: add general file management definitions --- STATUS | 14 +++++++++- include/stdio.h | 37 +++++++++++++++++++++++++++ include/target/gint/bits/types/FILE.h | 10 ++++++++ include/unistd.h | 5 ---- 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/STATUS b/STATUS index 6e7fcc4..64e0cf8 100644 --- a/STATUS +++ b/STATUS @@ -86,7 +86,8 @@ DONE: Function/symbol/macro is defined, builds, links, and is tested 7.18 => GCC 7.19 -! 7.19.1 Introduction: TODO + 7.19.1 Introduction: TEST + TODO: Handle wide-oriented streams? (see notes) ! 7.19.4 Operations on files: TODO ! 7.19.5 File access functions: TODO ! 7.19.6 Formatted input/output functions: TODO @@ -182,3 +183,14 @@ What if we wanted to support more locales? -> Fix the "TODO: locale: ..." messages wherever assumptions on the locale are made in the code -> Properly implement strcoll() and strxfrm() + +# Supporting text and binary files (newline translation) + +Because of 7.19.2%1,223 we don't need to support newline translation. + +# Support wide-oriented streams + +This requires all the wide-char functions but also updating fpos_t to be a +structure with at least some mbstate_t member (7.19.2ยง6). + +I really don't want to do that. Use multi-byte functions with UTF-8. diff --git a/include/stdio.h b/include/stdio.h index 01566d3..0648603 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -3,8 +3,45 @@ #include #include + +/* Type of FILE handlers. */ #include +/* Type of positions within files. */ +typedef size_t fpos_t; + +/* Buffering modes. */ +#define _IOFBF 0 +#define _IOLBF 1 +#define _IONBF 2 + +/* Some buffer size for file buffering. */ +/* TODO: We might want a larger BUFSIZ than 256 on fx-CG 50. */ +#define BUFSIZ 256 + +/* End-of-file marker. */ +#define EOF ((int)(-1)) + +/* Number of files guaranteed can be opened simultaneously. */ +/* TODO: FOPEN_MAX is BFile-specific, Vhex might have much larger limits. */ +#define FOPEN_MAX 4 + +/* Recommended length of a filename. */ +/* TODO: FILENAME_MAX = 128 is quite BFile-centric, Vhex might be different. */ +#define FILENAME_MAX 128 + +/* Length a filename for tmpnam. */ +#define L_tmpnam FILENAME_MAX + +/* Seeking positions. */ +#define SEEK_CUR 0 +#define SEEK_END 1 +#define SEEK_SET 2 + +/* Maximum number of unique filenames that tmpnam can generate. */ +/* TODO: Set a useful value in TMP_MAX other than 16*16*16 */ +#define TMP_MAX (16*16*16) + /* Standard input, output and error streams. */ extern FILE *stdin; extern FILE *stdout; diff --git a/include/target/gint/bits/types/FILE.h b/include/target/gint/bits/types/FILE.h index f65bcb4..fb12011 100644 --- a/include/target/gint/bits/types/FILE.h +++ b/include/target/gint/bits/types/FILE.h @@ -1,7 +1,17 @@ #ifndef __BITS_TYPES_FILE_H__ # define __BITS_TYPES_FILE_H__ +#include + typedef struct { + /* BFile handler */ + int fd; + /* Current position in file */ + size_t pos; + /* Buffering mode */ + // TODO + /* Opening mode */ + // TODO } FILE; #endif /*__BITS_TYPES_FILE_H__*/ diff --git a/include/unistd.h b/include/unistd.h index a00b835..76096bc 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -59,11 +59,6 @@ extern ssize_t pread (int __fd, void *__buf, size_t __nbytes, off_t __offset); */ extern ssize_t pwrite (int __fd, const void *__buf, size_t __n, off_t __offset); -/* Values for the WHENCE argument to lseek. */ -#define SEEK_SET 0 /* Seek from beginning of file. */ -#define SEEK_CUR 1 /* Seek from current position. */ -#define SEEK_END 2 /* Seek from end of file. */ - /* ** Move FD's file position to OFFSET bytes from the beginning of the file ** (if WHENCE is SEEK_SET), the current position (if WHENCE is SEEK_CUR),