diff --git a/headers/posix/stdio.h b/headers/posix/stdio.h index 02ccc00c81..f140dbbd82 100644 --- a/headers/posix/stdio.h +++ b/headers/posix/stdio.h @@ -1,4 +1,4 @@ -/* +/* ** Distributed under the terms of the OpenBeOS License. */ #ifndef _STDIO_H_ @@ -96,6 +96,7 @@ extern void perror(const char *errorPrefix); /* file I/O */ extern int fflush(FILE *stream); extern int fflush_unlocked(FILE *stream); +extern int fpurge(FILE *stream); extern int fgetpos(FILE *stream, fpos_t *position); extern int fsetpos(FILE *stream, const fpos_t *position); diff --git a/headers/posix/stdio_ext.h b/headers/posix/stdio_ext.h index e5f3a6e773..76cbe04e23 100644 --- a/headers/posix/stdio_ext.h +++ b/headers/posix/stdio_ext.h @@ -17,12 +17,12 @@ extern "C" { /* The following stdio extensions are not implemented yet */ /* extern size_t __fufsize(FILE* stream); */ -/* extern int __freading(FILE* stream); */ +extern int __freading(FILE* stream); /* extern int __fwriting(FILE* stream); */ /* extern int __freadable(FILE* stream); */ /* extern int __fwritable(FILE* stream); */ /* extern int __flbf(FILE* stream); */ -/* extern void __fpurge(FILE* stream); */ +extern void __fpurge(FILE* stream); /* extern size_t __fpending(FILE* stream); */ extern void _flushlbf(void); diff --git a/src/system/libroot/posix/stdio/Jamfile b/src/system/libroot/posix/stdio/Jamfile index c731492c5f..1289b74ca3 100644 --- a/src/system/libroot/posix/stdio/Jamfile +++ b/src/system/libroot/posix/stdio/Jamfile @@ -3,7 +3,9 @@ SubDir HAIKU_TOP src system libroot posix stdio ; UsePrivateSystemHeaders ; MergeObject posix_stdio.o : + __freading.cpp _fseek.c + fpurge.cpp remove.c rename.c # The other files are superseded by the glibc libio/stdio stuff diff --git a/src/system/libroot/posix/stdio/__freading.cpp b/src/system/libroot/posix/stdio/__freading.cpp new file mode 100644 index 0000000000..ece7bc922c --- /dev/null +++ b/src/system/libroot/posix/stdio/__freading.cpp @@ -0,0 +1,17 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include +#include + + +int +__freading(FILE* stream) +{ + // Return true, if writing is not allowed or the last operation was a read. + return (stream->_flags & _IO_NO_WRITES) != 0 + || ((stream->_flags & (_IO_NO_READS | _IO_CURRENTLY_PUTTING)) == 0 + && stream->_IO_read_base != NULL); +} diff --git a/src/system/libroot/posix/stdio/fpurge.cpp b/src/system/libroot/posix/stdio/fpurge.cpp new file mode 100644 index 0000000000..e007ffac32 --- /dev/null +++ b/src/system/libroot/posix/stdio/fpurge.cpp @@ -0,0 +1,32 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include +#include +#include + + +int +fpurge(FILE* stream) +{ + // purge read and write buffers + stream->_IO_read_end = stream->_IO_read_ptr; + stream->_IO_write_ptr = stream->_IO_write_base; + + // free ungetc buffer + if (stream->_IO_save_base != NULL) { + free(stream->_IO_save_base); + stream->_IO_save_base = NULL; + } + + return 0; +} + + +void +__fpurge(FILE* stream) +{ + fpurge(stream); +}