Fixed segfault with 'cut -f 1 -d:' and added 'cut -s' suport.
[oweals/busybox.git] / mkfs_minix.c
index f4f1d0997f5a2fdcfab44b0e3a23ed01f5cda117..670d03a3a92072004636d8d60bc7b72595eea543 100644 (file)
@@ -74,6 +74,7 @@
 #include <termios.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
+#include <sys/param.h>
 #include <mntent.h>
 
 #include <linux/fs.h>
 #define HAVE_MINIX2 1
 #endif
 
-#ifndef __GNUC__
-#error "needs gcc for the bitop-__asm__'s"
-#endif
-
 #ifndef __linux__
 #define volatile
 #endif
@@ -191,7 +188,7 @@ static volatile void show_usage()
        fprintf(stderr,
                        "\t-n [14|30]\tSpecify the maximum length of filenames\n");
        fprintf(stderr,
-                       "\t-i\t\tSpecify the number of inodes for the filesystem\n");
+                       "\t-i INODES\tSpecify the number of inodes for the filesystem\n");
        fprintf(stderr,
                        "\t-l FILENAME\tRead the bad blocks list from FILENAME\n");
        fprintf(stderr, "\t-v\t\tMake a Minix version 2 filesystem\n\n");
@@ -647,7 +644,7 @@ char *filename;
 
 extern int mkfs_minix_main(int argc, char **argv)
 {
-       int i;
+       int i=1;
        char *tmp;
        struct stat statbuf;
        char *listfile = NULL;
@@ -663,23 +660,32 @@ extern int mkfs_minix_main(int argc, char **argv)
 #endif
        
        /* Parse options */
-       //printf("argc='%d'  argv='%s'\n", argc, *argv);
        argv++;
        while (--argc >= 0 && *argv && **argv) {
                if (**argv == '-') {
                        stopIt=FALSE;
                        while (i > 0 && *++(*argv) && stopIt==FALSE) {
-                               //printf("argc='%d'  argv='%s'\n", argc, *argv);
                                switch (**argv) {
                                        case 'c':
                                                check = 1;
                                                break;
                                        case 'i':
-                                               if (--argc == 0) {
-                                                       goto goodbye;
+                                               {
+                                                       char *cp=NULL;
+                                                       if (*(*argv+1) != 0) {
+                                                               cp = ++(*argv);
+                                                       } else {
+                                                               if (--argc == 0) {
+                                                                       goto goodbye;
+                                                               }
+                                                               cp = *(++argv);
+                                                       }
+                                                       req_nr_inodes = strtoul(cp, &tmp, 0);
+                                                       if (*tmp)
+                                                               show_usage();
+                                                       stopIt=TRUE;
+                                                       break;
                                                }
-                                               req_nr_inodes = (unsigned long) atol(*(++argv));
-                                               break;
                                        case 'l':
                                                if (--argc == 0) {
                                                        goto goodbye;
@@ -690,16 +696,15 @@ extern int mkfs_minix_main(int argc, char **argv)
                                                {
                                                        char *cp=NULL;
 
-                                                       if (--argc == 0) {
-                                                               goto goodbye;
-                                                       }
                                                        if (*(*argv+1) != 0) {
                                                                cp = ++(*argv);
                                                        } else {
+                                                               if (--argc == 0) {
+                                                                       goto goodbye;
+                                                               }
                                                                cp = *(++argv);
                                                        }
                                                        i = strtoul(cp, &tmp, 0);
-                                                       //printf("cp='%s'   i='%d'\n", cp, i);
                                                        if (*tmp)
                                                                show_usage();
                                                        if (i == 14)
@@ -730,7 +735,6 @@ goodbye:
                                }
                        }
                } else {
-                       //printf("else:  argc='%d'  argv='%s'\n", argc, *argv);
                        if (device_name == NULL)
                                device_name = *argv;
                        else if (BLOCKS == 0)
@@ -793,6 +797,6 @@ goodbye:
        }
        mark_good_blocks();
        write_tables();
-       exit( 0);
+       return( 0);
 
 }