commit 5f4d18d4fa61448668560086e7f7ef02528bf92b
Author: Hiltjo Posthuma <[email protected]>
Date:   Fri Apr 4 19:41:37 2014 +0200

    mount: cat /proc/mounts if no arguments given
    
    Signed-off-by: Hiltjo Posthuma <[email protected]>

diff --git a/mount.c b/mount.c
index d099586..a43444b 100644
--- 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;


Reply via email to