From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 32177 invoked from network); 11 Apr 2021 20:01:19 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 11 Apr 2021 20:01:19 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date:Content-ID: Content-Type:MIME-Version:Subject:To:From:Reply-To:Cc: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=lwOh7KSemlRGv2cFGomc60HjJFTXl1MCEUKHRnfMA7s=; b=ziFcTXVUU6gLHDyL7wsN8vDCVl xearC1X99+SyYGHFCdFKumA595Fv/tV8VQktN5ZSfLzvA7xwHJUnffykmIueK2ojL2+yg5sB3azbA Wxojk7IKG5IouzNqJcc9gUBEeUe6v4ynUgHeZP4ZTd0g9mwwSm4ijrCZBuQYKtP9VDIjBC/y7N8AF 9nlTkdoTLxRzZNj3Sqqshk0CUbuopUuDJdpX8GPRYgUuYu184RpvJpvVP0WaU3wTl/HRbxgk9zBZY EEQ2YbDQJu6BkISNfUfiHzEUs6kbEkdBzUXsEqiPW53FKe+CKNTwA4SQLG6sHouRWvri7sDCHR0Sb 1d3bCZ7g==; Received: from authenticated user by zero.zsh.org with local id 1lVgGf-0004xh-DE; Sun, 11 Apr 2021 20:01:13 +0000 Received: from authenticated user by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1lVgFx-0004gv-LA; Sun, 11 Apr 2021 20:00:29 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.93.0.4) (envelope-from ) id 1lVgFw-000Ct9-Be for zsh-workers@zsh.org; Sun, 11 Apr 2021 22:00:28 +0200 From: Oliver Kiddle To: Zsh workers Subject: PATCH: use SEEK_ macros in fseek() calls MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <49545.1618171228.1@hydra> Date: Sun, 11 Apr 2021 22:00:28 +0200 Message-ID: <49546-1618171228.358138@8CQF.W6Uc.F2Ms> X-Seq: 48504 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: When looking at the fseek in history contributions, I noticed that in calls to fseek(), we have 0, 1 and 2 hard-coded for the whence parameter in many but not all cases. Perhaps the SEEK_ macros couldn't be relied upon in the distant past but we also do use them in some cases. I think they make the code slightly more readable so this patch adds them in. Oliver diff --git a/Src/hist.c b/Src/hist.c index 2e5ac97d9..42cae030c 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -2664,7 +2664,7 @@ readhistfile(char *fn, int err, int readflags) pushheap(); if (readflags & HFILE_FAST && lasthist.text) { if (lasthist.fpos < lasthist.fsiz) { - fseek(in, lasthist.fpos, 0); + fseek(in, lasthist.fpos, SEEK_SET); searching = 1; } else { @@ -2741,7 +2741,7 @@ readhistfile(char *fn, int err, int readflags) && histstrcmp(pt, lasthist.text) == 0) searching = 0; else { - fseek(in, 0, 0); + fseek(in, 0, SEEK_SET); histfile_linect = 0; searching = -1; } diff --git a/Src/input.c b/Src/input.c index e9989ffe4..f568cc135 100644 --- a/Src/input.c +++ b/Src/input.c @@ -495,9 +495,9 @@ stuff(char *fn) zerr("can't open %s", fn); return 1; } - fseek(in, 0, 2); + fseek(in, 0, SEEK_END); len = ftell(in); - fseek(in, 0, 0); + fseek(in, 0, SEEK_SET); buf = (char *)zalloc(len + 1); if (!(fread(buf, len, 1, in))) { zerr("read error on %s", fn); diff --git a/Src/watch.c b/Src/watch.c index 93b3cb134..c41704315 100644 --- a/Src/watch.c +++ b/Src/watch.c @@ -169,9 +169,9 @@ getlogtime(WATCH_STRUCT_UTMP *u, int inout) return u->ut_time; if (!(in = fopen(WATCH_WTMP_FILE, "r"))) return time(NULL); - fseek(in, 0, 2); + fseek(in, 0, SEEK_END); do { - if (fseek(in, ((first) ? -1 : -2) * sizeof(WATCH_STRUCT_UTMP), 1)) { + if (fseek(in, ((first) ? -1 : -2) * sizeof(WATCH_STRUCT_UTMP), SEEK_CUR)) { fclose(in); return time(NULL); }