commit 85db99906136b77c3a31a58c53ffc746b1568353 from: Mark Jamsek via: Stefan Sperling date: Tue Jan 21 08:00:00 2025 UTC switch to fseeko() and tweak error checking in file_is_binary() provided by mark during review of previous change commit - c1142a3476cd388c1eddb581390528dc92d36bdd commit + 85db99906136b77c3a31a58c53ffc746b1568353 blob - 0d5a5b54769d0ac8294a460110d7bfbac89c9b55 blob + 347dee89931812371ac672ad6fde03759da76d4f --- lib/worktree.c +++ lib/worktree.c @@ -1735,14 +1735,17 @@ get_symlink_modification_status(unsigned char *status, 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); @@ -1752,10 +1755,10 @@ file_is_binary(int *is_binary , FILE *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 *