Merge "Add Google-style ReadFileToString and WriteStringToFile."
diff --git a/adb/adb.c b/adb/adb.c
index c939ef0..4258a01 100644
--- a/adb/adb.c
+++ b/adb/adb.c
@@ -1348,7 +1348,7 @@
     ** AID_ADB to access the USB driver
     ** AID_LOG to read system logs (adb logcat)
     ** AID_INPUT to diagnose input issues (getevent)
-    ** AID_INET to diagnose network issues (netcfg, ping)
+    ** AID_INET to diagnose network issues (ping)
     ** AID_NET_BT and AID_NET_BT_ADMIN to diagnose bluetooth (hcidump)
     ** AID_SDCARD_R to allow reading from the SD card
     ** AID_SDCARD_RW to allow writing to the SD card
diff --git a/init/Android.mk b/init/Android.mk
index 4df4489..606c199 100644
--- a/init/Android.mk
+++ b/init/Android.mk
@@ -17,7 +17,11 @@
 	ueventd_parser.c \
 	watchdogd.c
 
-LOCAL_CFLAGS    += -Wno-unused-parameter
+LOCAL_CFLAGS += \
+    -std=gnu11 \
+    -Wall \
+    -Werror -Wno-error=deprecated-declarations \
+    -Wno-unused-parameter \
 
 ifeq ($(strip $(INIT_BOOTCHART)),true)
 LOCAL_SRC_FILES += bootchart.c
diff --git a/init/builtins.c b/init/builtins.c
index 303a8ca..2521daf 100644
--- a/init/builtins.c
+++ b/init/builtins.c
@@ -221,16 +221,15 @@
          */
         zap_stdio();
         char *exec_args[100];
-        int i;
-        int num_process_args = nargs;
+        size_t num_process_args = nargs;
 
         memset(exec_args, 0, sizeof(exec_args));
         if (num_process_args > ARRAY_SIZE(exec_args) - 1) {
-            ERROR("exec called with %d args, limit is %d", num_process_args,
+            ERROR("exec called with %zu args, limit is %zu", num_process_args,
                   ARRAY_SIZE(exec_args) - 1);
             _exit(1);
         }
-        for (i = 1; i < num_process_args; i++)
+        for (size_t i = 1; i < num_process_args; i++)
             exec_args[i - 1] = args[i];
 
         if (execv(exec_args[0], exec_args) == -1) {
diff --git a/init/init.c b/init/init.c
index 096d898..8bb6da0 100644
--- a/init/init.c
+++ b/init/init.c
@@ -349,7 +349,7 @@
                 if (arg_idx == INIT_PARSER_MAXARGS)
                     break;
             }
-            arg_ptrs[arg_idx] = '\0';
+            arg_ptrs[arg_idx] = NULL;
             execve(svc->args[0], (char**) arg_ptrs, (char**) ENV);
         }
         _exit(127);
diff --git a/init/readme.txt b/init/readme.txt
index 132a869..e5406ed 100644
--- a/init/readme.txt
+++ b/init/readme.txt
@@ -123,7 +123,7 @@
    Triggers of this form occur when the property <name> is set
    to the specific value <value>.
 
-   One can also test Mutliple properties to execute a group
+   One can also test multiple properties to execute a group
    of commands. For example:
 
    on property:test.a=1 && property:test.b=1
