ok, icc _did_ track down a few ones, and I fixed errno abuse a little too

however, bad S/N ratio

side effect bonus: smaller code size now
This commit is contained in:
tg 2007-06-06 23:28:17 +00:00
parent ffd63798f3
commit 3dcf22a319
13 changed files with 98 additions and 111 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.110 2007/06/05 19:48:46 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.111 2007/06/06 23:28:12 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -7,7 +7,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout:
@(#)MIRBSD KSH R29 2007/06/05
@(#)MIRBSD KSH R29 2007/06/06
description:
Check version of shell.
category: pdksh

66
edit.c
View File

@ -5,7 +5,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.100 2007/06/06 22:26:26 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.101 2007/06/06 23:28:13 tg Exp $");
/* tty driver characters we are interested in */
typedef struct {
@ -25,21 +25,20 @@ X_chars edchars;
#define XCF_FULLPATH BIT(2) /* command completion: store full path */
#define XCF_COMMAND_FILE (XCF_COMMAND|XCF_FILE)
int x_getc(void);
void x_flush(void);
void x_putc(int);
void x_puts(const u_char *);
bool x_mode(bool);
int x_do_comment(char *, int, int *);
void x_print_expansions(int, char *const *, int);
int x_cf_glob(int, const char *, int, int, int *, int *, char ***, int *);
int x_longest_prefix(int, char *const *);
int x_basename(const char *, const char *);
void x_free_words(int, char **);
int x_escape(const char *, size_t, int (*)(const char *, size_t));
int x_emacs(char *, size_t);
void x_init_emacs(void);
int x_vi(char *, size_t);
static int x_getc(void);
static void x_flush(void);
static void x_putc(int);
static bool x_mode(bool);
static int x_do_comment(char *, int, int *);
static void x_print_expansions(int, char *const *, int);
static int x_cf_glob(int, const char *, int, int, int *, int *, char ***, int *);
static int x_longest_prefix(int, char *const *);
static int x_basename(const char *, const char *);
static void x_free_words(int, char **);
static int x_escape(const char *, size_t, int (*)(const char *, size_t));
static int x_emacs(char *, size_t);
static void x_init_emacs(void);
static int x_vi(char *, size_t);
#ifdef TIOCGWINSZ
static void chkwinsz(void);
@ -121,7 +120,7 @@ x_read(char *buf, size_t len)
/* tty I/O */
int
static int
x_getc(void)
{
char c;
@ -136,25 +135,18 @@ x_getc(void)
return ((n == 1) ? (int)(unsigned char)c : -1);
}
void
static void
x_flush(void)
{
shf_flush(shl_out);
}
void
static void
x_putc(int c)
{
shf_putc(c, shl_out);
}
void
x_puts(const u_char *s)
{
while (*s != 0)
shf_putc(*s++, shl_out);
}
/* ------------------------------------------------------------------------- */
/* Misc common code for vi/emacs */
@ -166,7 +158,7 @@ x_puts(const u_char *s)
* If successful, *lenp contains the new length. Note: cursor should be
* moved to the start of the line after (un)commenting.
*/
int
static int
x_do_comment(char *buf, int bsize, int *lenp)
{
int i, j;
@ -211,7 +203,7 @@ x_do_comment(char *buf, int bsize, int *lenp)
/* Common file/command completion code for vi/emacs */
void
static void
x_print_expansions(int nwords, char * const *words, int is_command)
{
int use_copy = 0;
@ -500,7 +492,7 @@ x_locate_word(const char *buf, int buflen, int pos, int *startp,
return end - start;
}
int
static int
x_cf_glob(int flags, const char *buf, int buflen, int pos, int *startp,
int *endp, char ***wordsp, int *is_commandp)
{
@ -574,7 +566,7 @@ add_glob(const char *str, int slen)
/*
* Find longest common prefix
*/
int
static int
x_longest_prefix(int nwords, char * const * words)
{
int i, j;
@ -594,7 +586,7 @@ x_longest_prefix(int nwords, char * const * words)
return prefix_len;
}
void
static void
x_free_words(int nwords, char **words)
{
int i;
@ -616,7 +608,7 @@ x_free_words(int nwords, char **words)
* /// 2
* 0
*/
int
static int
x_basename(const char *s, const char *se)
{
const char *p;
@ -723,7 +715,7 @@ glob_path(int flags, const char *pat, XPtrV *wp, const char *lpath)
* be escaped and the result will be put into edit buffer by
* keybinding-specific function
*/
int
static int
x_escape(const char *s, size_t len, int (*putbuf_func)(const char *, size_t))
{
size_t add, wlen;
@ -1431,7 +1423,7 @@ x_e_getmbc(char *sbuf)
return (pos);
}
int
static int
x_emacs(char *buf, size_t len)
{
int c, i;
@ -2641,7 +2633,7 @@ x_bind(const char *a1, const char *a2,
return (0);
}
void
static void
x_init_emacs(void)
{
int i, j;
@ -3255,7 +3247,7 @@ x_lastcp(void)
return (xlp);
}
bool
static bool
x_mode(bool onoff)
{
static bool x_cur_mode;
@ -3499,7 +3491,7 @@ enum expand_mode {
};
static enum expand_mode expanded = NONE; /* last input was expanded */
int
static int
x_vi(char *buf, size_t len)
{
int c;

9
eval.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.27 2007/05/13 19:14:04 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.28 2007/06/06 23:28:14 tg Exp $");
#ifdef MKSH_SMALL
#define MKSH_NOPWNAM
@ -712,17 +712,14 @@ varsub(Expand *xp, const char *sp, const char *word,
if ((p = cstrchr(sp, '[')) && (p[1] == '*' || p[1] == '@') &&
p[2] == ']') {
int n = 0;
int max = 0;
vp = global(arrayname(sp));
if (vp->flag & (ISSET|ARRAY))
zero_ok = 1;
for (; vp; vp = vp->u.array)
if (vp->flag & ISSET) {
max = vp->index + 1;
if (vp->flag & ISSET)
n++;
}
c = n; /* ksh88/ksh93 go for number, not max index */
c = n;
} else if (c == '*' || c == '@')
c = e->loc->argc;
else {

37
exec.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.31 2007/05/13 18:49:00 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.32 2007/06/06 23:28:14 tg Exp $");
static int comexec(struct op *, struct tbl *volatile, const char **,
int volatile);
@ -348,11 +348,12 @@ execute(struct op *volatile t,
cargs.ro = t->args;
execve(t->str, cargs.rw, up);
rv = errno;
}
if (errno == ENOEXEC)
if (rv == ENOEXEC)
scriptexec(t, (const char **)up);
else
errorf("%s: %s", s, strerror(errno));
errorf("%s: %s", s, strerror(rv));
}
Break:
exstat = rv;
@ -514,7 +515,7 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap,
case CFUNC: /* function call */
{
volatile int old_xflag;
volatile char old_xflag;
volatile Tflag old_inuse;
const char *volatile old_kshname;
@ -537,9 +538,10 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap,
break;
}
if (include(tp->u.fpath, 0, NULL, 0) < 0) {
rv = errno;
warningf(true,
"%s: can't open function definition file %s - %s",
cp, tp->u.fpath, strerror(errno));
cp, tp->u.fpath, strerror(rv));
rv = 127;
break;
}
@ -576,7 +578,7 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap,
}
old_xflag = Flag(FXTRACE);
Flag(FXTRACE) = tp->flag & TRACE ? true : false;
Flag(FXTRACE) = tp->flag & TRACE ? 1 : 0;
old_inuse = tp->flag & FINUSE;
tp->flag |= FINUSE;
@ -1137,11 +1139,13 @@ iosetup(struct ioword *iop, struct tbl *tp)
}
if (u < 0) {
/* herein() may already have printed message */
if (u == -1)
if (u == -1) {
u = errno;
warningf(true, "cannot %s %s: %s",
iotype == IODUP ? "dup" :
(iotype == IOREAD || iotype == IOHERE) ?
"open" : "create", cp, strerror(errno));
"open" : "create", cp, strerror(u));
}
return -1;
}
/* Do not save if it has already been redirected (i.e. "cat >x >y"). */
@ -1163,10 +1167,13 @@ iosetup(struct ioword *iop, struct tbl *tp)
close(iop->unit);
else if (u != iop->unit) {
if (ksh_dup2(u, iop->unit, true) < 0) {
int ev;
ev = errno;
warningf(true,
"could not finish (dup) redirection %s: %s",
snptreef(NULL, 32, "%R", &iotmp),
strerror(errno));
strerror(ev));
if (iotype != IODUP)
close(u);
return -1;
@ -1212,9 +1219,10 @@ herein(const char *content, int sub)
*/
h = maketemp(ATEMP, TT_HEREDOC_EXP, &e->temps);
if (!(shf = h->shf) || (fd = open(h->name, O_RDONLY, 0)) < 0) {
fd = errno;
warningf(true, "can't %s temporary file %s: %s",
!shf ? "create" : "open",
h->name, strerror(errno));
h->name, strerror(fd));
if (shf)
shf_close(shf);
return -2 /* special to iosetup(): don't print error */;
@ -1244,9 +1252,11 @@ herein(const char *content, int sub)
quitenv(NULL);
if (shf_close(shf) == EOF) {
i = errno;
close(fd);
warningf(true, "error writing %s: %s", h->name,
strerror(errno));
fd = errno;
warningf(true, "error writing %s: %s, %s", h->name,
strerror(i), strerror(fd));
return -2; /* special to iosetup(): don't print error */
}
@ -1381,9 +1391,6 @@ pr_list(char *const *ap)
* [[ ... ]] evaluation routines
*/
extern const char *const dbtest_tokens[];
extern const char db_close[];
/* Test if the current token is a whatever. Accepts the current token if
* it is. Returns 0 if it is not, non-zero if it is (in the case of
* TM_UNOP and TM_BINOP, the returned value is a Test_op).

18
funcs.c
View File

@ -5,7 +5,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.55 2007/06/05 19:18:11 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.56 2007/06/06 23:28:15 tg Exp $");
int
c_cd(const char **wp)
@ -1790,7 +1790,8 @@ int
c_eval(const char **wp)
{
struct source *s, *saves = source;
int savef, rv;
char savef;
int rv;
if (ksh_getopt(wp, &builtin_opt, null) == '?')
return 1;
@ -1843,17 +1844,12 @@ c_trap(const char **wp)
wp += builtin_opt.optind;
if (*wp == NULL) {
int anydfl = 0;
for (p = sigtraps, i = NSIG+1; --i >= 0; p++) {
if (p->trap == NULL)
anydfl = 1;
else {
for (p = sigtraps, i = NSIG+1; --i >= 0; p++)
if (p->trap != NULL) {
shprintf("trap -- ");
print_value_quoted(p->trap);
shprintf(" %s\n", p->name);
}
}
return 0;
}
@ -2267,11 +2263,11 @@ c_mknod(const char **wp)
}
dv = makedev(majnum, minnum);
if ((unsigned long)major(dv) != majnum) {
bi_errorf("device major too large: %ld", majnum);
bi_errorf("device major too large: %lu", majnum);
goto c_mknod_err;
}
if ((unsigned long)minor(dv) != minnum) {
bi_errorf("device minor too large: %ld", minnum);
bi_errorf("device minor too large: %lu", minnum);
goto c_mknod_err;
}
if (mknod(argv[0], mode, dv))

View File

@ -3,10 +3,10 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.48 2007/06/05 21:47:48 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.49 2007/06/06 23:28:15 tg Exp $");
Trap sigtraps[NSIG + 1];
static struct sigaction Sigact_ign, Sigact_trap;
static struct sigaction Sigact_ign;
#if HAVE_PERSISTENT_HISTORY
static int hist_count_lines(unsigned char *, int);
@ -1009,8 +1009,6 @@ inittraps(void)
sigemptyset(&Sigact_ign.sa_mask);
Sigact_ign.sa_flags = 0; /* interruptible */
Sigact_ign.sa_handler = SIG_IGN;
Sigact_trap = Sigact_ign;
Sigact_trap.sa_handler = trapsig;
sigtraps[SIGINT].flags |= TF_DFL_INTR | TF_TTY_INTR;
sigtraps[SIGQUIT].flags |= TF_DFL_INTR | TF_TTY_INTR;

8
jobs.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.22 2007/05/13 17:51:22 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.23 2007/06/06 23:28:15 tg Exp $");
/* Order important! */
#define PRUNNING 0
@ -49,7 +49,7 @@ struct job {
Job *next; /* next job in list */
int job; /* job number: %n */
int flags; /* see JF_* */
int state; /* job state */
volatile int state; /* job state */
int status; /* exit status of last process */
pid_t pgrp; /* process group of job */
pid_t ppid; /* pid of process that forked job */
@ -905,8 +905,8 @@ j_waitj(Job *j,
if (!Flag(FMONITOR))
flags |= JW_STOPPEDWAIT;
while ((volatile int) j->state == PRUNNING ||
((flags & JW_STOPPEDWAIT) && (volatile int) j->state == PSTOPPED)) {
while (j->state == PRUNNING ||
((flags & JW_STOPPEDWAIT) && j->state == PSTOPPED)) {
sigsuspend(&sm_default);
if (fatal_trap) {
int oldf = j->flags & (JF_WAITING|JF_W_ASYNCNOTIFY);

23
main.c
View File

@ -13,7 +13,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.75 2007/05/13 17:51:22 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.76 2007/06/06 23:28:16 tg Exp $");
extern char **environ;
@ -936,23 +936,18 @@ ksh_dup2(int ofd, int nfd, int errok)
* move fd from user space (0<=fd<10) to shell space (fd>=10),
* set close-on-exec flag.
*/
int
short
savefd(int fd)
{
int nfd;
int nfd = fd;
if (fd < FDBASE) {
nfd = fcntl(fd, F_DUPFD, FDBASE);
if (nfd < 0) {
if (errno == EBADF)
return -1;
else
errorf("too many files open in shell");
}
} else
nfd = fd;
if (fd < FDBASE && (nfd = fcntl(fd, F_DUPFD, FDBASE)) < 0 &&
errno == EBADF)
return -1;
if (nfd < 0 || nfd > SHRT_MAX)
errorf("too many files open in shell");
fcntl(nfd, F_SETFD, FD_CLOEXEC);
return nfd;
return ((short)nfd);
}
void

13
misc.c
View File

@ -6,7 +6,7 @@
#include <grp.h>
#endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.56 2007/06/06 21:36:29 tg Exp $\t"
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.57 2007/06/06 23:28:16 tg Exp $\t"
MKSH_SH_H_ID);
#undef USE_CHVT
@ -226,9 +226,9 @@ getoptions(void)
void
change_flag(enum sh_flag f,
int what, /* flag to change */
int newval) /* what is changing the flag (command line vs set) */
char newval) /* what is changing the flag (command line vs set) */
{
int oldval;
char oldval;
oldval = Flag(f);
Flag(f) = newval;
@ -274,11 +274,11 @@ parse_args(const char **argv,
{
static char cmd_opts[NELEM(options) + 5]; /* o:T:\0 */
static char set_opts[NELEM(options) + 6]; /* A:o;s\0 */
char *opts;
char set, *opts;
const char *array = NULL;
Getopt go;
size_t i;
int optc, set, sortargs = 0, arrayset = 0;
int optc, sortargs = 0, arrayset = 0;
/* First call? Build option strings... */
if (cmd_opts[0] == '\0') {
@ -392,8 +392,7 @@ parse_args(const char **argv,
for (i = 0; i < NELEM(options); i++)
if (optc == options[i].c &&
(what & options[i].flags)) {
change_flag((enum sh_flag) i, what,
set);
change_flag((enum sh_flag)i, what, set);
break;
}
if (i == NELEM(options))

10
sh.h
View File

@ -8,8 +8,8 @@
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
/* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.142 2007/06/06 21:36:29 tg Exp $"
#define MKSH_VERSION "R29 2007/06/05"
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.143 2007/06/06 23:28:16 tg Exp $"
#define MKSH_VERSION "R29 2007/06/06"
#if HAVE_SYS_PARAM_H
#include <sys/param.h>
@ -1360,7 +1360,7 @@ void shprintf(const char *, ...)
int can_seek(int);
void initio(void);
int ksh_dup2(int, int, int);
int savefd(int);
short savefd(int);
void restfd(int, int);
void openpipe(int *);
void closepipe(int *);
@ -1391,7 +1391,7 @@ char *str_save(const char *, Area *);
char *str_nsave(const char *, int, Area *);
size_t option(const char *);
char *getoptions(void);
void change_flag(enum sh_flag, int, int);
void change_flag(enum sh_flag, int, char);
int parse_args(const char **, int, int *);
int getn(const char *, int *);
int bi_getn(const char *, int *);
@ -1521,6 +1521,8 @@ struct test_env {
void (*error)(Test_env *, int, const char *);
};
extern const char *const dbtest_tokens[];
Test_op test_isop(Test_meta, const char *);
int test_eval(Test_env *, Test_op, const char *, const char *, int);
int test_parse(Test_env *);

6
shf.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.14 2007/05/13 17:51:23 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.15 2007/06/06 23:28:17 tg Exp $");
/* flags to shf_emptybuf() */
#define EB_READSW 0x01 /* about to switch to reading */
@ -553,7 +553,7 @@ shf_putchar(int c, struct shf *shf)
return EOF;
if (shf->flags & SHF_UNBUF) {
char cc = c;
u_char cc = (u_char)c;
int n;
if (shf->fd < 0)
@ -924,7 +924,7 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
case 'c':
flags &= ~FL_DOT;
numbuf[0] = va_arg(args, int);
numbuf[0] = (char)(va_arg(args, int));
s = numbuf;
len = 1;
break;

4
syn.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.13 2007/05/13 19:00:30 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.14 2007/06/06 23:28:17 tg Exp $");
struct nesting_state {
int start_token; /* token than began nesting (eg, FOR) */
@ -315,7 +315,7 @@ get_command(int cf)
if (!is_wdvarname(yylval.cp, true))
yyerror("%s: bad identifier\n",
c == FOR ? "for" : "select");
t->str = str_save(ident, ATEMP);
t->str = str_nsave(ident, strlen(ident), ATEMP);
nesting_push(&old_nesting, c);
t->vars = wordlist();
t->left = dogroup();

5
var.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.38 2007/05/13 17:51:24 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.39 2007/06/06 23:28:17 tg Exp $");
/*
* Variables
@ -953,7 +953,8 @@ setspec(struct tbl *vp)
case V_PATH:
if (path)
afree(path, APERM);
path = str_save(str_val(vp), APERM);
s = str_val(vp);
path = str_save(s, APERM);
flushcom(1); /* clear tracked aliases */
break;
case V_IFS: