commit - c1142a3476cd388c1eddb581390528dc92d36bdd
commit + 85db99906136b77c3a31a58c53ffc746b1568353
blob - 0d5a5b54769d0ac8294a460110d7bfbac89c9b55
blob + 347dee89931812371ac672ad6fde03759da76d4f
--- lib/worktree.c
+++ lib/worktree.c
static const struct got_error *
file_is_binary(int *is_binary , FILE *f)
{
- const struct got_error *err = NULL;
char buf[8192];
size_t r;
- off_t pos = ftello(f);
+ off_t pos;
*is_binary = 0;
- if (fseek(f, 0L, SEEK_SET) == -1)
+ pos = ftello(f);
+ if (pos == -1)
+ return got_error_from_errno("ftello");
+
+ if (fseeko(f, 0L, SEEK_SET) == -1)
return got_ferror(f, GOT_ERR_IO);
r = fread(buf, 1, sizeof(buf), f);
if (r > 0)
*is_binary = memchr(buf, '\0', r) != NULL;
- if (fseek(f, pos, SEEK_SET) == -1 && err == NULL)
- err = got_ferror(f, GOT_ERR_IO);
+ if (fseeko(f, pos, SEEK_SET) == -1)
+ return got_ferror(f, GOT_ERR_IO);
- return err;
+ return NULL;
}
static const struct got_error *