Merge changes If5359c26,I5d09be41

* changes:
  Use a function instead of a macro.
  Mark sockets on accept().
diff --git a/fastboot/Android.mk b/fastboot/Android.mk
index 05ddf2a..73794a0 100644
--- a/fastboot/Android.mk
+++ b/fastboot/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_SRC_FILES := protocol.c engine.c bootimg.c fastboot.c util.c fs.c
 LOCAL_MODULE := fastboot
 LOCAL_MODULE_TAGS := debug
-LOCAL_CFLAGS += -std=gnu99
+LOCAL_CFLAGS += -std=gnu99 -Werror
 
 ifeq ($(HOST_OS),linux)
   LOCAL_SRC_FILES += usb_linux.c util_linux.c
@@ -72,6 +72,7 @@
 include $(CLEAR_VARS)
 LOCAL_SRC_FILES := usbtest.c usb_linux.c util.c
 LOCAL_MODULE := usbtest
+LOCAL_CFLAGS := -Werror
 include $(BUILD_HOST_EXECUTABLE)
 endif
 
diff --git a/fastboot/engine.c b/fastboot/engine.c
index 5a6709b..2f90e41 100644
--- a/fastboot/engine.c
+++ b/fastboot/engine.c
@@ -30,10 +30,10 @@
 #include "fs.h"
 
 #include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
 #include <stdarg.h>
 #include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -45,6 +45,10 @@
 #include <sys/mman.h>
 #endif
 
+#ifndef __unused
+#define __unused __attribute__((__unused__))
+#endif
+
 #define ARRAY_SIZE(x)           (sizeof(x)/sizeof(x[0]))
 
 #define OP_DOWNLOAD   1
@@ -106,7 +110,6 @@
 {
     char fs_type[FB_RESPONSE_SZ + 1] = {0,};
     int status;
-    unsigned int i;
 
     if (type_override) {
         return !!fs_get_generator(type_override);
@@ -197,9 +200,7 @@
 
 static int match(char *str, const char **value, unsigned count)
 {
-    const char *val;
     unsigned n;
-    int len;
 
     for (n = 0; n < count; n++) {
         const char *val = value[n];
@@ -325,7 +326,7 @@
     a->func = cb_save;
 }
 
-static int cb_do_nothing(Action *a, int status, char *resp)
+static int cb_do_nothing(Action *a __unused, int status __unused, char *resp __unused)
 {
     fprintf(stderr,"\n");
     return 0;
diff --git a/fastboot/fastboot.c b/fastboot/fastboot.c
index 4d3e0af..3a140ab 100644
--- a/fastboot/fastboot.c
+++ b/fastboot/fastboot.c
@@ -28,22 +28,20 @@
 
 #define _LARGEFILE64_SOURCE
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <string.h>
-
+#include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <unistd.h>
-#include <limits.h>
-#include <ctype.h>
 #include <getopt.h>
-
+#include <limits.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/types.h>
-#include <sys/stat.h>
+#include <unistd.h>
 
 #include <bootimg.h>
 #include <sparse/sparse.h>
@@ -72,7 +70,6 @@
 static const char *serial = 0;
 static const char *product = 0;
 static const char *cmdline = 0;
-static int wipe_data = 0;
 static unsigned short vendor_id = 0;
 static int long_listing = 0;
 static int64_t sparse_limit = -1;
@@ -270,7 +267,7 @@
             announce = 0;
             fprintf(stderr,"< waiting for device >\n");
         }
-        sleep(1);
+        usleep(1000);
     }
 }
 
@@ -428,7 +425,7 @@
         return -1;
     }
 
-    if (write(fd, data, sz) != sz) {
+    if (write(fd, data, sz) != (ssize_t)sz) {
         fd = -1;
     }
 
@@ -722,7 +719,7 @@
     int fd;
     int rc;
     struct fastboot_buffer buf;
-    int i;
+    size_t i;
 
     queue_info_dump();
 
@@ -796,7 +793,7 @@
     void *data;
     unsigned sz;
     struct fastboot_buffer buf;
-    int i;
+    size_t i;
 
     queue_info_dump();
 
@@ -828,7 +825,6 @@
 
 int do_oem_command(int argc, char **argv)
 {
-    int i;
     char command[256];
     if (argc <= 1) return 0;
 
@@ -915,7 +911,7 @@
                     "Warning: %s type is %s, but %s was requested for formating.\n",
                     partition, pType, type_override);
         }
