summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-01-29 22:51:00 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-01-29 22:51:00 +0000
commita41fdf331af344ecd3ec230a072857ea197e1890 (patch)
tree70ffff0b7f48b35a70b8b04253abe9118ded6026
parente935602ff5d5a45be56585b8bad44194c3e837a3 (diff)
downloadbusybox-a41fdf331af344ecd3ec230a072857ea197e1890.tar.gz
preparatory patch for -Wwrite-strings #1
-rw-r--r--applets/applets.c6
-rw-r--r--archival/tar.c2
-rw-r--r--coreutils/cat.c2
-rw-r--r--coreutils/date.c6
-rw-r--r--coreutils/du.c2
-rw-r--r--coreutils/expr.c8
-rw-r--r--coreutils/fold.c2
-rw-r--r--coreutils/head.c2
-rw-r--r--coreutils/ln.c2
-rw-r--r--coreutils/md5_sha1_sum.c2
-rw-r--r--coreutils/printf.c20
-rw-r--r--coreutils/tail.c2
-rw-r--r--coreutils/yes.c2
-rw-r--r--editors/awk.c47
-rw-r--r--editors/ed.c2
-rw-r--r--include/libbb.h2
-rw-r--r--libbb/find_root_device.c2
17 files changed, 59 insertions, 52 deletions
diff --git a/applets/applets.c b/applets/applets.c
index a974743da..8a17cbf0b 100644
--- a/applets/applets.c
+++ b/applets/applets.c
@@ -106,7 +106,7 @@ static char *get_trimmed_slice(char *s, char *e)
}
-#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 @@ static void parse_config_file(void)
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 @@ static void parse_config_file(void)
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 ca59643e5..6c15f65c9 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -504,7 +504,7 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
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 2b7c6035f..7a34891e8 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 a6690e8bd..034a18b98 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -41,7 +41,7 @@ static void xputenv(char *s)
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 @@ format_utc:
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 @@ format_utc:
/* 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 a1ca5b59b..a4b3c817e 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -222,7 +222,7 @@ int du_main(int argc, char **argv)
/* 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 51e553dc6..469d467bf 100644
--- a/coreutils/expr.c
+++ b/coreutils/expr.c
@@ -67,8 +67,8 @@ static char **args;
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 @@ static VALUE *int_value(arith_t i)
/* Return a VALUE for S. */
-static VALUE *str_value(char *s)
+static VALUE *str_value(const char *s)
{
VALUE *v;
@@ -172,7 +172,7 @@ static int toarith(VALUE * v)
/* 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 fd7298169..490882f6d 100644
--- a/coreutils/fold.c
+++ b/coreutils/fold.c
@@ -66,7 +66,7 @@ int fold_main(int argc, char **argv)
argv += optind;
if (!*argv) {
- *--argv = "-";
+ *--argv = (char*)"-";
}
do {
diff --git a/coreutils/head.c b/coreutils/head.c
index 56e7a960c..59b4d552c 100644
--- a/coreutils/head.c
+++ b/coreutils/head.c
@@ -92,7 +92,7 @@ int head_main(int argc, char **argv)
argv += optind;
if (!*argv) {
- *--argv = "-";
+ *--argv = (char*)"-";
}
fmt = header_fmt_str + 1;
diff --git a/coreutils/ln.c b/coreutils/ln.c
index 231a3bf03..a307e5579 100644
--- a/coreutils/ln.c
+++ b/coreutils/ln.c
@@ -26,7 +26,7 @@ int ln_main(int argc, char **argv)
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 014ecefd0..d945ce7e0 100644
--- a/coreutils/md5_sha1_sum.c
+++ b/coreutils/md5_sha1_sum.c
@@ -102,7 +102,7 @@ int md5_sha1_sum_main(int argc, char **argv)
}
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 0e818354f..924499b29 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 @@ static void multiconvert(char *arg, void *result, converter convert)
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 @@ static void conv_strtod(char *arg, void *result)
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 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)
+ const char *argument)
{
char *p; /* Null-terminated copy of % directive. */
diff --git a/coreutils/tail.c b/coreutils/tail.c
index f1ba04ec6..2a1645309 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -91,7 +91,7 @@ int tail_main(int argc, char **argv)
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 894506a89..fc6e611e6 100644
--- a/coreutils/yes.c
+++ b/coreutils/yes.c
@@ -22,7 +22,7 @@ int yes_main(int argc, char **argv)
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 d6dcd9578..ae7ca23d4 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -47,7 +47,7 @@ typedef struct var_s {
typedef struct chain_s {
struct node_s *first;
struct node_s *last;
- char *programname;
+ const char *programname;
} chain;
/* Function */
@@ -399,7 +399,7 @@ static int nextrec, nextfile;
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 @@ static var *setvar_i(var *v, double value)
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 @@ static node *new_node(uint32_t info)
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 @@ static void parse_program(char *p)
/* -------- 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 node *mk_splitter(char *s, tsplitter *spl)
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 @@ static void fsrealloc(int size)
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 @@ static int awk_split(char *s, node *spl, char **slist)
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 @@ static int awk_split(char *s, node *spl, char **slist)
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 split_f0(void)
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 int fmt_num(char *b, int size, const char *format, double n, int int_as_i
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 @@ static char *awk_printf(node *n)
* 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 @@ static var *exec_builtin(node *op, var *res)
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 @@ static var *exec_builtin(node *op, var *res)
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 @@ static var *evaluate(node *op, var *res)
var *v1;
union {
var *v;
- char *s;
+ const char *s;
double d;
int i;
} L, R;
@@ -2168,7 +2175,7 @@ static var *evaluate(node *op, var *res)
} 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 *next_input_file(void)
{
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 3aca75912..5a48fbe75 100644
--- a/editors/ed.c
+++ b/editors/ed.c
@@ -401,7 +401,7 @@ static void subCommand(const char * cmd, int num1, int num2)
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 540170cdd..6f195cf46 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -239,7 +239,7 @@ extern int recursive_action(const char *fileName, int recurse,
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 1d74d1ea8..ea360eae5 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;