preparatory patch for -Wwrite-strings #1
diff --git a/applets/applets.c b/applets/applets.c
index a974743..8a17cbf 100644
--- a/applets/applets.c
+++ b/applets/applets.c
@@ -106,7 +106,7 @@
 }
 
 
-#define parse_error(x)  { err=x; goto pe_label; }
+#define parse_error(x)  do { errmsg = x; goto pe_label; } while(0)
 
 /* Don't depend on the tools to combine strings. */
 static const char config_file[] = CONFIG_FILE;
@@ -130,7 +130,7 @@
 	struct BB_suid_config *sct;
 	struct BB_applet *applet;
 	FILE *f;
-	char *err;
+	const char *errmsg;
 	char *s;
 	char *e;
 	int i, lc, section;
@@ -307,7 +307,7 @@
 
  pe_label:
 	fprintf(stderr, "Parse error in %s, line %d: %s\n",
-			config_file, lc, err);
+			config_file, lc, errmsg);
 
 	fclose(f);
 	/* Release any allocated memory before returning. */
diff --git a/archival/tar.c b/archival/tar.c
index ca59643..6c15f65 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -504,7 +504,7 @@
 		int gzipDataPipe[2] = { -1, -1 };
 		int gzipStatusPipe[2] = { -1, -1 };
 		volatile int vfork_exec_errno = 0;
-		char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
+		const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
 
 		if (pipe(gzipDataPipe) < 0 || pipe(gzipStatusPipe) < 0)
 			bb_perror_msg_and_die("pipe");
diff --git a/coreutils/cat.c b/coreutils/cat.c
index 2b7c603..7a34891 100644
--- a/coreutils/cat.c
+++ b/coreutils/cat.c
@@ -14,7 +14,7 @@
 
 int bb_cat(char **argv)
 {
-	static char *const argv_dash[] = { "-", NULL };
+	static const char *const argv_dash[] = { "-", NULL };
 	FILE *f;
 	int retval = EXIT_SUCCESS;
 
diff --git a/coreutils/date.c b/coreutils/date.c
index a6690e8..034a18b 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -41,7 +41,7 @@
 static void maybe_set_utc(int opt)
 {
 	if (opt & DATE_OPT_UTC)
-		xputenv("TZ=UTC0");
+		xputenv((char*)"TZ=UTC0");
 }
 
 int date_main(int argc, char **argv)
@@ -218,7 +218,7 @@
 			i = 22;
 			goto format_utc;
 		} else /* default case */