diff --git a/libnetutils/dhcpclient.c b/libnetutils/dhcpclient.c
index 700b02f..a05b7cb 100644
--- a/libnetutils/dhcpclient.c
+++ b/libnetutils/dhcpclient.c
@@ -353,28 +353,28 @@
 static int is_valid_reply(dhcp_msg *msg, dhcp_msg *reply, int sz)
 {
     if (sz < DHCP_MSG_FIXED_SIZE) {
-        if (verbose) ALOGD("netcfg: Wrong size %d != %d\n", sz, DHCP_MSG_FIXED_SIZE);
+        if (verbose) ALOGD("Wrong size %d != %d\n", sz, DHCP_MSG_FIXED_SIZE);
         return 0;
     }
     if (reply->op != OP_BOOTREPLY) {
-        if (verbose) ALOGD("netcfg: Wrong Op %d != %d\n", reply->op, OP_BOOTREPLY);
+        if (verbose) ALOGD("Wrong Op %d != %d\n", reply->op, OP_BOOTREPLY);
         return 0;
     }
     if (reply->xid != msg->xid) {
-        if (verbose) ALOGD("netcfg: Wrong Xid 0x%x != 0x%x\n", ntohl(reply->xid),
-                          ntohl(msg->xid));
+        if (verbose) ALOGD("Wrong Xid 0x%x != 0x%x\n", ntohl(reply->xid),
+                           ntohl(msg->xid));
         return 0;
     }
     if (reply->htype != msg->htype) {
-        if (verbose) ALOGD("netcfg: Wrong Htype %d != %d\n", reply->htype, msg->htype);
+        if (verbose) ALOGD("Wrong Htype %d != %d\n", reply->htype, msg->htype);
         return 0;
     }
     if (reply->hlen != msg->hlen) {
-        if (verbose) ALOGD("netcfg: Wrong Hlen %d != %d\n", reply->hlen, msg->hlen);
+        if (verbose) ALOGD("Wrong Hlen %d != %d\n", reply->hlen, msg->hlen);
         return 0;
     }
     if (memcmp(msg->chaddr, reply->chaddr, msg->hlen)) {
-        if (verbose) ALOGD("netcfg: Wrong chaddr %x != %x\n", *(reply->chaddr),*(msg->chaddr));
+        if (verbose) ALOGD("Wrong chaddr %x != %x\n", *(reply->chaddr),*(msg->chaddr));
         return 0;
     }
     return 1;
diff --git a/netcfg/netcfg.c b/netcfg/netcfg.c
index 204bf1d..eec1b2f 100644
--- a/netcfg/netcfg.c
+++ b/netcfg/netcfg.c
@@ -24,13 +24,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-void die(const char *reason)
-{
-    perror(reason);
-    exit(1);
-}
-
-const char *ipaddr(in_addr_t addr)
+static const char *ipaddr(in_addr_t addr)
 {
     struct in_addr in_addr;
 
@@ -38,13 +32,13 @@
     return inet_ntoa(in_addr);
 }
 
-void usage(void)
+static void usage(void)
 {
-    fprintf(stderr,"usage: netcfg [<interface> {dhcp|up|down}]\n");
+    fprintf(stderr,"usage: netcfg [<interface> dhcp]\n");
     exit(1);
 }
 
-int dump_interface(const char *name)
+static int dump_interface(const char *name)
 {
     unsigned addr, flags;
     unsigned char hwbuf[ETH_ALEN];
@@ -69,7 +63,7 @@
     return 0;
 }
 
-int dump_interfaces(void)
+static int dump_interfaces(void)
 {
     DIR *d;
     struct dirent *de;
@@ -85,56 +79,11 @@
     return 0;
 }
 
-int set_hwaddr(const char *name, const char *asc) {
-    struct ether_addr *addr = ether_aton(asc);
-    if (!addr) {
-        printf("Failed to parse '%s'\n", asc);
-        return -1;
-    }
-    return ifc_set_hwaddr(name, addr->ether_addr_octet);
-}
-
-struct 
-{
-    const char *name;
-    int nargs;
-    void *func;
-} CMDS[] = {
-    { "dhcp",   1, do_dhcp },
-    { "up",     1, ifc_up },
-    { "down",   1, ifc_down },
-    { "deldefault", 1, ifc_remove_default_route },
-    { "hwaddr", 2, set_hwaddr },
-    { 0, 0, 0 },
-};
-
-static int call_func(void *_func, unsigned nargs, char **args)
-{
-    switch(nargs){
-    case 1: {
-        int (*func)(char *a0) = _func;
-        return func(args[0]);
-    }
-    case 2: {
-        int (*func)(char *a0, char *a1) = _func;
-        return func(args[0], args[1]);
-    }
-    case 3: {
-        int (*func)(char *a0, char *a1, char *a2) = _func;
-        return func(args[0], args[1], args[2]);
-    }
-    default:
-        return -1;
-    }
-}
-
 int main(int argc, char **argv)
 {
-    char *iname;
-    int n;
-    
     if(ifc_init()) {
-        die("Cannot perform requested operation");
+        perror("Cannot perform requested operation");
+        exit(1);
     }
 
     if(argc == 1) {
@@ -143,41 +92,23 @@
         return result;
     }
 
-    if(argc < 3) usage();
+    if(argc != 3) usage();
 
-    iname = argv[1];
+    char* iname = argv[1];
+    char* action = argv[2];
     if(strlen(iname) > 16) usage();
 
-    argc -= 2;
-    argv += 2;
-    while(argc > 0) {
-        for(n = 0; CMDS[n].name; n++){
-            if(!strcmp(argv[0], CMDS[n].name)) {
-                char *cmdname = argv[0];
-                int nargs = CMDS[n].nargs;
-                
-                argv[0] = iname;
-                if(argc < nargs) {
-                    fprintf(stderr, "not enough arguments for '%s'\n", cmdname);
-                    ifc_close();
-                    exit(1);
-                }
-                if(call_func(CMDS[n].func, nargs, argv)) {
-                    fprintf(stderr, "action '%s' failed (%s)\n", cmdname, strerror(errno));
-                    ifc_close();
-                    exit(1);
-                }
-                argc -= nargs;
-                argv += nargs;
-                goto done;
-            }
+    if (!strcmp(action, "dhcp")) {
+        if (do_dhcp(iname)) {
+            fprintf(stderr, "dhcp failed: %s\n", strerror(errno));
+            ifc_close();
+            exit(1);
         }
-        fprintf(stderr,"no such action '%s'\n", argv[0]);
+    } else {
+        fprintf(stderr,"no such action '%s'\n", action);
         usage();
-    done:
-        ;
     }
-    ifc_close();
 
+    ifc_close();
     return 0;
 }