Skip to content

Commit

Permalink
fix: refactor function to fix GCC warning
Browse files Browse the repository at this point in the history
  • Loading branch information
cyuria committed Jun 5, 2024
1 parent 415bf2b commit 9ead6d2
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,15 @@ void open_files(void)
void copy_files(FILE *dest, FILE *src)
{
const long pos = ftell(src);
fseek(src, 0L, SEEK_END);
size_t sz = (size_t)ftell(outputtempfile);
rewind(outputtempfile);

char *buffer = xmalloc(BUFSIZ);
while (sz > BUFSIZ) {
fread(buffer, 1, BUFSIZ, src);
fwrite(buffer, 1, BUFSIZ, dest);
sz -= BUFSIZ;
for (;;) {
const size_t bytes = fread(buffer, 1, BUFSIZ, src);
fwrite(buffer, 1, bytes, dest);
if (bytes != BUFSIZ)
break;
}
buffer = xrealloc(buffer, sz);
fread(buffer, 1, sz, src);
fwrite(buffer, 1, sz, dest);
free(buffer);

fseek(src, pos, SEEK_SET);
Expand Down

0 comments on commit 9ead6d2

Please sign in to comment.