From: Oliver Kiddle <opk@zsh.org>
To: Zsh workers <zsh-workers@zsh.org>
Subject: PATCH: use SEEK_ macros in fseek() calls
Date: Sun, 11 Apr 2021 22:00:28 +0200 [thread overview]
Message-ID: <49546-1618171228.358138@8CQF.W6Uc.F2Ms> (raw)
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);
}
reply other threads:[~2021-04-11 20:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49546-1618171228.358138@8CQF.W6Uc.F2Ms \
--to=opk@zsh.org \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).