Skip to content

Commit

Permalink
don't perform buffering on raw FILE*s.
Browse files Browse the repository at this point in the history
  • Loading branch information
nyuichi committed Mar 31, 2014
1 parent 0cbb590 commit c7d08eb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions xfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,15 @@ file_close(void *cookie)
xFILE *
xfpopen(FILE *fp)
{
return xfunopen(fp, file_read, file_write, file_seek, file_close);
xFILE *file;

file = xfunopen(fp, file_read, file_write, file_seek, file_close);
if (! file) {
return NULL;
}
xsetvbuf(file, NULL, _IONBF, 0);

return file;
}

#endif
Expand Down Expand Up @@ -210,12 +218,21 @@ xFILE *
xfopen(const char *filename, const char *mode)
{
FILE *fp;
xFILE *file;

fp = fopen(filename, mode);
if (! fp) {
return NULL;
}
return xfpopen(fp);
setvbuf(fp, NULL, _IONBF, 0);

file = xfpopen(fp);
if (! file) {
return NULL;
}
xsetvbuf(file, NULL, _IOFBF, 0);

return file;
}

#elif XFILE_FOPEN_TYPE == 2
Expand Down
2 changes: 1 addition & 1 deletion xfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int xffill(xFILE *);
xFILE *xfopen(const char *, const char *);
#endif
#if XFILE_ENABLE_CSTDIO
xFILE *xfpopen(FILE *);
xFILE *xfpopen(FILE *); /* disables xfile's buffer management */
#endif
#if XFILE_ENABLE_POSIX
xFILE *xfdopen(int);
Expand Down

0 comments on commit c7d08eb

Please sign in to comment.