-			date_fmt = "%a %b %e %H:%M:%S %Z %Y";
+			date_fmt = (char*)"%a %b %e %H:%M:%S %Z %Y";
 	}
 
 	if (*date_fmt == '\0') {
@@ -228,7 +228,7 @@
 		/* Handle special conversions */
 
 		if (strncmp(date_fmt, "%f", 2) == 0) {
-			date_fmt = "%Y.%m.%d-%H:%M:%S";
+			date_fmt = (char*)"%Y.%m.%d-%H:%M:%S";
 		}
 
 		/* Generate output string */
diff --git a/coreutils/du.c b/coreutils/du.c
index a1ca5b5..a4b3c81 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -222,7 +222,7 @@
 	/* go through remaining args (if any) */
 	argv += optind;
 	if (optind >= argc) {
-		*--argv = ".";
+		*--argv = (char*)".";
 		if (slink_depth == 1) {
 			slink_depth = 0;
 		}
diff --git a/coreutils/expr.c b/coreutils/expr.c
index 51e553d..469d467 100644
--- a/coreutils/expr.c
+++ b/coreutils/expr.c
@@ -67,8 +67,8 @@
 static VALUE *docolon(VALUE * sv, VALUE * pv);
 static VALUE *eval(void);
 static VALUE *int_value(arith_t i);
-static VALUE *str_value(char *s);
-static int nextarg(char *str);
+static VALUE *str_value(const char *s);
+static int nextarg(const char *str);
 static int null(VALUE * v);
 static int toarith(VALUE * v);
 static void freev(VALUE * v);
@@ -110,7 +110,7 @@
 
 /* Return a VALUE for S.  */
 
-static VALUE *str_value(char *s)
+static VALUE *str_value(const char *s)
 {
 	VALUE *v;
 
@@ -172,7 +172,7 @@
 /* Return nonzero if the next token matches STR exactly.
    STR must not be NULL.  */
 
-static int nextarg(char *str)
+static int nextarg(const char *str)
 {
 	if (*args == NULL)
 		return 0;
diff --git a/coreutils/fold.c b/coreutils/fold.c
index fd72981..490882f 100644
--- a/coreutils/fold.c
+++ b/coreutils/fold.c
@@ -66,7 +66,7 @@
 
 	argv += optind;
 	if (!*argv) {
-		*--argv = "-";
+		*--argv = (char*)"-";
 	}
 
 	do {
diff --git a/coreutils/head.c b/coreutils/head.c
index 56e7a96..59b4d55 100644
--- a/coreutils/head.c
+++ b/coreutils/head.c
@@ -92,7 +92,7 @@
 
 	argv += optind;
 	if (!*argv) {
-		*--argv = "-";
+		*--argv = (char*)"-";
 	}
 
 	fmt = header_fmt_str + 1;
diff --git a/coreutils/ln.c b/coreutils/ln.c
index 231a3bf..a307e55 100644
--- a/coreutils/ln.c
+++ b/coreutils/ln.c
@@ -26,7 +26,7 @@
 	char *last;
 	char *src_name;
 	char *src;
-	char *suffix = "~";
+	char *suffix = (char*)"~";
 	struct stat statbuf;
 	int (*link_func)(const char *, const char *);
 
diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c
index 014ecef..d945ce7 100644
--- a/coreutils/md5_sha1_sum.c
+++ b/coreutils/md5_sha1_sum.c
@@ -102,7 +102,7 @@
 	}
 
 	if (argc == optind) {
-		argv[argc++] = "-";
+		argv[argc++] = (char*)"-";
 	}
 
 	if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && (flags & FLAG_CHECK)) {
diff --git a/coreutils/printf.c b/coreutils/printf.c
index 0e81835..924499b 100644
--- a/coreutils/printf.c
+++ b/coreutils/printf.c
@@ -42,11 +42,11 @@
 
 static int print_formatted(char *format, int argc, char **argv);
 static void print_direc(char *start, size_t length,
-			int field_width, int precision, char *argument);
+		int field_width, int precision, const char *argument);
 
-typedef void (*converter)(char *arg, void *result);
+typedef void (*converter)(const char *arg, void *result);
 
-static void multiconvert(char *arg, void *result, converter convert)
+static void multiconvert(const char *arg, void *result, converter convert)
 {
 	char s[16];
 	if (*arg == '"' || *arg == '\'') {
@@ -58,15 +58,15 @@
 		fputs(arg, stderr);
 }
 
-static void conv_strtoul(char *arg, void *result)
+static void conv_strtoul(const char *arg, void *result)
 {
 	*(unsigned long*)result = bb_strtoul(arg, NULL, 10);
 }
-static void conv_strtol(char *arg, void *result)
+static void conv_strtol(const char *arg, void *result)
 {
 	*(long*)result = bb_strtol(arg, NULL, 10);
 }
-static void conv_strtod(char *arg, void *result)
+static void conv_strtod(const char *arg, void *result)
 {
 	char *end;
 	/* Well, this one allows leading whitespace... so what */
@@ -75,21 +75,21 @@
 	if (end[0]) errno = ERANGE;
 }
 
-static unsigned long my_xstrtoul(char *arg)
+static unsigned long my_xstrtoul(const char *arg)
 {
 	unsigned long result;
 	multiconvert(arg, &result, conv_strtoul);
 	return result;
 }
 
-static long my_xstrtol(char *arg)
+static long my_xstrtol(const char *arg)
 {
 	long result;
 	multiconvert(arg, &result, conv_strtol);
 	return result;
 }
 
-static double my_xstrtod(char *arg)
+static double my_xstrtod(const char *arg)
 {
 	double result;
 	multiconvert(arg, &result, conv_strtod);
@@ -239,7 +239,7 @@
 
 static void
 print_direc(char *start, size_t length, int field_width, int precision,
-			char *argument)
+		const char *argument)
 {
 	char *p;		/* Null-terminated copy of % directive. */
 
diff --git a/coreutils/tail.c b/coreutils/tail.c
index f1ba04e..2a16453 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -91,7 +91,7 @@
 	if (argc >= 2 && (argv[1][0] == '+' || argv[1][0] == '-')
 	 && isdigit(argv[1][1])
 	) {
-		argv[0] = "-n";
+		argv[0] = (char*)"-n";
 		argv--;
 		argc++;
 	}
diff --git a/coreutils/yes.c b/coreutils/yes.c
index 894506a..fc6e611 100644
--- a/coreutils/yes.c
+++ b/coreutils/yes.c
@@ -22,7 +22,7 @@
 	const char *fmt;
 	char **first_arg;
 
-	*argv = "y";
+	*argv = (char*)"y";
 	if (argc != 1) {
 		++argv;
 	}
diff --git a/editors/awk.c b/editors/awk.c
index d6dcd95..ae7ca23 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -47,7 +47,7 @@
 typedef struct chain_s {
 	struct node_s *first;
 	struct node_s *last;
-	char *programname;
+	const char *programname;
 } chain;
 
 /* Function */
@@ -399,7 +399,7 @@
 static node *break_ptr, *continue_ptr;
 static rstream *iF;
 static xhash *vhash, *ahash, *fdhash, *fnhash;
-static char *programname;
+static const char *programname;
 static short lineno;
 static int is_f0_split;
 static int nfields;
@@ -703,7 +703,7 @@
 	return v;
 }
 
-static char *getvar_s(var *v)
+static const char *getvar_s(var *v)
 {
 	/* if v is numeric and has no cached string, convert it to string */
 	if ((v->type & (VF_NUMBER | VF_CACHED)) == VF_NUMBER) {
@@ -995,7 +995,7 @@
 	return n;
 }
 
-static node *mk_re_node(char *s, node *n, regex_t *re)
+static node *mk_re_node(const char *s, node *n, regex_t *re)
 {
 	n->info = OC_REGEXP;
 	n->l.re = re;
@@ -1347,7 +1347,7 @@
 
 /* -------- program execution part -------- */
 
-static node *mk_splitter(char *s, tsplitter *spl)
+static node *mk_splitter(const char *s, tsplitter *spl)
 {
 	regex_t *re, *ire;
 	node *n;
@@ -1375,7 +1375,7 @@
 static regex_t *as_regex(node *op, regex_t *preg)
 {
 	var *v;
-	char *s;
+	const char *s;
 
 	if ((op->info & OPCLSMASK) == OC_REGEXP) {
 		return icase ? op->r.ire : op->l.re;
@@ -1419,7 +1419,7 @@
 	nfields = size;
 }
 
-static int awk_split(char *s, node *spl, char **slist)
+static int awk_split(const char *s, node *spl, char **slist)
 {
 	int l, n = 0;
 	char c[4];
@@ -1427,7 +1427,8 @@
 	regmatch_t pmatch[2];
 
 	/* in worst case, each char would be a separate field */
-	*slist = s1 = xstrndup(s, strlen(s) * 2 + 3);
+	*slist = s1 = xzalloc(strlen(s) * 2 + 3);
+	strcpy(s1, s);
 
 	c[0] = c[1] = (char)spl->info;
 	c[2] = c[3] = '\0';
@@ -1436,8 +1437,9 @@
 	if ((spl->info & OPCLSMASK) == OC_REGEXP) {		/* regex split */
 		while (*s) {
 			l = strcspn(s, c+2);
-			if (regexec(icase ? spl->r.ire : spl->l.re, s, 1, pmatch, 0) == 0 &&
-			pmatch[0].rm_so <= l) {
+			if (regexec(icase ? spl->r.ire : spl->l.re, s, 1, pmatch, 0) == 0
+			 && pmatch[0].rm_so <= l
+			) {
 				l = pmatch[0].rm_so;
 				if (pmatch[0].rm_eo == 0) { l++; pmatch[0].rm_eo++; }
 			} else {
@@ -1510,7 +1512,8 @@
 static void handle_special(var *v)
 {
 	int n;
-	char *b, *sep, *s;
+	char *b;
+	const char *sep, *s;
 	int sl, l, len, i, bsize;
 
 	if (!(v->type & VF_SPECIAL))
@@ -1737,7 +1740,8 @@
 static char *awk_printf(node *n)
 {
 	char *b = NULL;
-	char *fmt, *s, *s1, *f;
+	char *fmt, *s, *f;
+	const char *s1;
 	int i, j, incr, bsize;
 	char c, c1;
 	var *v, *arg;
@@ -1793,10 +1797,11 @@
  * all matches. If src or dst is NULL, use $0. If ex=TRUE, enable
  * subexpression matching (\1-\9)
  */
-static int awk_sub(node *rn, char *repl, int nm, var *src, var *dest, int ex)
+static int awk_sub(node *rn, const char *repl, int nm, var *src, var *dest, int ex)
 {
 	char *ds = NULL;
-	char *sp, *s;
+	const char *s;
+	const char *sp;
 	int c, i, j, di, rl, so, eo, nbs, n, dssize;
 	regmatch_t pmatch[10];
 	regex_t sreg, *re;
@@ -1865,7 +1870,7 @@
 	var *tv;
 	node *an[4];
 	var  *av[4];
-	char *as[4];
+	const char *as[4];
 	regmatch_t pmatch[2];
 	regex_t sreg, *re;
 	static tsplitter tspl;
@@ -1998,8 +2003,10 @@
 			tt = getvar_i(av[1]);
 		else
 			time(&tt);
-		s = (nargs > 0) ? as[0] : "%a %b %d %H:%M:%S %Z %Y";
-		i = strftime(buf, MAXVARFMT, s, localtime(&tt));
+		//s = (nargs > 0) ? as[0] : "%a %b %d %H:%M:%S %Z %Y";
+		i = strftime(buf, MAXVARFMT,
+			((nargs > 0) ? as[0] : "%a %b %d %H:%M:%S %Z %Y"),
+			localtime(&tt));
 		buf[i] = '\0';
 		setvar_s(res, buf);
 		break;
@@ -2054,7 +2061,7 @@
 	var *v1;
 	union {
 		var *v;
-		char *s;
+		const char *s;
 		double d;
 		int i;
 	} L, R;
@@ -2168,7 +2175,7 @@
 			} else {	/* OC_PRINTF */
 				L.s = awk_printf(op1);
 				fputs(L.s, X.F);
-				free(L.s);
+				free((char*)L.s);
 			}
 			fflush(X.F);
 			break;
@@ -2610,7 +2617,7 @@
 {
 	static rstream rsm;
 	FILE *F = NULL;
-	char *fname, *ind;
+	const char *fname, *ind;
 	static int files_happen = FALSE;
 
 	if (rsm.F) fclose(rsm.F);
diff --git a/editors/ed.c b/editors/ed.c
index 3aca759..5a48fbe 100644
--- a/editors/ed.c
+++ b/editors/ed.c
@@ -401,7 +401,7 @@
 	if (cp)
 		*cp++ = '\0';
 	else
-		cp = "";
+		cp = (char*)"";
 
 	while (*cp) switch (*cp++) {
 		case 'g':
diff --git a/include/libbb.h b/include/libbb.h
index 540170c..6f195cf 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -239,7 +239,7 @@
 	void* userData, int depth);
 extern int device_open(const char *device, int mode);
 extern int get_console_fd(void);
-extern char *find_block_device(char *path);
+extern char *find_block_device(const char *path);
 /* bb_copyfd_XX print read/write errors and return -1 if they occur */
 extern off_t bb_copyfd_eof(int fd1, int fd2);
 extern off_t bb_copyfd_size(int fd1, int fd2, off_t size);
diff --git a/libbb/find_root_device.c b/libbb/find_root_device.c
index 1d74d1e..ea360ea 100644
--- a/libbb/find_root_device.c
+++ b/libbb/find_root_device.c
@@ -9,7 +9,7 @@
 
 #include "libbb.h"
 
-char *find_block_device(char *path)
+char *find_block_device(const char *path)
 {
 	DIR *dir;
 	struct dirent *entry;