{
#if DEBUG
if (!p || (g_stacknxt < (char *)p) || ((char *)p < g_stackp->space)) {
- write(2, "stunalloc\n", 10);
+ write(STDERR_FILENO, "stunalloc\n", 10);
abort();
}
#endif
INT_ON;
} else {
char *oldspace = g_stacknxt;
- int oldlen = g_stacknleft;
+ size_t oldlen = g_stacknleft;
char *p = stalloc(newlen);
/* free the space we just allocated */
return stackblock();
}
growstackblock();
- return stackblock() + len;
+ return (char *)stackblock() + len;
}
/*
break;
growstackblock();
}
- return stackblock() + len;
+ return (char *)stackblock() + len;
}
static char *
stack_nputstr(const char *s, size_t n, char *p)
{
p = makestrspace(n, p);
- p = memcpy(p, s, n) + n;
+ p = (char *)memcpy(p, s, n) + n;
return p;
}
q = p = makestrspace(len + 3, p);
*q++ = '\'';
- q = memcpy(q, s, len) + len;
+ q = (char *)memcpy(q, s, len) + len;
*q++ = '\'';
s += len;
q = p = makestrspace(len + 3, p);
*q++ = '"';
- q = memcpy(q, s, len) + len;
+ q = (char *)memcpy(q, s, len) + len;
*q++ = '"';
s += len;
#define vartab (G_var.vartab )
#define varinit (G_var.varinit )
#define INIT_G_var() do { \
- int i; \
+ unsigned i; \
(*(struct globals_var**)&ash_ptr_to_globals_var) = xzalloc(sizeof(G_var)); \
barrier(); \
for (i = 0; i < ARRAY_SIZE(varinit_data); i++) { \
}
INT_OFF;
nameeq = ckmalloc(namelen + vallen + 2);
- p = memcpy(nameeq, name, namelen) + namelen;
+ p = (char *)memcpy(nameeq, name, namelen) + namelen;
if (val) {
*p++ = '=';
- p = memcpy(p, val, vallen) + vallen;
+ p = (char *)memcpy(p, val, vallen) + vallen;
}
*p = '\0';
setvareq(nameeq, flags | VNOSAVE);
new = stack_putstr(curdir, new);
}
new = makestrspace(strlen(dir) + 2, new);
- lim = stackblock() + 1;
+ lim = (char *)stackblock() + 1;
if (*dir != '/') {
if (new[-1] != '/')
USTPUTC('/', new);
full_write(pip[1], redir->nhere.doc->narg.text, len);
else
expandhere(redir->nhere.doc, pip[1]);
- _exit(0);
+ _exit(EXIT_SUCCESS);
}
out:
close(pip[1]);
}
q = r;
if (len > 0) {
- q = memcpy(q, str, len) + len;
+ q = (char *)memcpy(q, str, len) + len;
}
}
inquotes = (flag & RMESCAPE_QUOTED) ^ RMESCAPE_QUOTED;
char *p;
char *dest;
int startloc;
- int syntax = quoted? DQSYNTAX : BASESYNTAX;
+ int syntax = quoted ? DQSYNTAX : BASESYNTAX;
struct stackmark smark;
INT_OFF;
char *idx, *repl = NULL;
unsigned char c;
- for (idx = arg; *arg; arg++) {
- if (*arg == '/') {
- /* Only the first '/' seen is our seperator */
+ idx = arg;
+ while (1) {
+ c = *arg;
+ if (!c)
+ break;
+ if (c == '/') {
+ /* Only the first '/' seen is our separator */
if (!repl) {
- *idx++ = '\0';
- repl = idx;
- } else
- *idx++ = *arg;
- } else if (*arg != '\\') {
- *idx++ = *arg;
- } else {
- if (inquotes)
- arg++;
- else {
- if (*(arg + 1) != '\\')
- goto single_backslash;
- arg += 2;
- }
-
- switch (*arg) {
- case 'n': c = '\n'; break;
- case 'r': c = '\r'; break;
- case 't': c = '\t'; break;
- case 'v': c = '\v'; break;
- case 'f': c = '\f'; break;
- case 'b': c = '\b'; break;
- case 'a': c = '\a'; break;
- case '\\':
- if (*(arg + 1) != '\\' && !inquotes)
- goto single_backslash;
- arg++;
- /* FALLTHROUGH */
- case '\0':
- /* Trailing backslash, just stuff one in the buffer
- * and backup arg so the loop will exit.
- */
- c = '\\';
- if (!*arg)
- arg--;
- break;
- default:
- c = *arg;
- if (isdigit(c)) {
- /* It's an octal number, parse it. */
- int i;
- c = 0;
-
- for (i = 0; *arg && i < 3; arg++, i++) {
- if (*arg >= '8' || *arg < '0')
- ash_msg_and_raise_error("Invalid octal char in pattern");
-// TODO: number() instead? It does error checking...
- c = (c << 3) + atoi(arg);
- }
- /* back off one (so outer loop can do it) */
- arg--;
- }
+ repl = idx + 1;
+ c = '\0';
}
- *idx++ = c;
}
+ *idx++ = c;
+ if (!inquotes && c == '\\' && arg[1] == '\\')
+ arg++; /* skip both \\, not just first one */
+ arg++;
}
- *idx = *arg;
+ *idx = c; /* NUL */
return repl;
-
- single_backslash:
- ash_msg_and_raise_error("single backslash unexpected");
- /* NOTREACHED */
}
#endif /* ENABLE_ASH_BASH_COMPAT */
STPUTC('\0', expdest);
herefd = saveherefd;
argbackq = saveargbackq;
- startp = stackblock() + startloc;
+ startp = (char *)stackblock() + startloc;
switch (subtype) {
case VSASSIGN:
amount = expdest - ((char *)stackblock() + resetloc);
STADJUST(-amount, expdest);
- startp = stackblock() + startloc;
+ startp = (char *)stackblock() + startloc;
rmesc = startp;
- rmescend = stackblock() + strloc;
+ rmescend = (char *)stackblock() + strloc;
if (quotes) {
rmesc = _rmescapes(startp, RMESCAPE_ALLOC | RMESCAPE_GROW);
if (rmesc != startp) {
rmescend = expdest;
- startp = stackblock() + startloc;
+ startp = (char *)stackblock() + startloc;
}
}
rmescend--;
- str = stackblock() + strloc;
+ str = (char *)stackblock() + strloc;
preglob(str, varflags & VSQUOTE, 0);
workloc = expdest - (char *)stackblock();
if (!eq) /* stop at first non-assignment */
break;
eq++;
- if (name_len == (eq - str)
+ if (name_len == (unsigned)(eq - str)
&& strncmp(str, name, name_len) == 0) {
p = eq;
/* goto value; - WRONG! */
* Apart from the above, [[ expr ]] should work as [ expr ]
*/
-#define testcmd test_main
-#define echocmd echo_main
+#define echocmd echo_main
+#define printfcmd printf_main
+#define testcmd test_main
/* Keep these in proper order since it is searched via bsearch() */
static const struct builtincmd builtintab[] = {
{ BUILTIN_SPEC_REG ".", dotcmd },
{ BUILTIN_SPEC_REG ":", truecmd },
#if ENABLE_ASH_BUILTIN_TEST
- { BUILTIN_REGULAR "[", testcmd },
+ { BUILTIN_REGULAR "[", testcmd },
#if ENABLE_ASH_BASH_COMPAT
- { BUILTIN_REGULAR "[[", testcmd },
+ { BUILTIN_REGULAR "[[", testcmd },
#endif
#endif
#if ENABLE_ASH_ALIAS
{ BUILTIN_NOSPEC "let", letcmd },
#endif
{ BUILTIN_ASSIGN "local", localcmd },
+#if ENABLE_ASH_BUILTIN_PRINTF
+ { BUILTIN_REGULAR "printf", printfcmd },
+#endif
{ BUILTIN_NOSPEC "pwd", pwdcmd },
{ BUILTIN_REGULAR "read", readcmd },
{ BUILTIN_SPEC_REG_ASSG "readonly", exportcmd },
{ BUILTIN_SPEC_REG "shift", shiftcmd },
{ BUILTIN_SPEC_REG "source", dotcmd },
#if ENABLE_ASH_BUILTIN_TEST
- { BUILTIN_REGULAR "test", testcmd },
+ { BUILTIN_REGULAR "test", testcmd },
#endif
{ BUILTIN_SPEC_REG "times", timescmd },
{ BUILTIN_SPEC_REG "trap", trapcmd },
ash_msg("illegal option %co %s", val ? '-' : '+', name);
return 1;
}
- for (i = 0; i < NOPTS; i++)
+ for (i = 0; i < NOPTS; i++) {
if (val) {
out1fmt("%-16s%s\n", optnames(i), optlist[i] ? "on" : "off");
} else {
out1fmt("set %co %s\n", optlist[i] ? '-' : '+', optnames(i));
}
+ }
return 0;
}
static void
return 1;
optnext = optfirst + *param_optind - 1;
- if (*param_optind <= 1 || *optoff < 0 || strlen(optnext[-1]) < *optoff)
+ if (*param_optind <= 1 || *optoff < 0 || (int)strlen(optnext[-1]) < *optoff)
p = NULL;
else
p = optnext[-1] + *optoff;
#if ENABLE_ASH_MATH_SUPPORT
PARSEARITH();
#else
- raise_error_syntax("We unsupport $((arith))");
+ raise_error_syntax("you disabled math support for $((arith)) syntax");
#endif
} else {
pungetc();
return readtoken1(c, BASESYNTAX, (char *) NULL, 0);
}
- if (p - xxreadtoken_chars >= xxreadtoken_singles) {
+ if ((size_t)(p - xxreadtoken_chars) >= xxreadtoken_singles) {
if (pgetc() == *p) { /* double occurrence? */
p += xxreadtoken_doubles + 1;
} else {
static int
helpcmd(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
{
- int col, i;
+ unsigned col;
+ unsigned i;
out1fmt("\nBuilt-in commands:\n-------------------\n");
for (col = 0, i = 0; i < ARRAY_SIZE(builtintab); i++) {
while ((c = *p++) >= '0' && c <= '9') {
val = (val * 10) + (long)(c - '0');
+ // val is actually 'unsigned long int' and can't get < 0
if (val < (rlim_t) 0)
break;
}