ao-tools/ao-chaosread: Add -Wall -Wextra, clean up results
authorKeith Packard <keithp@keithp.com>
Wed, 6 Sep 2017 14:37:12 +0000 (08:37 -0600)
committerKeith Packard <keithp@keithp.com>
Tue, 12 Sep 2017 20:31:38 +0000 (13:31 -0700)
ao-tools/ao-chaosread/Makefile.am
ao-tools/ao-chaosread/ao-chaosread.c

index 581eb2d22bc45b5e4ff9b98e0190836869727b1f..6ba8885ce12dd1ebb5f3c113b842cc42f5e1e1d8 100644 (file)
@@ -1,6 +1,6 @@
 bin_PROGRAMS=ao-chaosread
 
-AM_CFLAGS=-I$(top_srcdir)/ao-tools/lib $(LIBUSB_CFLAGS)
+AM_CFLAGS=$(LIBUSB_CFLAGS) -Wall -Wextra
 
 ao_chaosread_LDADD=$(LIBUSB_LIBS)
 
index 7808f6c91d5cdad2689219951ac117ff96bc6392..6d860139f71487a59dbd3f9d8e6433532fa018b4 100644 (file)
@@ -74,7 +74,7 @@ chaoskey_match(libusb_device *dev, char *match_serial)
                goto out;
        }
 
-       ret = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, device_serial, match_len + 1);
+       ret = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, (unsigned char *) device_serial, match_len + 1);
 
        if (ret < 0) {
                fprintf(stderr, "failed to get serial number: %s\n", libusb_strerror(ret));
@@ -103,7 +103,6 @@ chaoskey_open(char *serial)
        int             ret;
        ssize_t         num;
        libusb_device   **list;
-       libusb_device   *device = NULL;
        int             d;
 
        ck = calloc(sizeof (struct chaoskey), 1);
@@ -173,12 +172,6 @@ chaoskey_close(struct chaoskey *ck)
        free(ck);
 }
 
-void
-chaoskey_transfer_callback(struct libusb_transfer *transfer)
-{
-       struct chaoskey *ck = transfer->user_data;
-}
-
 #define ENDPOINT       0x86
 
 int
@@ -202,7 +195,9 @@ chaoskey_read(struct chaoskey *ck, void *buffer, int len)
                }
                len -= transferred;
                buf += transferred;
+               total += transferred;
        }
+       return total;
 }
 
 static const struct option options[] = {
@@ -283,8 +278,17 @@ main (int argc, char **argv)
                        int i;
                        for (i = 0; i < got / 2; i++)
                                putchar((buf[i] >> 1 & 0xff));
-               } else
-                       write(1, buf, got);
+               } else {
+                       int i;
+                       int ret;
+                       for (i = 0; i < got; i += ret) {
+                               ret = write(1, ((char *) buf) + i, got - i);
+                               if (ret <= 0) {
+                                       perror("write");
+                                       exit(1);
+                               }
+                       }
+               }
                length -= got;
        }
        exit(0);