From 8158ef186bf16307b6ed2c329cf008064c6ba868 Mon Sep 17 00:00:00 2001 From: Kiyoshi Aman Date: Sun, 21 Jul 2019 06:48:19 -0500 Subject: bin/uname: fix nonstandard behaviour --- bin/uname/uname.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/bin/uname/uname.c b/bin/uname/uname.c index f648f92..3efd037 100644 --- a/bin/uname/uname.c +++ b/bin/uname/uname.c @@ -45,6 +45,7 @@ int main(int argc, char **argv) { bool mflag, nflag, oflag, rflag, sflag, vflag; mflag = nflag = oflag = rflag = sflag = vflag = false; char ch; + bool space = false; while ((ch = getopt(argc, argv, "amnorsv")) != -1) { switch (ch) { @@ -84,22 +85,27 @@ int main(int argc, char **argv) { } if (sflag) { - printf("%s ", sysinfo.sysname); + printf("%s", sysinfo.sysname); + space = true; } if (nflag) { - printf("%s ", sysinfo.nodename); + printf("%s%s", (space ? " " : ""), sysinfo.nodename); + space = true; } if (rflag) { - printf("%s ", sysinfo.release); + printf("%s%s", (space ? " " : ""), sysinfo.release); + space = true; } if (vflag) { - printf("%s ", sysinfo.version); + printf("%s%s", (space ? " " : ""), sysinfo.version); + space = true; } if (mflag) { - printf("%s ", sysinfo.machine); + printf("%s%s", (space ? " " : ""), sysinfo.machine); + space = true; } if (oflag) { - printf("%s ", sysinfo.sysname); + printf("%s%s", (space ? " " : ""), sysinfo.sysname); } printf("\n"); -- cgit v1.2.3-70-g09d2