}
-#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;
struct BB_suid_config *sct;
struct BB_applet *applet;
FILE *f;
- char *err;
+ const char *errmsg;
char *s;
char *e;
int i, lc, section;
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. */
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");
int bb_cat(char **argv)
{
- static char *const argv_dash[] = { "-", NULL };
+ static const char *const argv_dash[] = { "-", NULL };
FILE *f;
int retval = EXIT_SUCCESS;
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)
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') {
/* 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 */
/* go through remaining args (if any) */
argv += optind;
if (optind >= argc) {
- *--argv = ".";
+ *--argv = (char*)".";
if (slink_depth == 1) {
slink_depth = 0;
}
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);
/* Return a VALUE for S. */
-static VALUE *str_value(char *s)
+static VALUE *str_value(const char *s)
{
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;
argv += optind;
if (!*argv) {
- *--argv = "-";
+ *--argv = (char*)"-";
}
do {
argv += optind;
if (!*argv) {
- *--argv = "-";
+ *--argv = (char*)"-";
}
fmt = header_fmt_str + 1;
char *last;
char *src_name;
char *src;
- char *suffix = "~";
+ char *suffix = (char*)"~";
struct stat statbuf;
int (*link_func)(const char *, const char *);
}
if (argc == optind) {
- argv[argc++] = "-";
+ argv[argc++] = (char*)"-";
}
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && (flags & FLAG_CHECK)) {
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 == '\'') {
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 */
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);
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. */
if (argc >= 2 && (argv[1][0] == '+' || argv[1][0] == '-')
&& isdigit(argv[1][1])
) {
- argv[0] = "-n";
+ argv[0] = (char*)"-n";
argv--;
argc++;
}
const char *fmt;
char **first_arg;
- *argv = "y";
+ *argv = (char*)"y";
if (argc != 1) {
++argv;
}
typedef struct chain_s {
struct node_s *first;
struct node_s *last;
- char *programname;
+ const char *programname;
} chain;
/* Function */
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;
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) {
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;
/* -------- 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;
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;
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];
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';
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 {
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))
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;
* 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;
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;
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;
var *v1;
union {
var *v;
- char *s;
+ const char *s;
double d;
int i;
} L, R;
} else { /* OC_PRINTF */
L.s = awk_printf(op1);
fputs(L.s, X.F);
- free(L.s);
+ free((char*)L.s);
}
fflush(X.F);
break;
{
static rstream rsm;
FILE *F = NULL;
- char *fname, *ind;
+ const char *fname, *ind;
static int files_happen = FALSE;
if (rsm.F) fclose(rsm.F);
if (cp)
*cp++ = '\0';
else
- cp = "";
+ cp = (char*)"";
while (*cp) switch (*cp++) {
case 'g':
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);
#include "libbb.h"
-char *find_block_device(char *path)
+char *find_block_device(const char *path)
{
DIR *dir;
struct dirent *entry;