extra uname spaces confuse scripts

This commit is contained in:
Connor Lane Smith 2011-06-09 00:40:23 +01:00
parent ff97891dad
commit 17a81ace44
1 changed files with 18 additions and 5 deletions

23
uname.c
View File

@ -6,6 +6,8 @@
#include <sys/utsname.h>
#include "util.h"
static void print(const char *);
int
main(int argc, char *argv[])
{
@ -44,15 +46,26 @@ main(int argc, char *argv[])
eprintf("uname:");
if(sflag || !(nflag || rflag || vflag || mflag))
printf("%s ", u.sysname);
print(u.sysname);
if(nflag)
printf("%s ", u.nodename);
print(u.nodename);
if(rflag)
printf("%s ", u.release);
print(u.release);
if(vflag)
printf("%s ", u.version);
print(u.version);
if(mflag)
printf("%s ", u.machine);
print(u.machine);
putchar('\n');
return EXIT_SUCCESS;
}
void
print(const char *s)
{
static bool first = true;
if(!first)
putchar(' ');
fputs(s, stdout);
first = false;
}