From 92baf1a5c9179ecadfb069aebf124cbb07363ad2 Mon Sep 17 00:00:00 2001 From: Connor Lane Smith Date: Thu, 2 Jun 2011 20:32:05 +0100 Subject: [PATCH] add uname, thanks hiltjo --- LICENSE | 1 + Makefile | 2 +- sort.1 | 4 ++-- uname.1 | 30 +++++++++++++++++++++++++++++ uname.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 uname.1 create mode 100644 uname.c diff --git a/LICENSE b/LICENSE index c55af1a..803da60 100644 --- a/LICENSE +++ b/LICENSE @@ -4,6 +4,7 @@ MIT/X Consortium License © 2011 Kamil Cholewiński © 2011 stateless © 2011 Rob Pilling +© 2011 Hiltjo Posthuma Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), diff --git a/Makefile b/Makefile index 05a90d1..eb2e58c 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/sort.1 b/sort.1 index 1f375e9..6cbe030 100644 --- a/sort.1 +++ b/sort.1 @@ -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. diff --git a/uname.1 b/uname.1 new file mode 100644 index 0000000..6e59b58 --- /dev/null +++ b/uname.1 @@ -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. diff --git a/uname.c b/uname.c new file mode 100644 index 0000000..549669b --- /dev/null +++ b/uname.c @@ -0,0 +1,58 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include +#include +#include +#include +#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; +}