Commit e45f7eba7c3fe929b6bd5852f390301aeace98aa

Christian Weisgerber 2022-05-14T18:55:37

got patch: switch from fseek() to fseeko(), use unary minus while here ok op

diff --git a/lib/patch.c b/lib/patch.c
index d7d7afe..3ed493e 100644
--- a/lib/patch.c
+++ b/lib/patch.c
@@ -296,8 +296,8 @@ copy(FILE *tmp, FILE *orig, off_t copypos, off_t pos)
 	char buf[BUFSIZ];
 	size_t len, r, w;
 
-	if (fseek(orig, copypos, SEEK_SET) == -1)
-		return got_error_from_errno("fseek");
+	if (fseeko(orig, copypos, SEEK_SET) == -1)
+		return got_error_from_errno("fseeko");
 
 	while (pos == -1 || copypos < pos) {
 		len = sizeof(buf);
@@ -362,8 +362,8 @@ locate_hunk(FILE *orig, struct got_patch_hunk *h, off_t *pos, long *lineno)
 	if (err == NULL) {
 		*pos = match;
 		*lineno = match_lineno;
-		if (fseek(orig, match, SEEK_SET) == -1)
-			err = got_error_from_errno("fseek");
+		if (fseeko(orig, match, SEEK_SET) == -1)
+			err = got_error_from_errno("fseeko");
 	}
 
 	free(line);
@@ -491,8 +491,8 @@ patch_file(struct got_patch *p, const char *path, FILE *tmp, int nop,
 			 * try to apply the hunk again starting the search
 			 * after the previous partial match.
 			 */
-			if (fseek(orig, pos, SEEK_SET) == -1) {
-				err = got_error_from_errno("fseek");
+			if (fseeko(orig, pos, SEEK_SET) == -1) {
+				err = got_error_from_errno("fseeko");
 				goto done;
 			}
 			linelen = getline(&line, &linesize, orig);
diff --git a/libexec/got-read-patch/got-read-patch.c b/libexec/got-read-patch/got-read-patch.c
index 96d9789..0e9106a 100644
--- a/libexec/got-read-patch/got-read-patch.c
+++ b/libexec/got-read-patch/got-read-patch.c
@@ -181,8 +181,8 @@ find_patch(int *done, FILE *fp)
 				break;
 
 			/* rewind to previous line */
-			if (fseek(fp, linelen * -1, SEEK_CUR) == -1)
-				err = got_error_from_errno("fseek");
+			if (fseeko(fp, -linelen, SEEK_CUR) == -1)
+				err = got_error_from_errno("fseeko");
 			break;
 		}
 	}
@@ -352,8 +352,8 @@ parse_hunk(FILE *fp, int *done)
 	if (err)
 		goto done;
 	if (*done) {
-		if (fseek(fp, linelen * -1, SEEK_CUR) == -1)
-			err = got_error_from_errno("fseek");
+		if (fseeko(fp, -linelen, SEEK_CUR) == -1)
+			err = got_error_from_errno("fseeko");
 		goto done;
 	}