sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 92baf1a5c9179ecadfb069aebf124cbb07363ad2
parent 16a0ee098c95c8b710fde00c5632cd82117992f1
Author: Connor Lane Smith <cls@lubutu.com>
Date:   Thu,  2 Jun 2011 20:32:05 +0100

add uname, thanks hiltjo
Diffstat:
MLICENSE | 1+
MMakefile | 2+-
Msort.1 | 4++--
Auname.1 | 30++++++++++++++++++++++++++++++
Auname.c | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 92 insertions(+), 3 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -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"), diff --git 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 @@ -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 @@ -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 @@ -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; +}