Check fwrite return value

This commit is contained in:
Rodrigo Arias 2023-03-21 10:52:24 +01:00 committed by Rodrigo Arias Mallo
parent 9304e84262
commit 2e91d29ae9

View File

@ -34,14 +34,20 @@ copy_file(const char *src, const char *dst)
return -1; return -1;
} }
int ret = 0;
size_t bytes; size_t bytes;
while ((bytes = fread(buffer, 1, sizeof(buffer), infile)) > 0) while ((bytes = fread(buffer, 1, sizeof(buffer), infile)) > 0) {
fwrite(buffer, 1, bytes, outfile); if (fwrite(buffer, 1, bytes, outfile) != bytes) {
err("fwrite failed");
ret = -1;
break;
}
}
fclose(outfile); fclose(outfile);
fclose(infile); fclose(infile);
return 0; return ret;
} }
static int static int