Skip to content

Commit

Permalink
stdio/file: fix multiple issues in file stream functions
Browse files Browse the repository at this point in the history
Fixed the following issues:
 - fclose returned -EINVAL instead of EOF
 - fclose did not return EOF on stream buffer flushing errors
 - removed unnecessary stream buffer flushing in fopen & fdopen
 - freopen did not return NULL on stream buffer flushing errors
 - fseek/fseeko/fsetpos cleared F_EOF flag on error
 - ftell/ftello/fgetpos cleared F_EOF flag
 - ftell/ftello/fgetpos flushed the stream buffer
 - non-blocking fflush was unsupported
 - flushing failed for non-seekable streams (lseek returning ESPIPE)
 - interleaved fread/fwrite failed for non-seekable streams (lseek returning ESPIPE)
 - non-blocking fread was unsupported
 - unbuffered fread did not set F_ERROR flag on read errors
 - unbuffered fread did not set F_EOF flag at end-of-file
 - buffered fread did not set F_ERROR flag on write buffer flushing errors
 - buffered fread did not return 0 on write buffer flushing errors
 - buffered fread did not set F_ERROR flag on buffer refilling errors
 - buffered fread incorrectly set F_EOF flag on EAGAIN errors
 - buffered fread did not always read full blocks from files
 - non-blocking fwrite was unsupported
 - unbuffered fwrite did not set F_ERROR flag on write errors
 - buffered fwrite did not set F_ERROR flag on read buffer flushing errors
 - buffered fwrite did not return 0 on read buffer flushing errors
 - buffered fwrite did not always write full blocks to files

JIRA: RTOS-892
  • Loading branch information
ziemleszcz committed Oct 14, 2024
1 parent 42ccd86 commit 408aeb3
Show file tree
Hide file tree
Showing 2 changed files with 365 additions and 182 deletions.
6 changes: 0 additions & 6 deletions include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ extern int fgetpos(FILE *stream, fpos_t *pos);

/* Opens the filename pointed to by filename using the given mode. */
extern FILE *fopen(const char *filename, const char *mode);
extern FILE *fopen_unlocked(const char *filename, const char *mode);


/* Associates a stream with existing file descriptor fd. */
Expand All @@ -146,9 +145,7 @@ extern int fileno_unlocked(FILE *stream);
* to seek from the given whence position.
*/
extern int fseek(FILE *stream, long int offset, int whence);
extern int fseek_unlocked(FILE *stream, long int offset, int whence);
extern int fseeko(FILE *stream, off_t offset, int whence);
extern int fseeko_unlocked(FILE *stream, off_t offset, int whence);


/*
Expand All @@ -160,9 +157,7 @@ extern int fsetpos(FILE *stream, const fpos_t *pos);

/* Returns the current file position of the given stream. */
extern long int ftell(FILE *stream);
extern long int ftell_unlocked(FILE *stream);
extern off_t ftello(FILE *stream);
extern off_t ftello_unlocked(FILE *stream);


/* Writes data from the array pointed to by ptr to the given stream. */
Expand Down Expand Up @@ -349,7 +344,6 @@ extern int puts(const char *str);

/* Pushes the character char (an unsigned char) onto the specified stream so that the next character is read. */
extern int ungetc(int c, FILE *stream);
extern int ungetc_unlocked(int c, FILE *stream);


/* Prints a descriptive error message to stderr. First the string str is printed followed by a colon and then a space. */
Expand Down
Loading

0 comments on commit 408aeb3

Please sign in to comment.