rework string pooling; disable our own (rely on compiler’s)…
• if HAVE_STRING_POOLING is set to 1 • if HAVE_STRING_POOLING is set to 2 and not GCC < 4 is used • if HAVE_STRING_POOLING is not set to 0 and LLVM or GCC >= 4 is used Closes: LP#1580348
This commit is contained in:
201
funcs.c
201
funcs.c
@ -38,7 +38,7 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.299 2016/07/24 23:11:50 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.300 2016/07/25 00:04:42 tg Exp $");
|
||||
|
||||
#if HAVE_KILLPG
|
||||
/*
|
||||
@ -73,7 +73,7 @@ bi_getn(const char *as, int *ai)
|
||||
int rv;
|
||||
|
||||
if (!(rv = getn(as, ai)))
|
||||
bi_errorf("%s: %s", as, "bad number");
|
||||
bi_errorf(Tf_sD_s, as, "bad number");
|
||||
return (rv);
|
||||
}
|
||||
|
||||
@ -94,15 +94,15 @@ c_false(const char **wp MKSH_A_UNUSED)
|
||||
* A leading * means a POSIX special builtin.
|
||||
*/
|
||||
const struct builtin mkshbuiltins[] = {
|
||||
{"*=.", c_dot},
|
||||
{Tsgdot, c_dot},
|
||||
{"*=:", c_true},
|
||||
{"[", c_test},
|
||||
{Tbracket, c_test},
|
||||
/* no =: AT&T manual wrong */
|
||||
{Talias, c_alias},
|
||||
{"*=break", c_brkcont},
|
||||
{Tgbuiltin, c_builtin},
|
||||
{"!cat", c_cat},
|
||||
{"cd", c_cd},
|
||||
{Tbcat, c_cat},
|
||||
{Tcd, c_cd},
|
||||
/* dash compatibility hack */
|
||||
{"chdir", c_cd},
|
||||
{Tcommand, c_command},
|
||||
@ -112,32 +112,32 @@ const struct builtin mkshbuiltins[] = {
|
||||
{"*=exec", c_exec},
|
||||
{"*=exit", c_exitreturn},
|
||||
{Tsgexport, c_typeset},
|
||||
{"false", c_false},
|
||||
{Tfalse, c_false},
|
||||
{"fc", c_fc},
|
||||
{"getopts", c_getopts},
|
||||
{Tgetopts, c_getopts},
|
||||
{"=global", c_typeset},
|
||||
{"jobs", c_jobs},
|
||||
{Tjobs, c_jobs},
|
||||
{"kill", c_kill},
|
||||
{"let", c_let},
|
||||
{"let]", c_let},
|
||||
{"print", c_print},
|
||||
{"pwd", c_pwd},
|
||||
{"read", c_read},
|
||||
{Tread, c_read},
|
||||
{Tsgreadonly, c_typeset},
|
||||
{"!realpath", c_realpath},
|
||||
{"rename", c_rename},
|
||||
{Trename, c_rename},
|
||||
{"*=return", c_exitreturn},
|
||||
{Tsgset, c_set},
|
||||
{"*=shift", c_shift},
|
||||
{"=source", c_dot},
|
||||
#if !defined(MKSH_UNEMPLOYED) && HAVE_GETSID
|
||||
{"suspend", c_suspend},
|
||||
{Tsuspend, c_suspend},
|
||||
#endif
|
||||
{"test", c_test},
|
||||
{"*=times", c_times},
|
||||
{"*=trap", c_trap},
|
||||
{"true", c_true},
|
||||
{T_typeset, c_typeset},
|
||||
{Ttrue, c_true},
|
||||
{Tgtypeset, c_typeset},
|
||||
{"ulimit", c_ulimit},
|
||||
{"umask", c_umask},
|
||||
{Tunalias, c_unalias},
|
||||
@ -145,8 +145,8 @@ const struct builtin mkshbuiltins[] = {
|
||||
{"=wait", c_wait},
|
||||
{"whence", c_whence},
|
||||
#ifndef MKSH_UNEMPLOYED
|
||||
{"bg", c_fgbg},
|
||||
{"fg", c_fgbg},
|
||||
{Tbg, c_fgbg},
|
||||
{Tfg, c_fgbg},
|
||||
#endif
|
||||
#ifndef MKSH_NO_CMDLINE_EDITING
|
||||
{"bind", c_bind},
|
||||
@ -255,7 +255,7 @@ c_pwd(const char **wp)
|
||||
wp += builtin_opt.optind;
|
||||
|
||||
if (wp[0]) {
|
||||
bi_errorf("too many arguments");
|
||||
bi_errorf(Ttoo_many_args);
|
||||
return (1);
|
||||
}
|
||||
p = current_wd[0] ? (physical ? allocd = do_realpath(current_wd) :
|
||||
@ -264,11 +264,11 @@ c_pwd(const char **wp)
|
||||
if (p && access(p, R_OK) < 0)
|
||||
p = NULL;
|
||||
if (!p && !(p = allocd = ksh_get_wd())) {
|
||||
bi_errorf("%s: %s", "can't determine current directory",
|
||||
bi_errorf(Tf_sD_s, "can't determine current directory",
|
||||
cstrerror(errno));
|
||||
return (1);
|
||||
}
|
||||
shprintf("%s\n", p);
|
||||
shprintf(Tf_sN, p);
|
||||
afree(allocd, ATEMP);
|
||||
return (0);
|
||||
}
|
||||
@ -367,7 +367,7 @@ c_print(const char **wp)
|
||||
break;
|
||||
case 'p':
|
||||
if ((fd = coproc_getfd(W_OK, &emsg)) < 0) {
|
||||
bi_errorf("-p: %s", emsg);
|
||||
bi_errorf(Tf_coproc, emsg);
|
||||
return (1);
|
||||
}
|
||||
break;
|
||||
@ -519,7 +519,7 @@ c_whence(const char **wp)
|
||||
int optc;
|
||||
bool pflag = false, vflag = false;
|
||||
|
||||
while ((optc = ksh_getopt(wp, &builtin_opt, "pv")) != -1)
|
||||
while ((optc = ksh_getopt(wp, &builtin_opt, Tpv)) != -1)
|
||||
switch (optc) {
|
||||
case 'p':
|
||||
pflag = true;
|
||||
@ -543,8 +543,7 @@ c_command(const char **wp)
|
||||
int optc, fcflags = FC_BI | FC_FUNC | FC_PATH | FC_WHENCE;
|
||||
bool vflag = false;
|
||||
|
||||
/* options not sorted to facilitate string pooling */
|
||||
while ((optc = ksh_getopt(wp, &builtin_opt, "Vpv")) != -1)
|
||||
while ((optc = ksh_getopt(wp, &builtin_opt, TpVv)) != -1)
|
||||
switch (optc) {
|
||||
case 'p':
|
||||
fcflags |= FC_DEFPATH;
|
||||
@ -630,7 +629,7 @@ do_whence(const char **wp, int fcflags, bool vflag, bool iscommand)
|
||||
shf_puts(tp->val.s, shl_stdout);
|
||||
} else {
|
||||
if (vflag)
|
||||
shprintf("%s not found", id);
|
||||
shprintf(Tnot_found_s, id);
|
||||
rv = 1;
|
||||
}
|
||||
break;
|
||||
@ -795,7 +794,7 @@ c_typeset(const char **wp)
|
||||
return (1);
|
||||
if (basestr) {
|
||||
if (!getn(basestr, &base)) {
|
||||
bi_errorf("%s: %s", "bad integer base", basestr);
|
||||
bi_errorf(Tf_sD_s, "bad integer base", basestr);
|
||||
return (1);
|
||||
}
|
||||
if (base < 1 || base > 36)
|
||||
@ -878,7 +877,7 @@ c_typeset(const char **wp)
|
||||
shf_putc('\n', shl_stdout);
|
||||
}
|
||||
} else if (!typeset(wp[i], fset, fclr, field, base)) {
|
||||
bi_errorf("%s: %s", wp[i], "is not an identifier");
|
||||
bi_errorf(Tf_sD_s, wp[i], Tnot_ident);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
@ -975,7 +974,7 @@ c_typeset_vardump(struct tbl *vp, uint32_t flag, int thing, bool pflag,
|
||||
/* no arguments */
|
||||
if (!thing && !flag) {
|
||||
if (any_set == 1) {
|
||||
shprintf("%s %s %s\n", Tset, "-A", vp->name);
|
||||
shprintf(Tf_s_s_sN, Tset, "-A", vp->name);
|
||||
any_set = 2;
|
||||
}
|
||||
/*
|
||||
@ -983,31 +982,31 @@ c_typeset_vardump(struct tbl *vp, uint32_t flag, int thing, bool pflag,
|
||||
* leftadj, zerofill, etc., but POSIX says must
|
||||
* be suitable for re-entry...
|
||||
*/
|
||||
shprintf("%s %s", Ttypeset, "");
|
||||
shprintf(Tf_s_s, Ttypeset, "");
|
||||
if (((vp->flag & (ARRAY | ASSOC)) == ASSOC))
|
||||
shprintf("-%c ", 'n');
|
||||
shprintf(Tf__c_, 'n');
|
||||
if ((vp->flag & INTEGER))
|
||||
shprintf("-%c ", 'i');
|
||||
shprintf(Tf__c_, 'i');
|
||||
if ((vp->flag & EXPORT))
|
||||
shprintf("-%c ", 'x');
|
||||
shprintf(Tf__c_, 'x');
|
||||
if ((vp->flag & RDONLY))
|
||||
shprintf("-%c ", 'r');
|
||||
shprintf(Tf__c_, 'r');
|
||||
if ((vp->flag & TRACE))
|
||||
shprintf("-%c ", 't');
|
||||
shprintf(Tf__c_, 't');
|
||||
if ((vp->flag & LJUST))
|
||||
shprintf("-L%d ", vp->u2.field);
|
||||
if ((vp->flag & RJUST))
|
||||
shprintf("-R%d ", vp->u2.field);
|
||||
if ((vp->flag & ZEROFIL))
|
||||
shprintf("-%c ", 'Z');
|
||||
shprintf(Tf__c_, 'Z');
|
||||
if ((vp->flag & LCASEV))
|
||||
shprintf("-%c ", 'l');
|
||||
shprintf(Tf__c_, 'l');
|
||||
if ((vp->flag & UCASEV_AL))
|
||||
shprintf("-%c ", 'u');
|
||||
shprintf(Tf__c_, 'u');
|
||||
if ((vp->flag & INT_U))
|
||||
shprintf("-%c ", 'U');
|
||||
shprintf(Tf__c_, 'U');
|
||||
} else if (pflag) {
|
||||
shprintf("%s %s", istset ? Ttypeset :
|
||||
shprintf(Tf_s_s, istset ? Ttypeset :
|
||||
(flag & EXPORT) ? Texport : Treadonly, "");
|
||||
}
|
||||
if (any_set)
|
||||
@ -1113,7 +1112,7 @@ c_alias(const char **wp)
|
||||
for (p = ktsort(t); (ap = *p++) != NULL; )
|
||||
if ((ap->flag & (ISSET|xflag)) == (ISSET|xflag)) {
|
||||
if (pflag)
|
||||
shprintf("%s ", Talias);
|
||||
shprintf(Tf_s_, Talias);
|
||||
shf_puts(ap->name, shl_stdout);
|
||||
if (prefix != '+') {
|
||||
shf_putc('=', shl_stdout);
|
||||
@ -1138,7 +1137,7 @@ c_alias(const char **wp)
|
||||
ap = ktsearch(t, alias, h);
|
||||
if (ap != NULL && (ap->flag&ISSET)) {
|
||||
if (pflag)
|
||||
shprintf("%s ", Talias);
|
||||
shprintf(Tf_s_, Talias);
|
||||
shf_puts(ap->name, shl_stdout);
|
||||
if (prefix != '+') {
|
||||
shf_putc('=', shl_stdout);
|
||||
@ -1146,8 +1145,7 @@ c_alias(const char **wp)
|
||||
}
|
||||
shf_putc('\n', shl_stdout);
|
||||
} else {
|
||||
shprintf("%s %s %s\n", alias, Talias,
|
||||
"not found");
|
||||
shprintf(Tf_s_s_sN, alias, Talias, Tnot_found);
|
||||
rv = 1;
|
||||
}
|
||||
continue;
|
||||
@ -1251,7 +1249,7 @@ c_let(const char **wp)
|
||||
|
||||
if (wp[1] == NULL)
|
||||
/* AT&T ksh does this */
|
||||
bi_errorf("no arguments");
|
||||
bi_errorf(Tno_args);
|
||||
else
|
||||
for (wp++; *wp; wp++)
|
||||
if (!evaluate(*wp, &val, KSH_RETURN_ERROR, true)) {
|
||||
@ -1302,7 +1300,7 @@ c_jobs(const char **wp)
|
||||
int
|
||||
c_fgbg(const char **wp)
|
||||
{
|
||||
bool bg = strcmp(*wp, "bg") == 0;
|
||||
bool bg = strcmp(*wp, Tbg) == 0;
|
||||
int rv = 0;
|
||||
|
||||
if (!Flag(FMONITOR)) {
|
||||
@ -1347,7 +1345,7 @@ c_kill(const char **wp)
|
||||
if ((p = wp[1]) && *p == '-' && (ksh_isdigit(p[1]) ||
|
||||
ksh_isupper(p[1]))) {
|
||||
if (!(t = gettrap(p + 1, false, false))) {
|
||||
bi_errorf("bad signal '%s'", p + 1);
|
||||
bi_errorf(Tbad_sig_s, p + 1);
|
||||
return (1);
|
||||
}
|
||||
i = (wp[2] && strcmp(wp[2], "--") == 0) ? 3 : 2;
|
||||
@ -1362,7 +1360,7 @@ c_kill(const char **wp)
|
||||
case 's':
|
||||
if (!(t = gettrap(builtin_opt.optarg,
|
||||
true, false))) {
|
||||
bi_errorf("bad signal '%s'",
|
||||
bi_errorf(Tbad_sig_s,
|
||||
builtin_opt.optarg);
|
||||
return (1);
|
||||
}
|
||||
@ -1392,9 +1390,9 @@ c_kill(const char **wp)
|
||||
n -= 128;
|
||||
#endif
|
||||
if (n > 0 && n < ksh_NSIG)
|
||||
shprintf("%s\n", sigtraps[n].name);
|
||||
shprintf(Tf_sN, sigtraps[n].name);
|
||||
else
|
||||
shprintf("%d\n", n);
|
||||
shprintf(Tf_dN, n);
|
||||
}
|
||||
} else if (Flag(FPOSIX)) {
|
||||
n = 1;
|
||||
@ -1439,12 +1437,12 @@ c_kill(const char **wp)
|
||||
if (j_kill(p, sig))
|
||||
rv = 1;
|
||||
} else if (!getn(p, &n)) {
|
||||
bi_errorf("%s: %s", p,
|
||||
bi_errorf(Tf_sD_s, p,
|
||||
"arguments must be jobs or process IDs");
|
||||
rv = 1;
|
||||
} else {
|
||||
if (mksh_kill(n, sig) < 0) {
|
||||
bi_errorf("%s: %s", p, cstrerror(errno));
|
||||
bi_errorf(Tf_sD_s, p, cstrerror(errno));
|
||||
rv = 1;
|
||||
}
|
||||
}
|
||||
@ -1476,22 +1474,22 @@ c_getopts(const char **wp)
|
||||
|
||||
opts = *wp++;
|
||||
if (!opts) {
|
||||
bi_errorf("missing %s argument", "options");
|
||||
bi_errorf(Tf_sD_s, "options", Tno_args);
|
||||
return (1);
|
||||
}
|
||||
|
||||
var = *wp++;
|
||||
if (!var) {
|
||||
bi_errorf("missing %s argument", "name");
|
||||
bi_errorf(Tf_sD_s, Tname, Tno_args);
|
||||
return (1);
|
||||
}
|
||||
if (!*var || *skip_varname(var, true)) {
|
||||
bi_errorf("%s: %s", var, "is not an identifier");
|
||||
bi_errorf(Tf_sD_s, var, Tnot_ident);
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (e->loc->next == NULL) {
|
||||
internal_warningf("%s: %s", "c_getopts", "no argv");
|
||||
internal_warningf(Tf_sD_s, Tgetopts, Tno_args);
|
||||
return (1);
|
||||
}
|
||||
/* Which arguments are we parsing... */
|
||||
@ -1636,7 +1634,7 @@ c_shift(const char **wp)
|
||||
/* nothing to do */
|
||||
return (0);
|
||||
} else if (n < 0) {
|
||||
bi_errorf("%s: %s", arg, "bad number");
|
||||
bi_errorf(Tf_sD_s, arg, "bad number");
|
||||
return (1);
|
||||
}
|
||||
if (l->argc < n) {
|
||||
@ -1676,7 +1674,7 @@ c_umask(const char **wp)
|
||||
old_umask = ~old_umask;
|
||||
p = buf;
|
||||
for (i = 0; i < 3; i++) {
|
||||
*p++ = "ugo"[i];
|
||||
*p++ = Tugo[i];
|
||||
*p++ = '=';
|
||||
for (j = 0; j < 3; j++)
|
||||
if (old_umask & (1 << (8 - (3*i + j))))
|
||||
@ -1684,7 +1682,7 @@ c_umask(const char **wp)
|
||||
*p++ = ',';
|
||||
}
|
||||
p[-1] = '\0';
|
||||
shprintf("%s\n", buf);
|
||||
shprintf(Tf_sN, buf);
|
||||
} else
|
||||
shprintf("%#3.3o\n", (unsigned int)old_umask);
|
||||
} else {
|
||||
@ -1712,7 +1710,7 @@ c_umask(const char **wp)
|
||||
new_umask = old_umask;
|
||||
positions = 0;
|
||||
while (*cp) {
|
||||
while (*cp && vstrchr("augo", *cp))
|
||||
while (*cp && vstrchr(Taugo, *cp))
|
||||
switch (*cp++) {
|
||||
case 'a':
|
||||
positions |= 0111;
|
||||
@ -1795,7 +1793,7 @@ c_dot(const char **wp)
|
||||
return (1);
|
||||
|
||||
if ((cp = wp[builtin_opt.optind]) == NULL) {
|
||||
bi_errorf("missing argument");
|
||||
bi_errorf(Tno_args);
|
||||
return (1);
|
||||
}
|
||||
file = search_path(cp, path, R_OK, &errcode);
|
||||
@ -1803,7 +1801,7 @@ c_dot(const char **wp)
|
||||
search_access(cp, R_OK) == 0)
|
||||
file = cp;
|
||||
if (!file) {
|
||||
bi_errorf("%s: %s", cp, cstrerror(errcode));
|
||||
bi_errorf(Tf_sD_s, cp, cstrerror(errcode));
|
||||
return (1);
|
||||
}
|
||||
|
||||
@ -1820,7 +1818,7 @@ c_dot(const char **wp)
|
||||
}
|
||||
if ((i = include(file, argc, argv, false)) < 0) {
|
||||
/* should not happen */
|
||||
bi_errorf("%s: %s", cp, cstrerror(errno));
|
||||
bi_errorf(Tf_sD_s, cp, cstrerror(errno));
|
||||
return (1);
|
||||
}
|
||||
return (i);
|
||||
@ -1901,7 +1899,7 @@ c_read(const char **wp)
|
||||
break;
|
||||
case 'p':
|
||||
if ((fd = coproc_getfd(R_OK, &ccp)) < 0) {
|
||||
bi_errorf("-p: %s", ccp);
|
||||
bi_errorf(Tf_coproc, ccp);
|
||||
return (2);
|
||||
}
|
||||
break;
|
||||
@ -1914,7 +1912,7 @@ c_read(const char **wp)
|
||||
#if HAVE_SELECT
|
||||
case 't':
|
||||
if (parse_usec(builtin_opt.optarg, &tv)) {
|
||||
bi_errorf("%s: %s '%s'", Tsynerr, cstrerror(errno),
|
||||
bi_errorf(Tf_sD_s_qs, Tsynerr, cstrerror(errno),
|
||||
builtin_opt.optarg);
|
||||
return (2);
|
||||
}
|
||||
@ -1925,7 +1923,7 @@ c_read(const char **wp)
|
||||
if (!builtin_opt.optarg[0])
|
||||
fd = 0;
|
||||
else if ((fd = check_fd(builtin_opt.optarg, R_OK, &ccp)) < 0) {
|
||||
bi_errorf("%s: %s: %s", "-u", builtin_opt.optarg, ccp);
|
||||
bi_errorf(Tf_sD_sD_s, "-u", builtin_opt.optarg, ccp);
|
||||
return (2);
|
||||
}
|
||||
break;
|
||||
@ -1937,7 +1935,7 @@ c_read(const char **wp)
|
||||
*--wp = REPLY;
|
||||
|
||||
if (intoarray && wp[1] != NULL) {
|
||||
bi_errorf("too many arguments");
|
||||
bi_errorf(Ttoo_many_args);
|
||||
return (2);
|
||||
}
|
||||
|
||||
@ -1997,7 +1995,7 @@ c_read(const char **wp)
|
||||
/* fake EOF read; all cases return 1 */
|
||||
goto c_read_didread;
|
||||
default:
|
||||
bi_errorf("%s: %s", Tselect, cstrerror(errno));
|
||||
bi_errorf(Tf_sD_s, Tselect, cstrerror(errno));
|
||||
rv = 2;
|
||||
goto c_read_out;
|
||||
}
|
||||
@ -2014,7 +2012,7 @@ c_read(const char **wp)
|
||||
/* pretend the read was killed */
|
||||
} else {
|
||||
/* unexpected error */
|
||||
bi_errorf("%s", cstrerror(errno));
|
||||
bi_errorf(Tf_s, cstrerror(errno));
|
||||
}
|
||||
rv = 2;
|
||||
goto c_read_out;
|
||||
@ -2116,7 +2114,7 @@ c_read(const char **wp)
|
||||
subarray = last_lookup_was_array;
|
||||
if (vp->flag & RDONLY) {
|
||||
c_read_splitro:
|
||||
bi_errorf("read-only: %s", *wp);
|
||||
bi_errorf(Tf_ro, *wp);
|
||||
c_read_spliterr:
|
||||
rv = 2;
|
||||
afree(cp, ATEMP);
|
||||
@ -2344,7 +2342,7 @@ c_trap(const char **wp)
|
||||
if (p->trap) {
|
||||
shf_puts("trap -- ", shl_stdout);
|
||||
print_value_quoted(shl_stdout, p->trap);
|
||||
shprintf(" %s\n", p->name);
|
||||
shprintf(Tf__sN, p->name);
|
||||
}
|
||||
++p;
|
||||
} while (i--);
|
||||
@ -2366,8 +2364,7 @@ c_trap(const char **wp)
|
||||
i = 0;
|
||||
while (*wp)
|
||||
if (!(p = gettrap(*wp++, true, true))) {
|
||||
warningf(true, "%s: bad signal '%s'",
|
||||
builtin_argv0, wp[-1]);
|
||||
warningf(true, Tbad_sig_ss, builtin_argv0, wp[-1]);
|
||||
i = 1;
|
||||
} else
|
||||
settrap(p, s);
|
||||
@ -2412,7 +2409,7 @@ c_exitreturn(const char **wp)
|
||||
/* NOTREACHED */
|
||||
|
||||
c_exitreturn_err:
|
||||
bi_errorf("too many arguments");
|
||||
bi_errorf(Ttoo_many_args);
|
||||
return (1);
|
||||
}
|
||||
|
||||
@ -2561,7 +2558,7 @@ c_unset(const char **wp)
|
||||
afree(cp, ATEMP);
|
||||
|
||||
if ((vp->flag&RDONLY)) {
|
||||
warningf(true, "read-only: %s", vp->name);
|
||||
warningf(true, Tf_ro, vp->name);
|
||||
rv = 1;
|
||||
} else
|
||||
unset(vp, optc);
|
||||
@ -2591,13 +2588,13 @@ c_times(const char **wp MKSH_A_UNUSED)
|
||||
|
||||
getrusage(RUSAGE_SELF, &usage);
|
||||
p_time(shl_stdout, false, usage.ru_utime.tv_sec,
|
||||
usage.ru_utime.tv_usec, 0, null, " ");
|
||||
usage.ru_utime.tv_usec, 0, null, T1space);
|
||||
p_time(shl_stdout, false, usage.ru_stime.tv_sec,
|
||||
usage.ru_stime.tv_usec, 0, null, "\n");
|
||||
|
||||
getrusage(RUSAGE_CHILDREN, &usage);
|
||||
p_time(shl_stdout, false, usage.ru_utime.tv_sec,
|
||||
usage.ru_utime.tv_usec, 0, null, " ");
|
||||
usage.ru_utime.tv_usec, 0, null, T1space);
|
||||
p_time(shl_stdout, false, usage.ru_stime.tv_sec,
|
||||
usage.ru_stime.tv_usec, 0, null, "\n");
|
||||
|
||||
@ -2656,17 +2653,17 @@ timex(struct op *t, int f, volatile int *xerrok)
|
||||
timersub(&tv1, &tv0, &tv1);
|
||||
if (tf & TF_POSIX)
|
||||
p_time(shl_out, true, tv1.tv_sec, tv1.tv_usec,
|
||||
5, "real ", "\n");
|
||||
5, Treal_sp1, "\n");
|
||||
else
|
||||
p_time(shl_out, false, tv1.tv_sec, tv1.tv_usec,
|
||||
5, null, " real ");
|
||||
5, null, Treal_sp2);
|
||||
}
|
||||
if (tf & TF_POSIX)
|
||||
p_time(shl_out, true, usrtime.tv_sec, usrtime.tv_usec,
|
||||
5, "user ", "\n");
|
||||
5, Tuser_sp1, "\n");
|
||||
else
|
||||
p_time(shl_out, false, usrtime.tv_sec, usrtime.tv_usec,
|
||||
5, null, " user ");
|
||||
5, null, Tuser_sp2);
|
||||
if (tf & TF_POSIX)
|
||||
p_time(shl_out, true, systime.tv_sec, systime.tv_usec,
|
||||
5, "sys ", "\n");
|
||||
@ -2694,11 +2691,11 @@ timex_hook(struct op *t, char **volatile *app)
|
||||
t->str[0] |= TF_POSIX;
|
||||
break;
|
||||
case '?':
|
||||
errorf("time: -%s %s", opt.optarg,
|
||||
"unknown option");
|
||||
errorf(Tf_optfoo, Ttime, Tcolsp,
|
||||
opt.optarg[0], Tunknown_option);
|
||||
case ':':
|
||||
errorf("time: -%s %s", opt.optarg,
|
||||
"requires an argument");
|
||||
errorf(Tf_optfoo, Ttime, Tcolsp,
|
||||
opt.optarg[0], Treq_arg);
|
||||
}
|
||||
/* Copy command words down over options. */
|
||||
if (opt.optind != 0) {
|
||||
@ -2788,28 +2785,28 @@ c_mknod(const char **wp)
|
||||
|
||||
majnum = strtoul(argv[2], &c, 0);
|
||||
if ((c == argv[2]) || (*c != '\0')) {
|
||||
bi_errorf("non-numeric %s %s '%s'", "device", "major", argv[2]);
|
||||
bi_errorf(Tf_nonnum, "device", "major", argv[2]);
|
||||
goto c_mknod_err;
|
||||
}
|
||||
minnum = strtoul(argv[3], &c, 0);
|
||||
if ((c == argv[3]) || (*c != '\0')) {
|
||||
bi_errorf("non-numeric %s %s '%s'", "device", "minor", argv[3]);
|
||||
bi_errorf(Tf_nonnum, "device", "minor", argv[3]);
|
||||
goto c_mknod_err;
|
||||
}
|
||||
dv = makedev(majnum, minnum);
|
||||
if ((unsigned long)(major(dv)) != majnum) {
|
||||
bi_errorf("%s %s too large: %lu", "device", "major", majnum);
|
||||
bi_errorf(Tf_toolarge, "device", "major", majnum);
|
||||
goto c_mknod_err;
|
||||
}
|
||||
if ((unsigned long)(minor(dv)) != minnum) {
|
||||
bi_errorf("%s %s too large: %lu", "device", "minor", minnum);
|
||||
bi_errorf(Tf_toolarge, "device", "minor", minnum);
|
||||
goto c_mknod_err;
|
||||
}
|
||||
if (mknod(argv[0], mode, dv))
|
||||
goto c_mknod_failed;
|
||||
} else if (mkfifo(argv[0], mode)) {
|
||||
c_mknod_failed:
|
||||
bi_errorf("%s: %s", argv[0], cstrerror(errno));
|
||||
bi_errorf(Tf_sD_s, argv[0], cstrerror(errno));
|
||||
c_mknod_err:
|
||||
rv = 1;
|
||||
}
|
||||
@ -2867,7 +2864,7 @@ c_test(const char **wp)
|
||||
for (argc = 0; wp[argc]; argc++)
|
||||
;
|
||||
|
||||
if (strcmp(wp[0], "[") == 0) {
|
||||
if (strcmp(wp[0], Tbracket) == 0) {
|
||||
if (strcmp(wp[--argc], "]") != 0) {
|
||||
bi_errorf("missing ]");
|
||||
return (T_ERR_EXIT);
|
||||
@ -3344,7 +3341,7 @@ test_primary(Test_env *te, bool do_eval)
|
||||
/* unary expression */
|
||||
opnd1 = (*te->getopnd)(te, op, do_eval);
|
||||
if (!opnd1) {
|
||||
(*te->error)(te, -1, "missing argument");
|
||||
(*te->error)(te, -1, Tno_args);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -3420,9 +3417,9 @@ ptest_error(Test_env *te, int ofs, const char *msg)
|
||||
|
||||
te->flags |= TEF_ERROR;
|
||||
if ((op = te->pos.wp + ofs >= te->wp_end ? NULL : te->pos.wp[ofs]))
|
||||
bi_errorf("%s: %s", op, msg);
|
||||
bi_errorf(Tf_sD_s, op, msg);
|
||||
else
|
||||
bi_errorf("%s", msg);
|
||||
bi_errorf(Tf_s, msg);
|
||||
}
|
||||
|
||||
#ifndef MKSH_NO_LIMITS
|
||||
@ -3550,7 +3547,7 @@ c_ulimit(const char **wp)
|
||||
found:
|
||||
if (wp[builtin_opt.optind]) {
|
||||
if (all || wp[builtin_opt.optind + 1]) {
|
||||
bi_errorf("too many arguments");
|
||||
bi_errorf(Ttoo_many_args);
|
||||
return (1);
|
||||
}
|
||||
return (set_ulimit(rlimits[i], wp[builtin_opt.optind], how));
|
||||
@ -3651,7 +3648,7 @@ c_rename(const char **wp)
|
||||
bi_errorf(Tsynerr);
|
||||
else if ((rv = rename(wp[0], wp[1])) != 0) {
|
||||
rv = errno;
|
||||
bi_errorf("%s: %s", "failed", cstrerror(rv));
|
||||
bi_errorf(Tf_sD_s, "failed", cstrerror(rv));
|
||||
}
|
||||
|
||||
return (rv);
|
||||
@ -3674,11 +3671,11 @@ c_realpath(const char **wp)
|
||||
bi_errorf(Tsynerr);
|
||||
else if ((buf = do_realpath(wp[0])) == NULL) {
|
||||
rv = errno;
|
||||
bi_errorf("%s: %s", wp[0], cstrerror(rv));
|
||||
bi_errorf(Tf_sD_s, wp[0], cstrerror(rv));
|
||||
if ((unsigned int)rv > 255)
|
||||
rv = 255;
|
||||
} else {
|
||||
shprintf("%s\n", buf);
|
||||
shprintf(Tf_sN, buf);
|
||||
afree(buf, ATEMP);
|
||||
rv = 0;
|
||||
}
|
||||
@ -3724,7 +3721,7 @@ c_cat(const char **wp)
|
||||
if (ksh_isdash(fn))
|
||||
fd = STDIN_FILENO;
|
||||
else if ((fd = binopen2(fn, O_RDONLY)) < 0) {
|
||||
bi_errorf("%s: %s", fn, cstrerror(errno));
|
||||
bi_errorf(Tf_sD_s, fn, cstrerror(errno));
|
||||
rv = 1;
|
||||
continue;
|
||||
}
|
||||
@ -3741,7 +3738,7 @@ c_cat(const char **wp)
|
||||
continue;
|
||||
}
|
||||
/* an error occured during reading */
|
||||
bi_errorf("%s: %s", fn, cstrerror(errno));
|
||||
bi_errorf(Tf_sD_s, fn, cstrerror(errno));
|
||||
rv = 1;
|
||||
break;
|
||||
} else if (n == 0)
|
||||
@ -3766,7 +3763,7 @@ c_cat(const char **wp)
|
||||
rv = ksh_sigmask(SIGPIPE);
|
||||
} else {
|
||||
/* an error occured during writing */
|
||||
bi_errorf("%s: %s", "<stdout>",
|
||||
bi_errorf(Tf_sD_s, "<stdout>",
|
||||
cstrerror(errno));
|
||||
rv = 1;
|
||||
}
|
||||
@ -3801,7 +3798,7 @@ c_sleep(const char **wp)
|
||||
if (!wp[0] || wp[1])
|
||||
bi_errorf(Tsynerr);
|
||||
else if (parse_usec(wp[0], &tv))
|
||||
bi_errorf("%s: %s '%s'", Tsynerr, cstrerror(errno), wp[0]);
|
||||
bi_errorf(Tf_sD_s_qs, Tsynerr, cstrerror(errno), wp[0]);
|
||||
else {
|
||||
#ifndef MKSH_NOPROSPECTOFWORK
|
||||
sigset_t omask, bmask;
|
||||
@ -3831,7 +3828,7 @@ c_sleep(const char **wp)
|
||||
*/
|
||||
rv = 0;
|
||||
else
|
||||
bi_errorf("%s: %s", Tselect, cstrerror(errno));
|
||||
bi_errorf(Tf_sD_s, Tselect, cstrerror(errno));
|
||||
#ifndef MKSH_NOPROSPECTOFWORK
|
||||
/* this will re-schedule signal delivery */
|
||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||
@ -3846,7 +3843,7 @@ static int
|
||||
c_suspend(const char **wp)
|
||||
{
|
||||
if (wp[1] != NULL) {
|
||||
bi_errorf("too many arguments");
|
||||
bi_errorf(Ttoo_many_args);
|
||||
return (1);
|
||||
}
|
||||
if (Flag(FLOGIN)) {
|
||||
|
Reference in New Issue
Block a user