fsck_minix: stop using data/bss
[oweals/busybox.git] / util-linux / losetup.c
index 6b9a810f283bc338b1f70178db36c9a34b41ca6d..e2d4e4d79162571f910ed09cd31ad41979eec091 100644 (file)
@@ -8,17 +8,17 @@
  */
 
 #include <getopt.h>
-#include <stdlib.h>
 
-#include "busybox.h"
+#include "libbb.h"
 
+int losetup_main(int argc, char **argv);
 int losetup_main(int argc, char **argv)
 {
-       unsigned long opt;
+       unsigned opt;
        char *opt_o;
-       int offset = 0;
+       unsigned long long offset = 0;
 
-       opt = bb_getopt_ulflags(argc, argv, "do:", &opt_o);
+       opt = getopt32(argc, argv, "do:", &opt_o);
        argc -= optind;
        argv += optind;
 
@@ -35,7 +35,7 @@ int losetup_main(int argc, char **argv)
        }
 
        if (opt == 0x2) // -o
-               offset = bb_xparse_number(opt_o, NULL);
+               offset = xatoull(opt_o);
 
        /* -o or no option */
 
@@ -44,19 +44,22 @@ int losetup_main(int argc, char **argv)
                        bb_perror_nomsg_and_die();
        } else if (argc == 1) {
                char *s = query_loop(argv[0]);
-               if (!s) bb_perror_nomsg_and_die();
+               if (!s)
+                       bb_perror_nomsg_and_die();
                printf("%s: %s\n", argv[0], s);
-               if (ENABLE_FEATURE_CLEAN_UP) free(s);
+               if (ENABLE_FEATURE_CLEAN_UP)
+                       free(s);
        } else {
-               char dev[11] = "/dev/loop0";
+               char dev[sizeof(LOOP_NAME"0")] = LOOP_NAME"0";
                char c;
                for (c = '0'; c <= '9'; ++c) {
                        char *s;
-                       dev[9] = c;
+                       dev[sizeof(LOOP_NAME"0")-2] = c;
                        s = query_loop(dev);
                        if (s) {
                                printf("%s: %s\n", dev, s);
-                               if (ENABLE_FEATURE_CLEAN_UP) free(s);
+                               if (ENABLE_FEATURE_CLEAN_UP)
+                                       free(s);
                        }
                }
        }