richardphibel / rpms / rpm

Forked from rpms/rpm 2 years ago
Clone
Blob Blame History Raw
From 7ae16d6bd37abdcc0430fbb1b25a0f821a60c234 Mon Sep 17 00:00:00 2001
From: Matthew Almond <malmond@fb.com>
Date: Mon, 28 Sep 2020 12:41:22 -0700
Subject: [PATCH] Make fdSeek return 0 on success, -1 on error

This code eliminates a false positive failure when the destination position is > 2GiB. This is done by changing the contract for `Fseek`. Now it returns `0` on success instead of an `int` offset. Care should be used to interpret the result as there is a difference in semantics between the POSIX `fseek(2)`. Existing code is correct: negative results are still failures.
---
 rpmio/rpmio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c
index 10a28a923..9f4a60aa1 100644
--- a/rpmio/rpmio.c
+++ b/rpmio/rpmio.c
@@ -382,7 +382,7 @@ static ssize_t fdWrite(FDSTACK_t fps, const void * buf, size_t count)
 
 static int fdSeek(FDSTACK_t fps, off_t pos, int whence)
 {
-    return lseek(fps->fdno, pos, whence);
+    return (lseek(fps->fdno, pos, whence) == -1) ? -1 : 0;
 }
 
 static int fdClose(FDSTACK_t fps)