Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions chapter_8/exercise_8_03/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ FILE *file_open(char *name, char *mode)

int file_close(FILE *file_p)
{
if (file_flush(file_p) == EOF)
if (file_p->flag._WRITE == 1 && file_flush(file_p) == EOF)
{
return EOF;
}
Expand All @@ -179,7 +179,7 @@ int file_close(FILE *file_p)
file_p->counter = 0;
close(file_p->file_descriptor);

return NULL;
return 0;
}

int main(void)
Expand All @@ -204,6 +204,7 @@ int main(void)
{
putc(c, file_out_p);
}
file_close(file_in_p);
file_close(file_out_p);

return EXIT_SUCCESS;
Expand Down
5 changes: 3 additions & 2 deletions chapter_8/exercise_8_04/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ FILE *file_open(char *name, char *mode)

int file_close(FILE *file_p)
{
if (file_flush(file_p) == EOF)
if (file_p->flag._WRITE == 1 && file_flush(file_p) == EOF)
{
return EOF;
}
Expand All @@ -179,7 +179,7 @@ int file_close(FILE *file_p)
file_p->counter = 0;
close(file_p->file_descriptor);

return NULL;
return 0;
}

int file_seek(FILE *file_p, long offset, int whence)
Expand Down Expand Up @@ -227,6 +227,7 @@ int main(void)
{
putc(c, file_out_p);
}
file_close(file_in_p);
file_close(file_out_p);

return EXIT_SUCCESS;
Expand Down