]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tail: xlseek switch → table
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 29 Jul 2025 20:23:58 +0000 (13:23 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 4 Aug 2025 02:48:05 +0000 (19:48 -0700)
* src/tail.c (xlseek): Turn a switch statement into a table.

src/tail.c

index a03d971a060054e7f3b24b53f4e27561756ff5dc..46dee32834f8aba80f30ff41838187f579e3b9f5 100644 (file)
@@ -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.