ifupdown: save some 100+ bytes of code in addstr()
[oweals/busybox.git] / util-linux / fdisk.c
index ab89467445e58510569f0f9d60a125e8b1c1b4e9..bd2f1e87f2fc7bd336a5459e25c45e7a15f87086 100644 (file)
@@ -131,25 +131,37 @@ enum label_type {
        label_dos, label_sun, label_sgi, label_aix, label_osf
 };
 #define LABEL_IS_DOS   (label_dos == current_label_type)
+
 #ifdef CONFIG_FEATURE_SUN_LABEL
 #define LABEL_IS_SUN   (label_sun == current_label_type)
+#define STATIC_SUN static
 #else
 #define LABEL_IS_SUN   0
+#define STATIC_SUN extern
 #endif
+
 #ifdef CONFIG_FEATURE_SGI_LABEL
 #define LABEL_IS_SGI   (label_sgi == current_label_type)
+#define STATIC_SGI static
 #else
 #define LABEL_IS_SGI   0
+#define STATIC_SGI extern
 #endif
+
 #ifdef CONFIG_FEATURE_AIX_LABEL
 #define LABEL_IS_AIX   (label_aix == current_label_type)
+#define STATIC_AIX static
 #else
 #define LABEL_IS_AIX   0
+#define STATIC_AIX extern
 #endif
+
 #ifdef CONFIG_FEATURE_OSF_LABEL
 #define LABEL_IS_OSF   (label_osf == current_label_type)
+#define STATIC_OSF static
 #else
 #define LABEL_IS_OSF   0
+#define STATIC_OSF extern
 #endif
 
 enum action { fdisk, require, try_only, create_empty_dos, create_empty_sun };
@@ -275,7 +287,7 @@ read_line(void)
        line_ptr = line_buffer;
        if (!fgets(line_buffer, LINE_LENGTH, stdin)) {
                /* error or eof */
-               bb_error_msg_and_die("\ngot EOF - exiting...");
+               bb_error_msg_and_die("\ngot EOF, exiting");
        }
        while (*line_ptr && !isgraph(*line_ptr))
                line_ptr++;
@@ -317,21 +329,6 @@ read_hex(const struct systypes *sys)
 }
 #endif /* CONFIG_FEATURE_FDISK_WRITABLE */
 
-static const struct systypes sgi_sys_types[];
-static unsigned int sgi_get_num_sectors(int i);
-static int sgi_get_sysid(int i);
-static void sgi_delete_partition(int i);
-static void sgi_change_sysid(int i, int sys);
-static void sgi_list_table(int xtra);
-static void sgi_set_xcyl(void);
-static int verify_sgi(int verbose);
-static void sgi_add_partition(int n, int sys);
-static void sgi_set_swappartition(int i);
-static const char *sgi_get_bootfile(void);
-static void sgi_set_bootfile(const char* aFile);
-static void create_sgiinfo(void);
-static void sgi_write_table(void);
-static void sgi_set_bootpartition(int i);
 #include "fdisk_aix.c"
 
 typedef struct {
@@ -364,8 +361,8 @@ typedef struct {
 #define sunlabel ((sun_partition *)MBRbuffer)
 #define SUNOS_SWAP 3
 #define SUN_WHOLE_DISK 5
-static void bselect(void);
-static void xbsd_print_disklabel(int);
+STATIC_OSF void bsd_select(void);
+STATIC_OSF void xbsd_print_disklabel(int);
 #include "fdisk_osf.c"
 
 #define SGI_VOLHDR      0x00
@@ -398,23 +395,39 @@ __swap32(uint32_t x)
 }
 #endif
 
+STATIC_SGI const struct systypes sgi_sys_types[];
+STATIC_SGI unsigned int sgi_get_num_sectors(int i);
+STATIC_SGI int sgi_get_sysid(int i);
+STATIC_SGI void sgi_delete_partition(int i);
+STATIC_SGI void sgi_change_sysid(int i, int sys);
+STATIC_SGI void sgi_list_table(int xtra);
+STATIC_SGI void sgi_set_xcyl(void);
+STATIC_SGI int verify_sgi(int verbose);
+STATIC_SGI void sgi_add_partition(int n, int sys);
+STATIC_SGI void sgi_set_swappartition(int i);
+STATIC_SGI const char *sgi_get_bootfile(void);
+STATIC_SGI void sgi_set_bootfile(const char* aFile);
+STATIC_SGI void create_sgiinfo(void);
+STATIC_SGI void sgi_write_table(void);
+STATIC_SGI void sgi_set_bootpartition(int i);
+
 #include "fdisk_sgi.c"
 
-static const struct systypes sun_sys_types[];
-static void sun_delete_partition(int i);
-static void sun_change_sysid(int i, int sys);
-static void sun_list_table(int xtra);
-static void sun_set_xcyl(void);
-static void add_sun_partition(int n, int sys);
-static void sun_set_alt_cyl(void);
-static void sun_set_ncyl(int cyl);
-static void sun_set_xcyl(void);
-static void sun_set_ilfact(void);
-static void sun_set_rspeed(void);
-static void sun_set_pcylcount(void);
-static void toggle_sunflags(int i, unsigned char mask);
-static void verify_sun(void);
-static void sun_write_table(void);
+STATIC_SUN const struct systypes sun_sys_types[];
+STATIC_SUN void sun_delete_partition(int i);
+STATIC_SUN void sun_change_sysid(int i, int sys);
+STATIC_SUN void sun_list_table(int xtra);
+STATIC_SUN void sun_set_xcyl(void);
+STATIC_SUN void add_sun_partition(int n, int sys);
+STATIC_SUN void sun_set_alt_cyl(void);
+STATIC_SUN void sun_set_ncyl(int cyl);
+STATIC_SUN void sun_set_xcyl(void);
+STATIC_SUN void sun_set_ilfact(void);
+STATIC_SUN void sun_set_rspeed(void);
+STATIC_SUN void sun_set_pcylcount(void);
+STATIC_SUN void toggle_sunflags(int i, unsigned char mask);
+STATIC_SUN void verify_sun(void);
+STATIC_SUN void sun_write_table(void);
 #include "fdisk_sun.c"
 
 /* DOS partition types */
@@ -428,7 +441,7 @@ static const struct systypes i386_sys_types[] = {
        { "\x07" "HPFS/NTFS" },        /* OS/2 IFS, eg, HPFS or NTFS or QNX */
        { "\x0a" "OS/2 Boot Manager" },/* OS/2 Boot Manager */
        { "\x0b" "Win95 FAT32" },
-       { "\x0c" "Win95 FAT32 (LBA)" },/* LBA really is `Extended Int 13h' */
+       { "\x0c" "Win95 FAT32 (LBA)" },/* LBA really is 'Extended Int 13h' */
        { "\x0e" "Win95 FAT16 (LBA)" },
        { "\x0f" "Win95 Ext'd (LBA)" },
        { "\x11" "Hidden FAT12" },
@@ -523,7 +536,6 @@ static const struct systypes i386_sys_types[] = {
 };
 
 
-
 /* A valid partition table sector ends in 0x55 0xaa */
 static unsigned int
 part_table_flag(const char *b)
@@ -1041,7 +1053,7 @@ read_extended(int ext)
                if (partitions >= MAXIMUM_PARTS) {
                        /* This is not a Linux restriction, but
                           this program uses arrays of size MAXIMUM_PARTS.
-                          Do not try to `improve' this test. */
+                          Do not try to 'improve' this test. */
                        struct pte *pre = &ptes[partitions-1];
 #ifdef CONFIG_FEATURE_FDISK_WRITABLE
                        printf(_("Warning: deleting partitions after %d\n"),
@@ -1359,7 +1371,7 @@ get_boot(enum action what)
 #endif
                        break;
                default:
-                       bb_error_msg_and_die(_("Internal error"));
+                       bb_error_msg_and_die(_("internal error"));
                }
 #endif /* CONFIG_FEATURE_FDISK_WRITABLE */
        }
@@ -1704,7 +1716,7 @@ change_sysid(void)
                        printf(_("Type 0 means free space to many systems\n"
                                   "(but not to Linux). Having partitions of\n"
                                   "type 0 is probably unwise. You can delete\n"
-                                  "a partition using the `d' command.\n"));
+                                  "a partition using the 'd' command.\n"));
                        /* break; */
                }
 
