suppress warnings about easch <applet>_main() having
[oweals/busybox.git] / miscutils / hdparm.c
index 1c9a99e13edbd85604b139294bd25577d8edea79..eafb0789898817ed9602af38f7e830668f227163 100644 (file)
@@ -463,9 +463,7 @@ static void on_off(unsigned int value);
 
 static void print_flag_on_off(unsigned long get_arg, const char *s, unsigned long arg)
 {
-
-       if (get_arg)
-       {
+       if (get_arg) {
                printf(" setting %s to %ld", s, arg);
                on_off(arg);
        }
@@ -476,8 +474,7 @@ static void bb_ioctl_on_off(int fd, int request, void *argp, const char *string,
 {
        if (ioctl(fd, request, &argp) != 0)
                bb_perror_msg(" %s", string);
-       else
-       {
+       else {
                printf(" %s\t= %2ld", str, (unsigned long) argp);
                on_off((unsigned long) argp);
        }
@@ -486,16 +483,15 @@ static void bb_ioctl_on_off(int fd, int request, void *argp, const char *string,
 #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
 static void print_ascii(uint16_t *p, uint8_t length);
 
-static void xprint_ascii(uint16_t *val ,int i, char * string, int n)
+static void xprint_ascii(uint16_t *val ,int i, const char *string, int n)
 {
-       if (val[i])
-       {
-               printf("\t%-20s",string);
+       if (val[i]) {
+               printf("\t%-20s", string);
                print_ascii(&val[i], n);
        }
 }
 #endif
-/* end of  busybox specific stuff */
+/* end of busybox specific stuff */
 
 #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
 static uint8_t mode_loop(uint16_t mode_sup, uint16_t mode_sel, int cc, uint8_t *have_mode)
@@ -547,7 +543,7 @@ static void print_ascii(uint16_t *p, uint8_t length) {
                printf("%c%c",(char)0x00ff&((*p)>>8),(char)(*p)&0x00ff);
                p++;
        }
-       printf("\n");
+       puts("");
 }
 
 // Parse 512 byte disk identification block and print much crap.
@@ -574,7 +570,7 @@ static void identify(uint16_t *id_supplied)
        chksum &= 0xff;
 
        /* check if we recognise the device type */
-       printf("\n");
+       puts("");
        if (!(val[GEN_CONFIG] & NOT_ATA))
        {
                dev = ATA_DEV;
@@ -595,7 +591,7 @@ static void identify(uint16_t *id_supplied)
        }
        else
                /*"Unknown device type:\n\tbits 15&14 of general configuration word 0 both set to 1.\n"*/
-               bb_error_msg_and_die("Unknown device type");
+               bb_error_msg_and_die("unknown device type");
 
        printf("%sremovable media\n", !(val[GEN_CONFIG] & MEDIA_REMOVABLE) ? "non-" : "");
        /* Info from the specific configuration word says whether or not the
@@ -706,7 +702,7 @@ static void identify(uint16_t *id_supplied)
                else if (like_std > std)
                        printf("& some of %u\n",like_std);
                else
-                       printf("\n");
+                       puts("");
        }
        else
        {
@@ -818,7 +814,7 @@ static void identify(uint16_t *id_supplied)
                if (bbbig > 1000)
                        printf("(%"PRIu64" GB)\n", bbbig/1000);
                else
-                       printf("\n");
+                       puts("");
        }
 
        /* hw support of commands (capabilities) */
@@ -870,7 +866,7 @@ static void identify(uint16_t *id_supplied)
                        if ((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL))
                                printf(", %s device specific minimum\n",(val[CAPAB_1] & MIN_STANDBY_TIMER)?"with":"no");
                        else
-                         printf("\n");
+                         puts("");
                }
                printf("\tR/W multiple sector transfer: ");
                if ((like_std < 3) && !(val[SECTOR_XFER_MAX] & SECTOR_XFER))
@@ -913,7 +909,7 @@ static void identify(uint16_t *id_supplied)
                        printf("\tOverlap support:");
                        if (val[PKT_REL]) printf(" %uus to release bus.",val[PKT_REL]);
                        if (val[SVC_NBSY]) printf(" %uus to clear BSY after SERVICE cmd.",val[SVC_NBSY]);
-                       printf("\n");
+                       puts("");
                }
        }
 
@@ -944,7 +940,7 @@ static void identify(uint16_t *id_supplied)
                        err_dma += mode_loop(jj,kk,'u',&have_mode);
                }
                if (err_dma || !have_mode) printf("(?)");
-               printf("\n");
+               puts("");
 
                if ((dev == ATAPI_DEV) && (eqpt != CDROM) && (val[CAPAB_0] & DMA_IL_SUP))
                        printf("\t\tInterleaved DMA support\n");
@@ -955,7 +951,7 @@ static void identify(uint16_t *id_supplied)
                        printf("\t\tCycle time:");
                        if (val[DMA_TIME_MIN]) printf(" min=%uns",val[DMA_TIME_MIN]);
                        if (val[DMA_TIME_NORM]) printf(" recommended=%uns",val[DMA_TIME_NORM]);
-                       printf("\n");
+                       puts("");
                }
        }
 
