Merge "toolbox: turn on -Werror"
diff --git a/toolbox/Android.mk b/toolbox/Android.mk
index 5383b83..fddf0a9 100644
--- a/toolbox/Android.mk
+++ b/toolbox/Android.mk
@@ -96,7 +96,7 @@
 
 LOCAL_CFLAGS += \
     -std=gnu99 \
-    -Wno-unused-parameter \
+    -Werror -Wno-unused-parameter \
     -include bsd-compatibility.h \
 
 LOCAL_SHARED_LIBRARIES := \
diff --git a/toolbox/cp/cp.c b/toolbox/cp/cp.c
index bd3c70e..e666453 100644
--- a/toolbox/cp/cp.c
+++ b/toolbox/cp/cp.c
@@ -95,12 +95,14 @@
 
 static int copy(char *[], enum op, int);
 
+#ifndef ANDROID
 static void
 progress(int sig __unused)
 {
 
 	pinfo++;
 }
+#endif
 
 int
 cp_main(int argc, char *argv[])
diff --git a/toolbox/cp/utils.c b/toolbox/cp/utils.c
index b682bbe..9d0390f 100644
--- a/toolbox/cp/utils.c
+++ b/toolbox/cp/utils.c
@@ -380,10 +380,11 @@
 int
 setfile(struct stat *fs, int fd)
 {
-	int rval, islink;
+	int rval = 0;
+#ifndef ANDROID
+	int islink = S_ISLNK(fs->st_mode);
+#endif
 
-	rval = 0;
-	islink = S_ISLNK(fs->st_mode);
 	fs->st_mode &= S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO;
 
 	/*
@@ -401,13 +402,13 @@
 		fs->st_mode &= ~(S_ISUID | S_ISGID);
 	}
 #ifdef ANDROID
-    if (fd ? fchmod(fd, fs->st_mode) : chmod(to.p_path, fs->st_mode)) {
+        if (fd ? fchmod(fd, fs->st_mode) : chmod(to.p_path, fs->st_mode)) {
 #else
-    if (fd ? fchmod(fd, fs->st_mode) : lchmod(to.p_path, fs->st_mode)) {
+        if (fd ? fchmod(fd, fs->st_mode) : lchmod(to.p_path, fs->st_mode)) {
 #endif
-        warn("chmod: %s", to.p_path);
-        rval = 1;
-    }
+                warn("chmod: %s", to.p_path);
+                rval = 1;
+        }
 
 #ifndef ANDROID
 	if (!islink && !Nflag) {
diff --git a/toolbox/date.c b/toolbox/date.c
index aa3b72e..70ce1d5 100644
--- a/toolbox/date.c
+++ b/toolbox/date.c
@@ -140,14 +140,12 @@
 
 int date_main(int argc, char *argv[])
 {
-	int c;
+    int c;
     int res;
-	struct tm tm;
-	time_t t;
-	struct timeval tv;
-    struct timespec ts;
-	char strbuf[260];
-    int fd;
+    struct tm tm;
+    time_t t;
+    struct timeval tv;
+    char strbuf[260];
 
     int useutc = 0;
 
@@ -177,7 +175,6 @@
 
     int hasfmt = argc == optind + 1 && argv[optind][0] == '+';
     if(optind == argc || hasfmt) {
-        char buf[2000];
         time(&t);
         if (useutc) {
             gmtime_r(&t, &tm);
diff --git a/toolbox/dd.c b/toolbox/dd.c
index 6b61ffb..408a496 100644
--- a/toolbox/dd.c
+++ b/toolbox/dd.c
@@ -356,7 +356,7 @@
 			++st.in_full;
 
 		/* Handle full input blocks. */
-		} else if (n == in.dbsz) {
+		} else if (n == (int64_t)in.dbsz) {
 			in.dbcnt += in.dbrcnt = n;
 			++st.in_full;
 
@@ -521,7 +521,7 @@
 			outp += nw;
 			st.bytes += nw;
 			if (nw == n) {
-				if (n != out.dbsz)
+				if (n != (int64_t)out.dbsz)
 					++st.out_part;
 				else
 					++st.out_full;
@@ -649,8 +649,8 @@
 void
 pos_out(void)
 {
-//	struct mtop t_op;
-	int cnt, n;
+/*	struct mtop t_op;        */
+	int64_t cnt, n;
 
 	/*
 	 * If not a tape, try seeking on the file.  Seeking on a pipe is
@@ -681,7 +681,7 @@
 	}
 
 	/* Read it. */
-	for (cnt = 0; cnt < out.offset; ++cnt) {
+	for (cnt = 0; cnt < (int64_t)out.offset; ++cnt) {
 		if ((n = read(out.fd, out.db, out.dbsz)) > 0)
 			continue;
 
@@ -705,8 +705,8 @@
 			/* NOTREACHED */
 		}
 
-		while (cnt++ < out.offset)
-			if ((n = bwrite(out.fd, out.db, out.dbsz)) != out.dbsz) {
+		while (cnt++ < (int64_t)out.offset)
+			if ((n = bwrite(out.fd, out.db, out.dbsz)) != (int64_t)out.dbsz) {
 				fprintf(stderr, "%s: cannot position "
 					"by writing: %s\n",
 					out.name, strerror(errno));
@@ -1153,7 +1153,7 @@
 	    ((const struct arg *)b)->name));
 }
 
-static long long strsuftoll(const char* name, const char* arg, int def, unsigned int max)
+static long long strsuftoll(const char* name, const char* arg, int def, unsigned long long max)
 {
 	long long result;
 	
@@ -1180,7 +1180,7 @@
 f_count(char *arg)
 {
 
-	cpy_cnt = strsuftoll("block count", arg, 0, LLONG_MAX);
+	cpy_cnt = (uint64_t)strsuftoll("block count", arg, 0, 0xFFFFFFFFFFFFFFFFULL);
 	if (!cpy_cnt)
 		terminate(0);
 }
@@ -1228,14 +1228,14 @@
 f_seek(char *arg)
 {
 
-	out.offset = strsuftoll("seek blocks", arg, 0, LLONG_MAX);
+	out.offset = (uint64_t)strsuftoll("seek blocks", arg, 0, 0xFFFFFFFFFFFFFFFFULL);
 }
 
 static void
 f_skip(char *arg)
 {
 
-	in.offset = strsuftoll("skip blocks", arg, 0, LLONG_MAX);
+	in.offset = (uint64_t)strsuftoll("skip blocks", arg, 0, 0xFFFFFFFFFFFFFFFFULL);
 }
 
 static void
diff --git a/toolbox/du.c b/toolbox/du.c
index fc7c943..c8beba5 100644
--- a/toolbox/du.c
+++ b/toolbox/du.c
@@ -76,7 +76,7 @@
 	int64_t totalblocks;
 	int ftsoptions, listfiles;
 	int depth;
-	int Hflag, Lflag, aflag, ch, cflag, dflag, gkmflag, nflag, rval, sflag;
+	int Hflag, Lflag, aflag, ch, cflag, dflag, gkmflag, rval, sflag;
 	const char *noargv[2];
 
 	Hflag = Lflag = aflag = cflag = dflag = gkmflag = sflag = 0;
diff --git a/toolbox/getevent.c b/toolbox/getevent.c
index ed381f5..c2256ff 100644
--- a/toolbox/getevent.c
+++ b/toolbox/getevent.c
@@ -492,13 +492,11 @@
     int c;
     int i;
     int res;
-    int pollres;
     int get_time = 0;
     int print_device = 0;
     char *newline = "\n";
     uint16_t get_switch = 0;
     struct input_event event;
-    int version;
     int print_flags = 0;
     int print_flags_set = 0;
     int dont_block = -1;
@@ -629,7 +627,8 @@
         return 0;
 
     while(1) {
-        pollres = poll(ufds, nfds, -1);
+        //int pollres =
+        poll(ufds, nfds, -1);
         //printf("poll %d, returned %d\n", nfds, pollres);
         if(ufds[0].revents & POLLIN) {
             read_notify(device_path, ufds[0].fd, print_flags);
diff --git a/toolbox/getevent.h b/toolbox/getevent.h
index 2b76209..0482d04 100644
--- a/toolbox/getevent.h
+++ b/toolbox/getevent.h
@@ -652,6 +652,7 @@
         LABEL_END,
 };
 
+#if 0
 static struct label id_labels[] = {
         LABEL(ID_BUS),
         LABEL(ID_VENDOR),
@@ -682,6 +683,7 @@
         LABEL(BUS_SPI),
         LABEL_END,
 };
+#endif
 
 static struct label mt_tool_labels[] = {
         LABEL(MT_TOOL_FINGER),
diff --git a/toolbox/getprop.c b/toolbox/getprop.c
index 7fd694d..dcc0ea0 100644
--- a/toolbox/getprop.c
+++ b/toolbox/getprop.c
@@ -32,8 +32,6 @@
 
 int getprop_main(int argc, char *argv[])
 {
-    int n = 0;
-
     if (argc == 1) {
         list_properties();
     } else {
diff --git a/toolbox/grep/file.c b/toolbox/grep/file.c
index 86b7658..d28dff5 100644
--- a/toolbox/grep/file.c
+++ b/toolbox/grep/file.c
@@ -78,7 +78,9 @@
 grep_refill(struct file *f)
 {
 	ssize_t nr;
+#ifndef ANDROID
 	int bzerr;
+#endif
 
 	bufpos = buffer;
 	bufrem = 0;
diff --git a/toolbox/grep/grep.c b/toolbox/grep/grep.c
index 5a4fa0c..7b2c487 100644
--- a/toolbox/grep/grep.c
+++ b/toolbox/grep/grep.c
@@ -403,7 +403,7 @@
 				Aflag = 0;
 			else if (Aflag > LLONG_MAX / 10) {
 				errno = ERANGE;
-				err(2, NULL);
+				err(2, "%llu", Aflag);
 			}
 			Aflag = Bflag = (Aflag * 10) + (c - '0');
 			break;
@@ -420,10 +420,10 @@
 			l = strtoull(optarg, &ep, 10);
 			if (((errno == ERANGE) && (l == ULLONG_MAX)) ||
 			    ((errno == EINVAL) && (l == 0)))
-				err(2, NULL);
+				err(2, "strtoull");
 			else if (ep[0] != '\0') {
 				errno = EINVAL;
-				err(2, NULL);
+				err(2, "empty");
 			}
 			if (c == 'A')
 				Aflag = l;
@@ -509,10 +509,10 @@
 			mcount = strtoull(optarg, &ep, 10);
 			if (((errno == ERANGE) && (mcount == ULLONG_MAX)) ||
 			    ((errno == EINVAL) && (mcount == 0)))
-				err(2, NULL);
+				err(2, "strtoull");
 			else if (ep[0] != '\0') {
 				errno = EINVAL;
-				err(2, NULL);
+				err(2, "empty");
 			}
 			break;
 		case 'n':
diff --git a/toolbox/hd.c b/toolbox/hd.c
index 0d2f96a..7c9998e 100644
--- a/toolbox/hd.c
+++ b/toolbox/hd.c
@@ -14,7 +14,6 @@
 	unsigned char buf[4096];
     int res;
 	int read_len;
-	int rv = 0;
 	int i;
 	int filepos = 0;
 	int sum;
diff --git a/toolbox/ioctl.c b/toolbox/ioctl.c
index fb555d2..17fabff 100644
--- a/toolbox/ioctl.c
+++ b/toolbox/ioctl.c
@@ -21,9 +21,9 @@
     int arg_size = 4;
     int direct_arg = 0;
     uint32_t ioctl_nr;
-    void *ioctl_args;
+    void *ioctl_args = NULL;
     uint8_t *ioctl_argp;
-    uint8_t *ioctl_argp_save;
+    uint8_t *ioctl_argp_save = NULL;
     int rem;
 
     do {
@@ -112,6 +112,7 @@
     else
         res = ioctl(fd, ioctl_nr, 0);
     if (res < 0) {
+        free(ioctl_args);
         fprintf(stderr, "ioctl 0x%x failed, %d\n", ioctl_nr, res);
         return 1;
     }
@@ -124,5 +125,6 @@
         }
         printf("\n");
     }
+    free(ioctl_args);
     return 0;
 }
diff --git a/toolbox/load_policy.c b/toolbox/load_policy.c
index eb5aba6..90d48c4 100644
--- a/toolbox/load_policy.c
+++ b/toolbox/load_policy.c
@@ -10,7 +10,7 @@
 
 int load_policy_main(int argc, char **argv)
 {
-    int fd, rc, vers;
+    int fd, rc;
     struct stat sb;
     void *map;
     const char *path;
diff --git a/toolbox/ls.c b/toolbox/ls.c
index 06910ee..011f7b5 100644
--- a/toolbox/ls.c
+++ b/toolbox/ls.c
@@ -443,7 +443,6 @@
 int ls_main(int argc, char **argv)
 {
     int flags = 0;
-    int listed = 0;
 
     if(argc > 1) {
         int i;
diff --git a/toolbox/lsof.c b/toolbox/lsof.c
index af321af..bee981d 100644
--- a/toolbox/lsof.c
+++ b/toolbox/lsof.c
@@ -99,10 +99,7 @@
 static void print_maps(struct pid_info_t* info)
 {
     FILE *maps;
-    char buffer[PATH_MAX + 100];
-
     size_t offset;
-    int major, minor;
     char device[10];
     long int inode;
     char file[PATH_MAX];
diff --git a/toolbox/mkdir.c b/toolbox/mkdir.c
index 656970a..398d350 100644
--- a/toolbox/mkdir.c
+++ b/toolbox/mkdir.c
@@ -15,7 +15,6 @@
 
 int mkdir_main(int argc, char *argv[])
 {
-    int symbolic = 0;
     int ret;
     if(argc < 2 || strcmp(argv[1], "--help") == 0) {
         return usage();
diff --git a/toolbox/newfs_msdos.c b/toolbox/newfs_msdos.c
index 27dca42..30b9f77 100644
--- a/toolbox/newfs_msdos.c
+++ b/toolbox/newfs_msdos.c
@@ -360,7 +360,7 @@
     if (!opt_create && !strchr(fname, '/')) {
 	snprintf(buf, sizeof(buf), "%s%s", _PATH_DEV, fname);
 	if (!(fname = strdup(buf)))
-	    err(1, NULL);
+	    err(1, "%s", buf);
     }
     dtype = *argv;
     if (opt_create) {
@@ -493,7 +493,7 @@
 	if (!strchr(bname, '/')) {
 	    snprintf(buf, sizeof(buf), "/boot/%s", bname);
 	    if (!(bname = strdup(buf)))
-		err(1, NULL);
+		err(1, "%s", buf);
 	}
 	if ((fd1 = open(bname, O_RDONLY)) == -1 || fstat(fd1, &sb))
 	    err(1, "%s", bname);
@@ -611,7 +611,7 @@
 	now = tv.tv_sec;
 	tm = localtime(&now);
 	if (!(img = malloc(bpb.bps)))
-	    err(1, NULL);
+	    err(1, "%u", bpb.bps);
 	dir = bpb.res + (bpb.spf ? bpb.spf : bpb.bspf) * bpb.nft;
 	for (lsn = 0; lsn < dir + (fat == 32 ? bpb.spc : rds); lsn++) {
 	    x = lsn;
@@ -728,14 +728,14 @@
 static void
 check_mounted(const char *fname, mode_t mode)
 {
+#ifdef ANDROID
+    warnx("Skipping mount checks");
+#else
     struct statfs *mp;
     const char *s1, *s2;
     size_t len;
     int n, r;
 
-#ifdef ANDROID
-    warnx("Skipping mount checks");
-#else
     if (!(n = getmntinfo(&mp, MNT_NOWAIT)))
 	err(1, "getmntinfo");
     len = strlen(_PATH_DEV);
diff --git a/toolbox/ps.c b/toolbox/ps.c
index e9fba0b..57b4280 100644
--- a/toolbox/ps.c
+++ b/toolbox/ps.c
@@ -43,7 +43,7 @@
     struct stat stats;
     int fd, r;
     char *ptr, *name, *state;
-    int ppid, tty;
+    int ppid;
     unsigned wchan, rss, vss, eip;
     unsigned utime, stime;
     int prio, nice, rtprio, sched, psr;
@@ -91,7 +91,7 @@
     ppid = atoi(nexttok(&ptr));
     nexttok(&ptr); // pgrp
     nexttok(&ptr); // sid
-    tty = atoi(nexttok(&ptr));
+    nexttok(&ptr); // tty
     
     nexttok(&ptr); // tpgid
     nexttok(&ptr); // flags
@@ -133,7 +133,7 @@
     rtprio = atoi(nexttok(&ptr)); // rt_priority
     sched = atoi(nexttok(&ptr)); // scheduling policy
     
-    tty = atoi(nexttok(&ptr));
+    nexttok(&ptr); // tty
     
     if(tid != 0) {
         ppid = pid;
diff --git a/toolbox/rmdir.c b/toolbox/rmdir.c
index 06f3df2..749fec8 100644
--- a/toolbox/rmdir.c
+++ b/toolbox/rmdir.c
@@ -11,7 +11,6 @@
 
 int rmdir_main(int argc, char *argv[])
 {
-    int symbolic = 0;
     int ret;
     if(argc < 2) return usage();
 
diff --git a/toolbox/schedtop.c b/toolbox/schedtop.c
index 0c85e76..2fccd2e 100644
--- a/toolbox/schedtop.c
+++ b/toolbox/schedtop.c
@@ -227,7 +227,6 @@
     }
     for (i = 0; i < last_processes.active; i++) {
         int pid = last_processes.data[i].pid;
-        int tid = last_processes.data[i].tid;
         for (j = 0; j < processes.active; j++)
             if (pid == processes.data[j].pid)
                 break;
@@ -270,9 +269,6 @@
 {
     int c;
     DIR *d;
-    struct dirent *de;
-    char *namefilter = 0;
-    int pidfilter = 0;
     uint32_t flags = 0;    
     int delay = 3000000;
     float delay_f;
diff --git a/toolbox/sendevent.c b/toolbox/sendevent.c
index 1608e6c..9b813f6 100644
--- a/toolbox/sendevent.c
+++ b/toolbox/sendevent.c
@@ -47,9 +47,8 @@
 
 int sendevent_main(int argc, char *argv[])
 {
-    int i;
     int fd;
-    int ret;
+    ssize_t ret;
     int version;
     struct input_event event;
 
@@ -72,7 +71,7 @@
     event.code = atoi(argv[3]);
     event.value = atoi(argv[4]);
     ret = write(fd, &event, sizeof(event));
-    if(ret < sizeof(event)) {
+    if(ret < (ssize_t) sizeof(event)) {
         fprintf(stderr, "write event failed, %s\n", strerror(errno));
         return -1;
     }
diff --git a/toolbox/start.c b/toolbox/start.c
index 26344da..0941e64 100644
--- a/toolbox/start.c
+++ b/toolbox/start.c
@@ -7,8 +7,6 @@
 
 int start_main(int argc, char *argv[])
 {
-    char buf[1024];
-
     if(argc > 1) {
         property_set("ctl.start", argv[1]);
     } else {
diff --git a/toolbox/stop.c b/toolbox/stop.c
index 6552c7c..ed9a293 100644
--- a/toolbox/stop.c
+++ b/toolbox/stop.c
@@ -5,8 +5,6 @@
 
 int stop_main(int argc, char *argv[])
 {
-    char buf[1024];
-
     if(argc > 1) {
         property_set("ctl.stop", argv[1]);
     } else{
diff --git a/toolbox/top.c b/toolbox/top.c
index 7382f1f..280a032 100644
--- a/toolbox/top.c
+++ b/toolbox/top.c
@@ -328,7 +328,6 @@
 static int read_stat(char *filename, struct proc_info *proc) {
     FILE *file;
     char buf[MAX_LINE], *open_paren, *close_paren;
-    int res, idx;
 
     file = fopen(filename, "r");
     if (!file) return 1;
@@ -414,9 +413,7 @@
     struct proc_info *old_proc, *proc;
     long unsigned total_delta_time;
     struct passwd *user;
-    struct group *group;
     char *user_str, user_buf[20];
-    char *group_str, group_buf[20];
 
     for (i = 0; i < num_new_procs; i++) {
         if (new_procs[i]) {
@@ -467,19 +464,12 @@
         if (!proc || (max_procs && (i >= max_procs)))
             break;
         user  = getpwuid(proc->uid);
-        group = getgrgid(proc->gid);
         if (user && user->pw_name) {
             user_str = user->pw_name;
         } else {
             snprintf(user_buf, 20, "%d", proc->uid);
             user_str = user_buf;
         }
-        if (group && group->gr_name) {
-            group_str = group->gr_name;
-        } else {
-            snprintf(group_buf, 20, "%d", proc->gid);
-            group_str = group_buf;
-        }
         if (!threads)
             printf("%5d %2d %3ld%% %c %5d %6ldK %6ldK %3s %-8.8s %s\n", proc->pid, proc->prs, proc->delta_time * 100 / total_delta_time, proc->state, proc->num_threads,
                 proc->vss / 1024, proc->rss * getpagesize() / 1024, proc->policy, user_str, proc->name[0] != 0 ? proc->name : proc->tname);
diff --git a/toolbox/umount.c b/toolbox/umount.c
index 890e870..3e17396 100644
--- a/toolbox/umount.c
+++ b/toolbox/umount.c
@@ -33,7 +33,6 @@
     char mount_path[256];
     char rest[256];
     int result = 0;
-    int path_length = strlen(path);
     
     f = fopen("/proc/mounts", "r");
     if (!f) {
diff --git a/toolbox/watchprops.c b/toolbox/watchprops.c
index bf82882..9921dbc 100644
--- a/toolbox/watchprops.c
+++ b/toolbox/watchprops.c
@@ -77,9 +77,7 @@
 
 int watchprops_main(int argc, char *argv[])
 {
-    unsigned serial = 0;
-    unsigned count = 0;
-    unsigned n;
+    unsigned serial;
     
     Hashmap *watchlist = hashmapCreate(1024, str_hash, str_equals);
     if (!watchlist)
@@ -87,7 +85,7 @@
 
     __system_property_foreach(populate_watchlist, watchlist);
 
-    for(;;) {
+    for(serial = 0;;) {
         serial = __system_property_wait_any(serial);
         __system_property_foreach(update_watchlist, watchlist);
     }