add uname, thanks hiltjo

This commit is contained in:
Connor Lane Smith 2011-06-02 20:32:05 +01:00
parent 16a0ee098c
commit 92baf1a5c9
5 changed files with 92 additions and 3 deletions

View File

@ -4,6 +4,7 @@ MIT/X Consortium License
© 2011 Kamil Cholewiński <harry666t@gmail.com>
© 2011 stateless <stateless@archlinux.us>
© 2011 Rob Pilling <robpilling@gmail.com>
© 2011 Hiltjo Posthuma <hiltjo@codemadness.org>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),

View File

@ -6,7 +6,7 @@ LIB = util/afgets.o util/agetcwd.o util/concat.o util/enmasse.o util/eprintf.o \
SRC = basename.c cat.c chmod.c chown.c date.c dirname.c echo.c false.c grep.c \
head.c ln.c ls.c mkdir.c mkfifo.c nl.c pwd.c rm.c sleep.c sort.c tail.c \
tee.c touch.c true.c wc.c
tee.c touch.c true.c uname.c wc.c
OBJ = $(SRC:.c=.o) $(LIB)
BIN = $(SRC:.c=)
MAN = $(SRC:.c=.1)

4
sort.1
View File

@ -11,8 +11,8 @@ writes the sorted concatenation of the given files to stdout. If no file is
given, sort reads from stdin.
.SH OPTIONS
.TP
.BI \-r
.B \-r
reverses the sort.
.TP
.BI \-u
.B \-u
prints repeated lines only once.

30
uname.1 Normal file
View File

@ -0,0 +1,30 @@
.TH UNAME 1 sbase\-VERSION
.SH NAME
uname \- print system information
.SH SYNOPSIS
.B uname
.RB [ \-amnrsv ]
.SH DESCRIPTION
.B uname
prints system information. If no flags are given, uname will print only the
name of the operating system
.RB ( -s ).
.SH OPTIONS
.TP
.B \-a
print all the information below.
.TP
.B \-m
print the machine's architecture.
.TP
.B \-n
print the system's network name.
.TP
.B \-r
print the operating system's release name.
.TP
.B \-s
print the name of the operating system.
.TP
.B \-v
print the operating system's version name.

58
uname.c Normal file
View File

@ -0,0 +1,58 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/utsname.h>
#include "util.h"
int
main(int argc, char *argv[])
{
bool mflag = false;
bool nflag = false;
bool rflag = false;
bool sflag = false;
bool vflag = false;
char c;
struct utsname u;
while((c = getopt(argc, argv, "amnrsv")) != -1)
switch(c) {
case 'a':
mflag = nflag = rflag = sflag = vflag = true;
break;
case 'm':
mflag = true;
break;
case 'n':
nflag = true;
break;
case 'r':
rflag = true;
break;
case 's':
sflag = true;
break;
case 'v':
vflag = true;
break;
default:
exit(EXIT_FAILURE);
}
if(uname(&u) == -1)
eprintf("uname failed:");
if(sflag || !(nflag || rflag || vflag || mflag))
printf("%s ", u.sysname);
if(nflag)
printf("%s ", u.nodename);
if(rflag)
printf("%s ", u.release);
if(vflag)
printf("%s ", u.version);
if(mflag)
printf("%s ", u.machine);
putchar('\n');
return EXIT_SUCCESS;
}