-        pType = type_override;
+        pType = (char *)type_override;
     }
 
     status = fb_getvar(usb, pSize, "partition-size:%s", partition);
@@ -929,7 +925,7 @@
                     "Warning: %s size is %s, but %s was requested for formating.\n",
                     partition, pSize, size_override);
         }
-        pSize = size_override;
+        pSize = (char *)size_override;
     }
 
     gen = fs_get_generator(pType);
@@ -981,7 +977,6 @@
     unsigned sz;
     int status;
     int c;
-    int r;
 
     const struct option longopts[] = {
         {"base", required_argument, 0, 'b'},
@@ -996,7 +991,6 @@
     serial = getenv("ANDROID_SERIAL");
 
     while (1) {
-        int option_index = 0;
         c = getopt_long(argc, argv, "wub:k:n:r:t:s:S:lp:c:i:m:h", longopts, NULL);
         if (c < 0) {
             break;
diff --git a/fastboot/protocol.c b/fastboot/protocol.c
index a0e0fd4..84e9837 100644
--- a/fastboot/protocol.c
+++ b/fastboot/protocol.c
@@ -110,7 +110,6 @@
                           char *response)
 {
     int cmdsize = strlen(cmd);
-    int r;
 
     if(response) {
         response[0] = 0;
@@ -189,8 +188,6 @@
 static int _command_send_no_data(usb_handle *usb, const char *cmd,
                                  char *response)
 {
-    int r;
-
     return _command_start(usb, cmd, 0, response);
 }
 
diff --git a/fastboot/usb_linux.c b/fastboot/usb_linux.c
index f2ce226..a45f9f8 100644
--- a/fastboot/usb_linux.c
+++ b/fastboot/usb_linux.c
@@ -125,9 +125,6 @@
     unsigned i;
     unsigned e;
     
-    struct stat st;
-    int result;
-
     if(check(ptr, len, USB_DT_DEVICE, USB_DT_DEVICE_SIZE))
         return -1;
     dev = (void*) ptr;
diff --git a/fastboot/usb_windows.c b/fastboot/usb_windows.c
index f666015..0d13863 100644
--- a/fastboot/usb_windows.c
+++ b/fastboot/usb_windows.c
@@ -178,7 +178,7 @@
 
             count += written;
             len -= written;
-            data += written;
+            data = (const char *)data + written;
 
             if (len == 0)
                 return count;
diff --git a/fastboot/usbtest.c b/fastboot/usbtest.c
index b8fb9e2..e6e2b37 100644
--- a/fastboot/usbtest.c
+++ b/fastboot/usbtest.c
@@ -88,14 +88,14 @@
 
 int test_null(usb_handle *usb)
 {
-    int i;
+    unsigned i;
     unsigned char buf[4096];
     memset(buf, 0xee, 4096);
     long long t0, t1;
 
     t0 = NOW();
     for(i = 0; i < arg_count; i++) {
-        if(usb_write(usb, buf, arg_size) != arg_size) {
+        if(usb_write(usb, buf, arg_size) != (int)arg_size) {
             fprintf(stderr,"write failed (%s)\n", strerror(errno));
             return -1;
         }
@@ -107,13 +107,13 @@
 
 int test_zero(usb_handle *usb)
 {
-    int i;
+    unsigned i;
     unsigned char buf[4096];
     long long t0, t1;
 
     t0 = NOW();
     for(i = 0; i < arg_count; i++) {
-        if(usb_read(usb, buf, arg_size) != arg_size) {
+        if(usb_read(usb, buf, arg_size) != (int)arg_size) {
             fprintf(stderr,"read failed (%s)\n", strerror(errno));
             return -1;
         }
@@ -130,11 +130,11 @@
     int (*test)(usb_handle *usb);
     const char *help;
 } tests[] = {
-    { "list", printifc,   0,         "list interfaces" },
+    { "list", printifc,   NULL,      "list interfaces" },
     { "send", match_null, test_null, "send to null interface" },
     { "recv", match_zero, test_zero, "recv from zero interface" },
-    { "loop", match_loop, 0,         "exercise loopback interface" },
-    {},
+    { "loop", match_loop, NULL,      "exercise loopback interface" },
+    { NULL, NULL, NULL, NULL },
 };
 
 int usage(void)
diff --git a/libzipfile/Android.mk b/libzipfile/Android.mk
index d2d758c..614a460 100644
--- a/libzipfile/Android.mk
+++ b/libzipfile/Android.mk
@@ -14,6 +14,8 @@
 
 LOCAL_C_INCLUDES += external/zlib
 
+LOCAL_CFLAGS := -Werror
+
 include $(BUILD_HOST_STATIC_LIBRARY)
 
 # build device static library
@@ -30,6 +32,8 @@
 
 LOCAL_C_INCLUDES += external/zlib
 
+LOCAL_CFLAGS := -Werror
+
 include $(BUILD_STATIC_LIBRARY)
 
 
@@ -45,4 +49,6 @@
 
 LOCAL_C_INCLUDES += external/zlib
 
+LOCAL_CFLAGS := -Werror
+
 include $(BUILD_HOST_EXECUTABLE)
diff --git a/libzipfile/centraldir.c b/libzipfile/centraldir.c
index 911e2b9..69cf47a 100644
--- a/libzipfile/centraldir.c
+++ b/libzipfile/centraldir.c
@@ -3,6 +3,8 @@
 #include <string.h>

 #include <stdlib.h>

 

+#include <utils/Compat.h>

+

 enum {

     // finding the directory

     CD_SIGNATURE = 0x06054b50,

@@ -66,24 +68,10 @@
 {

     const unsigned char* p;

 

-    unsigned short  versionMadeBy;

-    unsigned short  versionToExtract;

-    unsigned short  gpBitFlag;

-    unsigned short  compressionMethod;

-    unsigned short  lastModFileTime;

-    unsigned short  lastModFileDate;

-    unsigned long   crc32;

     unsigned short  extraFieldLength;

     unsigned short  fileCommentLength;

-    unsigned short  diskNumberStart;

-    unsigned short  internalAttrs;

-    unsigned long   externalAttrs;

     unsigned long   localHeaderRelOffset;

-    const unsigned char*  extraField;

-    const unsigned char*  fileComment;

     unsigned int dataOffset;

-    unsigned short lfhExtraFieldSize;

-

 

     p = *buf;

 

@@ -97,21 +85,12 @@
         return -1;

     }

 

-    versionMadeBy = read_le_short(&p[0x04]);

-    versionToExtract = read_le_short(&p[0x06]);

-    gpBitFlag = read_le_short(&p[0x08]);

     entry->compressionMethod = read_le_short(&p[0x0a]);

-    lastModFileTime = read_le_short(&p[0x0c]);

-    lastModFileDate = read_le_short(&p[0x0e]);

-    crc32 = read_le_int(&p[0x10]);

     entry->compressedSize = read_le_int(&p[0x14]);

     entry->uncompressedSize = read_le_int(&p[0x18]);

     entry->fileNameLength = read_le_short(&p[0x1c]);

     extraFieldLength = read_le_short(&p[0x1e]);

     fileCommentLength = read_le_short(&p[0x20]);

-    diskNumberStart = read_le_short(&p[0x22]);

-    internalAttrs = read_le_short(&p[0x24]);

-    externalAttrs = read_le_int(&p[0x26]);

     localHeaderRelOffset = read_le_int(&p[0x2a]);

 

     p += ENTRY_LEN;

@@ -125,19 +104,9 @@
     p += entry->fileNameLength;

 

     // extra field

-    if (extraFieldLength != 0) {

-        extraField = p;

-    } else {

-        extraField = NULL;

-    }

     p += extraFieldLength;

 

     // comment, if any

-    if (fileCommentLength != 0) {

-        fileComment = p;

-    } else {

-        fileComment = NULL;

-    }

     p += fileCommentLength;

 

     *buf = p;

@@ -183,7 +152,7 @@
     int err;

 

     const unsigned char* buf = file->buf;

-    ssize_t bufsize = file->bufsize;

+    ZD_TYPE bufsize = file->bufsize;

     const unsigned char* eocd;

     const unsigned char* p;

     const unsigned char* start;

@@ -192,7 +161,7 @@
 

     // too small to be a ZIP archive?

     if (bufsize < EOCD_LEN) {

-        fprintf(stderr, "Length is %zd -- too small\n", bufsize);

+        fprintf(stderr, "Length is " ZD " -- too small\n", bufsize);

         goto bail;

     }

 

diff --git a/libzipfile/zipfile.c b/libzipfile/zipfile.c
index a401a9b..b903fcf 100644
--- a/libzipfile/zipfile.c
+++ b/libzipfile/zipfile.c
@@ -79,7 +79,6 @@
 uninflate(unsigned char* out, int unlen, const unsigned char* in, int clen)
 {
     z_stream zstream;
-    unsigned long crc;
     int err = 0;
     int zerr;