summaryrefslogtreecommitdiff
path: root/libpsx/include
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2021-10-24 02:57:40 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2021-10-24 03:10:03 +0200
commita34280dec778b7f6ba1e68450aee1c5b543aeda8 (patch)
treea56dc2569f49d8b771f5a117649241b1eef57c2a /libpsx/include
parent9c6112eb5bec5e66bff092e8131839f38a2be39b (diff)
Provide buffered fread(3)
In order to reduce calls to seek(2) (which are very expensive), this commit keeps a sector-sized cache for each available FILE instance, except from the standard streams, of course. As expected, this allows calls to fread(3) to react much faster when small, contiguous chunks are read.
Diffstat (limited to 'libpsx/include')
-rw-r--r--libpsx/include/stdio.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/libpsx/include/stdio.h b/libpsx/include/stdio.h
index 456a438..89d8817 100644
--- a/libpsx/include/stdio.h
+++ b/libpsx/include/stdio.h
@@ -70,6 +70,12 @@ typedef struct
unsigned int eof;
/** Error marker */
unsigned int error;
+ /** Sector buffer. */
+ unsigned char *const buf;
+ /** Last used sector for reading. */
+ size_t last_sect;
+ /** Sector buffer can be used for reading. */
+ unsigned int cache_available;
}FILE;
extern FILE *const stdin, *const stdout, *const stderr;
@@ -111,7 +117,7 @@ int vprintf(const char *fmt, va_list ap);
FILE *fdopen(int fildes, const char *mode);
FILE *fopen(const char *path, const char *mode);
int fclose(FILE *stream);
-int fread(void *ptr, int size, int nmemb, FILE *f);
+size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
size_t fwrite(void *ptr, size_t size, size_t nmemb, FILE *stream);
int fgetc(FILE *f);