@@ -2265,7 +2277,7 @@ add_partition(int n, int sys)
                if (start > limit)
                        break;
                if (start >= temp+units_per_sector && num_read) {
-                       printf(_("Sector %llu is already allocated\n"), (unsigned long long)temp);
+                       printf(_("Sector %"OFF_FMT" is already allocated\n"), temp);
                        temp = start;
                        num_read = 0;
                }
@@ -2422,7 +2434,7 @@ new_partition(void)
                        }
                        else
                                printf(_("Invalid partition number "
-                                        "for type `%c'\n"), c);
+                                        "for type '%c'\n"), c);
                }
        }
 }
@@ -2522,13 +2534,13 @@ print_buffer(char *pbuffer)
                        printf("0x%03X:", i);
                printf(" %02X", (unsigned char) pbuffer[i]);
                if (l == MAX_PER_LINE - 1) {
-                       printf("\n");
+                       puts("");
                        l = -1;
                }
        }
        if (l > 0)
-               printf("\n");
-       printf("\n");
+               puts("");
+       puts("");
 }
 
 
@@ -2638,7 +2650,7 @@ xselect(void)
                        break;
                case 'q':
                        close(fd);
-                       printf("\n");
+                       puts("");
                        exit(0);
                case 'r':
                        return;
@@ -2759,7 +2771,7 @@ tryprocpt(void)
        char line[100], ptname[100], devname[120], *s;
        int ma, mi, sz;
 
-       procpt = bb_wfopen("/proc/partitions", "r");
+       procpt = fopen_or_warn("/proc/partitions", "r");
 
        while (fgets(line, sizeof(line), procpt)) {
                if (sscanf(line, " %d %d %d %[^\n ]",
@@ -2921,7 +2933,7 @@ int fdisk_main(int argc, char **argv)
                /* OSF label, and no DOS label */
                printf(_("Detected an OSF/1 disklabel on %s, entering "
                        "disklabel mode.\n"), disk_device);
-               bselect();
+               bsd_select();
                /*Why do we do this?  It seems to be counter-intuitive*/
                current_label_type = label_dos;
                /* If we return we may want to make an empty DOS label? */
@@ -2954,7 +2966,7 @@ int fdisk_main(int argc, char **argv)
                                        sgi_set_bootfile(line_ptr);
                        } else
 #ifdef CONFIG_FEATURE_OSF_LABEL
-                               bselect();
+                               bsd_select();
 #endif
 
 /* BUG!? Think what will happen if !CONFIG_FEATURE_OSF_LABEL !!! */
@@ -3010,7 +3022,7 @@ int fdisk_main(int argc, char **argv)
                        break;
                case 'q':
                        close(fd);
-                       printf("\n");
+                       puts("");
                        return 0;
                case 's':
 #ifdef CONFIG_FEATURE_SUN_LABEL