Commit Diff


commit - 5b3b0e7ede788513318d34567cfc878837a91ef2e99023a2d8eb0cde36095e4d
commit + 9a47c4d14cf416a9acdc96d46cc26daf80cfa34fdd5a63692022d2eb04df435d
blob - bf7da7c9099f12cedc4c13b3d59bddf2a7dfae1ea84ab47530200f7e367cf57e
blob + edd77fcae217b3caec4ec9ade8fd948e7baf91bda93cc597b2f78077850f234b
--- 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 *