commit 794a213ff7f2e0fada025ef53a9b5cfeecf17b94 from: Mark Jamsek via: Thomas Adam date: Fri Jan 24 22:02:34 2025 UTC switch to fseeko() and tweak error checking in file_is_binary() provided by mark during review of previous change commit - 6861dde0464effde4b407fc83b9d01d94838645c commit + 794a213ff7f2e0fada025ef53a9b5cfeecf17b94 blob - 625f497531de7bc06ad51021e0ae869462e875da blob + 1446cf88c13ccf1495280a5f9e2ddb1321872824 --- lib/worktree.c +++ lib/worktree.c @@ -1732,14 +1732,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); @@ -1749,10 +1752,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 *