[hackers] [ubase] mount: cat /proc/mounts if no arguments given || Hiltjo Posthuma
commit 5f4d18d4fa61448668560086e7f7ef02528bf92b
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Fri Apr 4 19:41:37 2014 +0200
mount: cat /proc/mounts if no arguments given
Signed-off-by: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
diff --git a/mount.c b/mount.c
index d099586..a43444b 100644
--- a/mount.c
+++ b/mount.c
_AT_@ -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[])
{
_AT_@ -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;
Received on Fri Apr 04 2014 - 21:09:41 CEST
This archive was generated by hypermail 2.3.0
: Fri Apr 04 2014 - 21:12:31 CEST