1From 29df8734fdc342f5ffb626f1636e1e0b4f72c1ed Mon Sep 17 00:00:00 20012From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net>3Date: Thu, 13 Nov 2025 08:36:29 +01004Subject: [PATCH] Don't print the full ksh binary name in error messages56This results in much nicer to read error messages on Guix where7argv[0] will be a lengthy GNU store path with which we don't want8to prefix every error message.910Note that for login shell's (e.g., as created by login(8) or sshd), the11argv[0] will be `-ksh` and the error message will be readable. However,12for non-login shell's (e.g., as created by terminal emulators) argv[0]13will be the full binary path.1415---16 io.c | 23 +++++++++++++++++++++--17 1 file changed, 21 insertions(+), 2 deletions(-)1819diff --git a/io.c b/io.c20index 1ea1978..d9d9b3d 10064421--- a/io.c22+++ b/io.c23@@ -17,6 +17,22 @@2425 static int initio_done;2627+/*28+ * GNU's version of basename(3) from string.h which does *not* modify it's29+ * input but returns an empty string when path has a trailing '/' or is '/'.30+ */31+static const char*32+basename_const(const char *path)33+{34+ char *sep;35+36+ if ((sep = (strrchr(path, '/')))) {37+ return sep+1;38+ } else {39+ return path;40+ }41+}42+43 /*44 * formatted output functions45 */46@@ -126,8 +142,11 @@ error_prefix(int fileline)47 {48 /* Avoid foo: foo[2]: ... */49 if (!fileline || !source || !source->file ||50- strcmp(source->file, kshname) != 0)51- shf_fprintf(shl_out, "%s: ", kshname + (*kshname == '-'));52+ strcmp(source->file, kshname) != 0) {53+ const char *kshbasename = basename_const(kshname);54+ shf_fprintf(shl_out, "%s: ", kshbasename + (*kshbasename == '-'));55+ }56+57 if (fileline && source && source->file != NULL) {58 shf_fprintf(shl_out, "%s[%d]: ", source->file,59 source->errline > 0 ? source->errline : source->line);