From eb0086669fbc4d924772918b861a839dc3c1a5a9 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 29 Jul 2025 13:23:58 -0700 Subject: [PATCH] =?utf8?q?tail:=20xlseek=20switch=20=E2=86=92=20table?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * src/tail.c (xlseek): Turn a switch statement into a table. --- src/tail.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/tail.c b/src/tail.c index a03d971a06..46dee32834 100644 --- a/src/tail.c +++ b/src/tail.c @@ -481,24 +481,14 @@ xlseek (int fd, off_t offset, int whence, char const *prettyname) if (0 <= new_offset) return new_offset; - switch (whence) - { - case SEEK_SET: - error (EXIT_FAILURE, errno, _("%s: cannot seek to offset %jd"), - quotef (prettyname), (intmax_t) offset); - break; - case SEEK_CUR: - error (EXIT_FAILURE, errno, _("%s: cannot seek to relative offset %jd"), - quotef (prettyname), (intmax_t) offset); - break; - case SEEK_END: - error (EXIT_FAILURE, errno, - _("%s: cannot seek to end-relative offset %jd"), - quotef (prettyname), (intmax_t) offset); - break; - default: - unreachable (); - } + static char const *whence_msgid[] = { + [SEEK_SET] = N_("%s: cannot seek to offset %jd"), + [SEEK_CUR] = N_("%s: cannot seek to relative offset %jd"), + [SEEK_END] = N_("%s: cannot seek to end-relative offset %jd") + }; + intmax_t joffset = offset; + error (EXIT_FAILURE, errno, gettext (whence_msgid[whence]), + quotef (prettyname), joffset); } /* Print the last N_LINES lines from the end of file FD. -- 2.47.2