ubase

suckless linux base utils
git clone git://git.2f30.org/ubase
Log | Files | Refs | README | LICENSE

commit 5f4d18d4fa61448668560086e7f7ef02528bf92b
parent e71d009bd1116a5b962489f6a2d617f6e6cc423f
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Fri,  4 Apr 2014 19:41:37 +0200

mount: cat /proc/mounts if no arguments given

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>

Diffstat:
Mmount.c | 29+++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/mount.c b/mount.c @@ -101,6 +101,23 @@ usage(void) argv0); } +static int +catfile(FILE *in, FILE *out) +{ + char buf[BUFSIZ]; + size_t bytesread; + + while(1) { + if(feof(in)) + break; + bytesread = fread(buf, 1, sizeof(buf), in); + if(ferror(in)) + return 0; + fwrite(buf, 1, bytesread, out); + } + return 1; +} + int main(int argc, char *argv[]) { @@ -140,8 +157,16 @@ main(int argc, char *argv[]) usage(); } ARGEND; - if(argc < 1 && aflag == 0) - usage(); + if(argc < 1 && aflag == 0) { + if(!(fp = fopen(files[0], "r"))) + eprintf("fopen %s:", files[0]); + if(catfile(fp, stdout) != 1) { + weprintf("error while reading %s:", files[0]); + status = EXIT_FAILURE; + } + fclose(fp); + return status; + } if(aflag == 1) goto mountall;