Skip to content

Commit

Permalink
fix(file): properly check file system errors if any
Browse files Browse the repository at this point in the history
  • Loading branch information
jtheoof committed Dec 30, 2019
1 parent 319a610 commit 541ec21
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ char *file_dump_stdin_into_a_temp_file() {
}

// Reopen stdin as binary mode
g_freopen(NULL, "rb", stdin);
FILE *input_file = g_freopen(NULL, "rb", stdin);

if (!input_file) {
g_warning("unable to reopen stdin in binary mode: %s", g_strerror(errno));
return NULL;
}

const gchar *tempdir = g_get_tmp_dir();
gchar filename[] = "swappy-stdin-XXXXXX.png";
Expand All @@ -46,7 +51,10 @@ char *file_dump_stdin_into_a_temp_file() {
size_t count = 1;
while (count > 0) {
count = fread(buf, 1, sizeof(buf), stdin);
write(fd, &buf, count);
if (write(fd, &buf, count) == -1) {
g_warning("error while writing stdin to temporary file: %s - %s", ret,
g_strerror(errno));
}
}

g_close(fd, &error);
Expand Down

0 comments on commit 541ec21

Please sign in to comment.