@@ -971,13 +967,13 @@ static void identify(uint16_t *id_supplied)
                        if (jj & 0x0001) printf("pio%d ",ii);
                        jj >>=1;
                }
-               printf("\n");
+               puts("");
        }
        else if (((min_std < 5) || (eqpt == CDROM)) && (val[PIO_MODE] & MODE) )
        {
                for (ii = 0; ii <= val[PIO_MODE]>>8; ii++)
                        printf("pio%d ",ii);
-               printf("\n");
+               puts("");
        }
        else
                printf("unknown\n");
@@ -989,7 +985,7 @@ static void identify(uint16_t *id_supplied)
                        printf("\t\tCycle time:");
                        if (val[PIO_NO_FLOW]) printf(" no flow control=%uns", val[PIO_NO_FLOW]);
                        if (val[PIO_FLOW]) printf("  IORDY flow control=%uns", val[PIO_FLOW]);
-                       printf("\n");
+                       puts("");
                }
        }
 
@@ -1049,7 +1045,7 @@ static void identify(uint16_t *id_supplied)
                        printf("\t");
                        if (jj) printf("%umin for %sSECURITY ERASE UNIT. ", jj==ERASE_BITS ? 508 : jj<<1, "");
                        if (kk) printf("%umin for %sSECURITY ERASE UNIT. ", kk==ERASE_BITS ? 508 : kk<<1, "ENHANCED ");
-                       printf("\n");
+                       puts("");
                }
        }
 
@@ -1194,7 +1190,7 @@ static void dump_identity(const struct hd_driveid *id)
                else
                        printf("off");
        }
-       printf("\n");
+       puts("");
 
        if (!(id->field_valid&1))
                printf(" (maybe):");
@@ -1587,7 +1583,7 @@ static void interpret_xfermode(unsigned int xfermode)
 }
 #endif /* HDIO_DRIVE_CMD */
 
-static void print_flag(unsigned long flag, char *s, unsigned long value)
+static void print_flag(unsigned long flag, const char *s, unsigned long value)
 {
        if (flag)
                printf(" setting %s to %ld\n", s, value);
@@ -2025,28 +2021,28 @@ static void process_dev(char *devname)
 #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
 static int fromhex(unsigned char c)
 {
-       if (c >= 'a' && c <= 'f')
-               return 10 + (c - 'a');
-       if (c >= '0' && c <= '9')
+       if (isdigit(c))
                return (c - '0');
+       if (c >= 'a' && c <= 'f')
+               return (c - ('a' - 10));
        bb_error_msg_and_die("bad char: '%c' 0x%02x", c, c);
 }
 
 static void identify_from_stdin(void)
 {
        uint16_t sbuf[256];
-       unsigned char  buf[1280], *b = (unsigned char *)buf;
-       int i, count = read(0, buf, 1280);
+       unsigned char buf[1280];
+       unsigned char *b = (unsigned char *)buf;
+       int i;
 
-       if (count != 1280)
-               bb_error_msg_and_die("read(%d bytes) failed (rc=%d)", 1280, count);
+       xread(0, buf, 1280);
 
        // Convert the newline-separated hex data into an identify block.
 
-       for (i = 0; i<256; i++)
-       {
+       for (i = 0; i<256; i++)  {
                int j;
-               for(j=0;j<4;j++) sbuf[i] = (sbuf[i] <<4) + fromhex(*(b++));
+               for (j = 0; j < 4; j++)
+                       sbuf[i] = (sbuf[i] << 4) + fromhex(*(b++));
        }
 
        // Parse the data.
@@ -2098,7 +2094,9 @@ static const char hdparm_options[] = "gfu::n::p:r::m::c::k::a::B:tTh"
 /*-------------------------------------*/
 
 /* our main() routine: */
+int hdparm_main(int argc, char **argv) ATTRIBUTE_NORETURN;;
 int hdparm_main(int argc, char **argv) ATTRIBUTE_NORETURN;
+int hdparm_main(int argc, char **argv);
 int hdparm_main(int argc, char **argv)
 {
        int c;