• alloc() can’t fail, afree() can take NULL
‣ macro afreechk() is superfluous • get rid of macro afreechv() by re-doing the “don’t leak that much” code • some KNF (mostly, whitespace and 80c) while here
This commit is contained in:
parent
b41a72ac2e
commit
f17b8b1c8b
8
edit.c
8
edit.c
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.126 2008/05/02 18:55:35 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.127 2008/05/17 18:46:57 tg Exp $");
|
||||||
|
|
||||||
/* tty driver characters we are interested in */
|
/* tty driver characters we are interested in */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -396,7 +396,7 @@ x_command_glob(int flags, const char *str, int slen, char ***wordsp)
|
|||||||
int i, path_order = 0;
|
int i, path_order = 0;
|
||||||
|
|
||||||
info = (struct path_order_info *)
|
info = (struct path_order_info *)
|
||||||
alloc(sizeof(struct path_order_info) * nwords, ATEMP);
|
alloc(sizeof (struct path_order_info) * nwords, ATEMP);
|
||||||
for (i = 0; i < nwords; i++) {
|
for (i = 0; i < nwords; i++) {
|
||||||
info[i].word = words[i];
|
info[i].word = words[i];
|
||||||
info[i].base = x_basename(words[i], NULL);
|
info[i].base = x_basename(words[i], NULL);
|
||||||
@ -586,7 +586,7 @@ static void
|
|||||||
x_free_words(int nwords, char **words)
|
x_free_words(int nwords, char **words)
|
||||||
{
|
{
|
||||||
while (nwords)
|
while (nwords)
|
||||||
afreechk(words[--nwords]);
|
afree(words[--nwords], ATEMP);
|
||||||
afree(words, ATEMP);
|
afree(words, ATEMP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4705,7 +4705,7 @@ save_edstate(struct edstate *old)
|
|||||||
{
|
{
|
||||||
struct edstate *new;
|
struct edstate *new;
|
||||||
|
|
||||||
new = (struct edstate *)alloc(sizeof(struct edstate), APERM);
|
new = (struct edstate *)alloc(sizeof (struct edstate), APERM);
|
||||||
new->cbuf = alloc(old->cbufsize, APERM);
|
new->cbuf = alloc(old->cbufsize, APERM);
|
||||||
memcpy(new->cbuf, old->cbuf, old->linelen);
|
memcpy(new->cbuf, old->cbuf, old->linelen);
|
||||||
new->cbufsize = old->cbufsize;
|
new->cbufsize = old->cbufsize;
|
||||||
|
10
eval.c
10
eval.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.45 2008/03/01 22:49:37 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.46 2008/05/17 18:46:58 tg Exp $");
|
||||||
|
|
||||||
#ifdef MKSH_SMALL
|
#ifdef MKSH_SMALL
|
||||||
#define MKSH_NOPWNAM
|
#define MKSH_NOPWNAM
|
||||||
@ -297,8 +297,8 @@ expand(const char *cp, /* input word */
|
|||||||
if (!st->next) {
|
if (!st->next) {
|
||||||
SubType *newst;
|
SubType *newst;
|
||||||
|
|
||||||
newst = (SubType *) alloc(
|
newst = (SubType *)alloc(
|
||||||
sizeof(SubType), ATEMP);
|
sizeof (SubType), ATEMP);
|
||||||
newst->next = NULL;
|
newst->next = NULL;
|
||||||
newst->prev = st;
|
newst->prev = st;
|
||||||
st->next = newst;
|
st->next = newst;
|
||||||
@ -589,7 +589,7 @@ expand(const char *cp, /* input word */
|
|||||||
*/
|
*/
|
||||||
len = strlen(dp) + 1;
|
len = strlen(dp) + 1;
|
||||||
setstr(st->var,
|
setstr(st->var,
|
||||||
debunk((char *) alloc(len, ATEMP),
|
debunk((char *)alloc(len, ATEMP),
|
||||||
dp, len), KSH_UNWIND_ERROR);
|
dp, len), KSH_UNWIND_ERROR);
|
||||||
x.str = str_val(st->var);
|
x.str = str_val(st->var);
|
||||||
type = XSUB;
|
type = XSUB;
|
||||||
@ -1474,7 +1474,7 @@ alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo)
|
|||||||
l1 = brace_start - start;
|
l1 = brace_start - start;
|
||||||
l2 = (p - 1) - field_start;
|
l2 = (p - 1) - field_start;
|
||||||
l3 = end - brace_end;
|
l3 = end - brace_end;
|
||||||
new = (char *) alloc(l1 + l2 + l3 + 1, ATEMP);
|
new = (char *)alloc(l1 + l2 + l3 + 1, ATEMP);
|
||||||
memcpy(new, start, l1);
|
memcpy(new, start, l1);
|
||||||
memcpy(new + l1, field_start, l2);
|
memcpy(new + l1, field_start, l2);
|
||||||
memcpy(new + l1 + l2, brace_end, l3);
|
memcpy(new + l1 + l2, brace_end, l3);
|
||||||
|
4
exec.c
4
exec.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.43 2008/04/19 22:15:02 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.44 2008/05/17 18:46:58 tg Exp $");
|
||||||
|
|
||||||
static int comexec(struct op *, struct tbl *volatile, const char **,
|
static int comexec(struct op *, struct tbl *volatile, const char **,
|
||||||
int volatile);
|
int volatile);
|
||||||
@ -72,7 +72,7 @@ execute(struct op *volatile t,
|
|||||||
flags &= ~XTIME;
|
flags &= ~XTIME;
|
||||||
|
|
||||||
if (t->ioact != NULL || t->type == TPIPE || t->type == TCOPROC) {
|
if (t->ioact != NULL || t->type == TPIPE || t->type == TCOPROC) {
|
||||||
e->savefd = (short *) alloc(sizeofN(short, NUFILE), ATEMP);
|
e->savefd = (short *)alloc(sizeofN(short, NUFILE), ATEMP);
|
||||||
/* initialise to not redirected */
|
/* initialise to not redirected */
|
||||||
memset(e->savefd, 0, sizeofN(short, NUFILE));
|
memset(e->savefd, 0, sizeofN(short, NUFILE));
|
||||||
}
|
}
|
||||||
|
55
funcs.c
55
funcs.c
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.80 2008/05/17 18:27:55 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.81 2008/05/17 18:46:58 tg Exp $");
|
||||||
|
|
||||||
/* A leading = means assignments before command are kept;
|
/* A leading = means assignments before command are kept;
|
||||||
* a leading * means a POSIX special builtin;
|
* a leading * means a POSIX special builtin;
|
||||||
@ -138,8 +138,7 @@ c_cd(const char **wp)
|
|||||||
bool printpath = false; /* print where we cd'd? */
|
bool printpath = false; /* print where we cd'd? */
|
||||||
struct tbl *pwd_s, *oldpwd_s;
|
struct tbl *pwd_s, *oldpwd_s;
|
||||||
XString xs;
|
XString xs;
|
||||||
char *dir, *try, *pwd, *cdpath;
|
char *dir, *allocd = NULL, *try, *pwd, *cdpath;
|
||||||
bool dir_ = false;
|
|
||||||
|
|
||||||
while ((optc = ksh_getopt(wp, &builtin_opt, "LP")) != -1)
|
while ((optc = ksh_getopt(wp, &builtin_opt, "LP")) != -1)
|
||||||
switch (optc) {
|
switch (optc) {
|
||||||
@ -170,17 +169,16 @@ c_cd(const char **wp)
|
|||||||
}
|
}
|
||||||
} else if (!wp[1]) {
|
} else if (!wp[1]) {
|
||||||
/* One argument: - or dir */
|
/* One argument: - or dir */
|
||||||
dir = str_save(wp[0], ATEMP);
|
if (ksh_isdash((dir = allocd = str_save(wp[0], ATEMP)))) {
|
||||||
if (ksh_isdash(dir)) {
|
afree(allocd, ATEMP);
|
||||||
afree(dir, ATEMP);
|
allocd = NULL;
|
||||||
dir = str_val(oldpwd_s);
|
dir = str_val(oldpwd_s);
|
||||||
if (dir == null) {
|
if (dir == null) {
|
||||||
bi_errorf("no OLDPWD");
|
bi_errorf("no OLDPWD");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
printpath = true;
|
printpath = true;
|
||||||
} else
|
}
|
||||||
dir_ = true;
|
|
||||||
} else if (!wp[2]) {
|
} else if (!wp[2]) {
|
||||||
/* Two arguments - substitute arg1 in PWD for arg2 */
|
/* Two arguments - substitute arg1 in PWD for arg2 */
|
||||||
int ilen, olen, nlen, elen;
|
int ilen, olen, nlen, elen;
|
||||||
@ -203,8 +201,7 @@ c_cd(const char **wp)
|
|||||||
olen = strlen(wp[0]);
|
olen = strlen(wp[0]);
|
||||||
nlen = strlen(wp[1]);
|
nlen = strlen(wp[1]);
|
||||||
elen = strlen(current_wd + ilen + olen) + 1;
|
elen = strlen(current_wd + ilen + olen) + 1;
|
||||||
dir = alloc(ilen + nlen + elen, ATEMP);
|
dir = allocd = alloc(ilen + nlen + elen, ATEMP);
|
||||||
dir_ = true;
|
|
||||||
memcpy(dir, current_wd, ilen);
|
memcpy(dir, current_wd, ilen);
|
||||||
memcpy(dir + ilen, wp[1], nlen);
|
memcpy(dir + ilen, wp[1], nlen);
|
||||||
memcpy(dir + ilen + nlen, current_wd + ilen + olen, elen);
|
memcpy(dir + ilen + nlen, current_wd + ilen + olen, elen);
|
||||||
@ -232,7 +229,7 @@ c_cd(const char **wp)
|
|||||||
bi_errorf("%s: bad directory", dir);
|
bi_errorf("%s: bad directory", dir);
|
||||||
else
|
else
|
||||||
bi_errorf("%s - %s", try, strerror(errno));
|
bi_errorf("%s - %s", try, strerror(errno));
|
||||||
afreechv(dir_, dir);
|
afree(allocd, ATEMP);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,7 +263,7 @@ c_cd(const char **wp)
|
|||||||
if (printpath || cdnode)
|
if (printpath || cdnode)
|
||||||
shprintf("%s\n", pwd);
|
shprintf("%s\n", pwd);
|
||||||
|
|
||||||
afreechv(dir_, dir);
|
afree(allocd, ATEMP);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,8 +272,7 @@ c_pwd(const char **wp)
|
|||||||
{
|
{
|
||||||
int optc;
|
int optc;
|
||||||
bool physical = Flag(FPHYSICAL) ? true : false;
|
bool physical = Flag(FPHYSICAL) ? true : false;
|
||||||
char *p;
|
char *p, *allocd = NULL;
|
||||||
bool p_ = false;
|
|
||||||
|
|
||||||
while ((optc = ksh_getopt(wp, &builtin_opt, "LP")) != -1)
|
while ((optc = ksh_getopt(wp, &builtin_opt, "LP")) != -1)
|
||||||
switch (optc) {
|
switch (optc) {
|
||||||
@ -295,20 +291,16 @@ c_pwd(const char **wp)
|
|||||||
bi_errorf("too many arguments");
|
bi_errorf("too many arguments");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
p = current_wd[0] ? (physical ? get_phys_path(current_wd) : current_wd) :
|
p = current_wd[0] ? (physical ? get_phys_path(current_wd) :
|
||||||
NULL;
|
current_wd) : NULL;
|
||||||
if (p && access(p, R_OK) < 0)
|
if (p && access(p, R_OK) < 0)
|
||||||
p = NULL;
|
p = NULL;
|
||||||
if (!p) {
|
if (!p && !(p = allocd = ksh_get_wd(NULL))) {
|
||||||
if (!(p = ksh_get_wd(NULL))) {
|
bi_errorf("can't get current directory - %s", strerror(errno));
|
||||||
bi_errorf("can't get current directory - %s",
|
return (1);
|
||||||
strerror(errno));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
p_ = true;
|
|
||||||
}
|
}
|
||||||
shprintf("%s\n", p);
|
shprintf("%s\n", p);
|
||||||
afreechv(p_, p);
|
afree(allocd, ATEMP);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1124,7 +1116,7 @@ c_alias(const char **wp)
|
|||||||
ap->flag &= ~xflag;
|
ap->flag &= ~xflag;
|
||||||
else
|
else
|
||||||
ap->flag |= xflag;
|
ap->flag |= xflag;
|
||||||
afreechk(xalias);
|
afree(xalias, ATEMP);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
@ -1513,7 +1505,7 @@ c_bind(const char **wp)
|
|||||||
}
|
}
|
||||||
if (x_bind(up ? up : *wp, cp, macro, 0))
|
if (x_bind(up ? up : *wp, cp, macro, 0))
|
||||||
rv = 1;
|
rv = 1;
|
||||||
afreechk(up);
|
afree(up, ATEMP);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
@ -1886,14 +1878,14 @@ c_read(const char **wp)
|
|||||||
if (vp->flag & RDONLY) {
|
if (vp->flag & RDONLY) {
|
||||||
shf_flush(shf);
|
shf_flush(shf);
|
||||||
bi_errorf("%s is read only", *wp);
|
bi_errorf("%s is read only", *wp);
|
||||||
afreechk(wpalloc);
|
afree(wpalloc, ATEMP);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (Flag(FEXPORT))
|
if (Flag(FEXPORT))
|
||||||
typeset(*wp, EXPORT, 0, 0, 0);
|
typeset(*wp, EXPORT, 0, 0, 0);
|
||||||
if (!setstr(vp, Xstring(cs, ccp), KSH_RETURN_ERROR)) {
|
if (!setstr(vp, Xstring(cs, ccp), KSH_RETURN_ERROR)) {
|
||||||
shf_flush(shf);
|
shf_flush(shf);
|
||||||
afreechk(wpalloc);
|
afree(wpalloc, ATEMP);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1912,7 +1904,7 @@ c_read(const char **wp)
|
|||||||
if (c == EOF && !ecode)
|
if (c == EOF && !ecode)
|
||||||
coproc_read_close(fd);
|
coproc_read_close(fd);
|
||||||
|
|
||||||
afreechk(wpalloc);
|
afree(wpalloc, ATEMP);
|
||||||
return ecode ? ecode : c == EOF;
|
return ecode ? ecode : c == EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2121,7 +2113,7 @@ c_set(const char **wp)
|
|||||||
while (*++wp != NULL)
|
while (*++wp != NULL)
|
||||||
*wp = str_save(*wp, &l->area);
|
*wp = str_save(*wp, &l->area);
|
||||||
l->argc = wp - owp - 1;
|
l->argc = wp - owp - 1;
|
||||||
l->argv = (const char **) alloc(sizeofN(char *, l->argc+2),
|
l->argv = (const char **)alloc(sizeofN(char *, l->argc+2),
|
||||||
&l->area);
|
&l->area);
|
||||||
for (wp = l->argv; (*wp++ = *owp++) != NULL; )
|
for (wp = l->argv; (*wp++ = *owp++) != NULL; )
|
||||||
;
|
;
|
||||||
@ -3076,8 +3068,7 @@ c_realpath(const char **wp)
|
|||||||
else {
|
else {
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
buf = alloc(PATH_MAX, ATEMP);
|
if (realpath(*wp, (buf = alloc(PATH_MAX, ATEMP))) == NULL) {
|
||||||
if (realpath(*wp, buf) == NULL) {
|
|
||||||
rv = errno;
|
rv = errno;
|
||||||
bi_errorf("%s: %s", *wp, strerror(rv));
|
bi_errorf("%s: %s", *wp, strerror(rv));
|
||||||
} else
|
} else
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.61 2008/04/19 17:21:53 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.62 2008/05/17 18:46:59 tg Exp $");
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* MirOS: This is the default mapping type, and need not be specified.
|
* MirOS: This is the default mapping type, and need not be specified.
|
||||||
@ -554,7 +554,7 @@ init_histvec(void)
|
|||||||
{
|
{
|
||||||
if (history == (char **)NULL) {
|
if (history == (char **)NULL) {
|
||||||
histsize = HISTORYSIZE;
|
histsize = HISTORYSIZE;
|
||||||
history = (char **)alloc(histsize*sizeof (char *), APERM);
|
history = (char **)alloc(histsize * sizeof (char *), APERM);
|
||||||
histptr = history - 1;
|
histptr = history - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
jobs.c
6
jobs.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.34 2008/05/15 15:24:09 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.35 2008/05/17 18:46:59 tg Exp $");
|
||||||
|
|
||||||
/* Order important! */
|
/* Order important! */
|
||||||
#define PRUNNING 0
|
#define PRUNNING 0
|
||||||
@ -1402,7 +1402,7 @@ new_job(void)
|
|||||||
newj = free_jobs;
|
newj = free_jobs;
|
||||||
free_jobs = free_jobs->next;
|
free_jobs = free_jobs->next;
|
||||||
} else
|
} else
|
||||||
newj = (Job *) alloc(sizeof(Job), APERM);
|
newj = (Job *)alloc(sizeof (Job), APERM);
|
||||||
|
|
||||||
/* brute force method */
|
/* brute force method */
|
||||||
for (i = 1; ; i++) {
|
for (i = 1; ; i++) {
|
||||||
@ -1429,7 +1429,7 @@ new_proc(void)
|
|||||||
p = free_procs;
|
p = free_procs;
|
||||||
free_procs = free_procs->next;
|
free_procs = free_procs->next;
|
||||||
} else
|
} else
|
||||||
p = (Proc *) alloc(sizeof(Proc), APERM);
|
p = (Proc *)alloc(sizeof (Proc), APERM);
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
9
lex.c
9
lex.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.59 2008/05/04 01:51:30 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.60 2008/05/17 18:46:59 tg Exp $");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* states while lexing word
|
* states while lexing word
|
||||||
@ -774,7 +774,8 @@ yylex(int cf)
|
|||||||
if ((c == '<' || c == '>') && state == SBASE &&
|
if ((c == '<' || c == '>') && state == SBASE &&
|
||||||
((c2 = Xlength(ws, wp)) == 0 ||
|
((c2 = Xlength(ws, wp)) == 0 ||
|
||||||
(c2 == 2 && dp[0] == CHAR && ksh_isdigit(dp[1])))) {
|
(c2 == 2 && dp[0] == CHAR && ksh_isdigit(dp[1])))) {
|
||||||
struct ioword *iop = (struct ioword *) alloc(sizeof(*iop), ATEMP);
|
struct ioword *iop = (struct ioword *)alloc(sizeof (*iop),
|
||||||
|
ATEMP);
|
||||||
|
|
||||||
if (c2 == 2)
|
if (c2 == 2)
|
||||||
iop->unit = dp[1] - '0';
|
iop->unit = dp[1] - '0';
|
||||||
@ -1012,7 +1013,7 @@ pushs(int type, Area *areap)
|
|||||||
{
|
{
|
||||||
Source *s;
|
Source *s;
|
||||||
|
|
||||||
s = (Source *)alloc(sizeof(Source), areap);
|
s = (Source *)alloc(sizeof (Source), areap);
|
||||||
s->type = type;
|
s->type = type;
|
||||||
s->str = null;
|
s->str = null;
|
||||||
s->start = NULL;
|
s->start = NULL;
|
||||||
@ -1501,7 +1502,7 @@ getsc_bn(void)
|
|||||||
static Lex_state *
|
static Lex_state *
|
||||||
push_state_(State_info *si, Lex_state *old_end)
|
push_state_(State_info *si, Lex_state *old_end)
|
||||||
{
|
{
|
||||||
Lex_state *new = alloc(sizeof(Lex_state) * STATE_BSIZE, ATEMP);
|
Lex_state *new = alloc(sizeof (Lex_state) * STATE_BSIZE, ATEMP);
|
||||||
|
|
||||||
new[0].ls_info.base = old_end;
|
new[0].ls_info.base = old_end;
|
||||||
si->base = &new[0];
|
si->base = &new[0];
|
||||||
|
6
main.c
6
main.c
@ -13,7 +13,7 @@
|
|||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.97 2008/05/15 15:24:10 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.98 2008/05/17 18:47:00 tg Exp $");
|
||||||
|
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
|
|
||||||
@ -592,7 +592,7 @@ newenv(int type)
|
|||||||
{
|
{
|
||||||
struct env *ep;
|
struct env *ep;
|
||||||
|
|
||||||
ep = (struct env *) alloc(sizeof(*ep), ATEMP);
|
ep = (struct env *)alloc(sizeof (*ep), ATEMP);
|
||||||
ep->type = type;
|
ep->type = type;
|
||||||
ep->flags = 0;
|
ep->flags = 0;
|
||||||
ainit(&ep->area);
|
ainit(&ep->area);
|
||||||
@ -1133,7 +1133,7 @@ maketemp(Area *ap, Temp_type type, struct temp **tlist)
|
|||||||
pathname = tempnam(dir, "mksh.");
|
pathname = tempnam(dir, "mksh.");
|
||||||
len = ((pathname == NULL) ? 0 : strlen(pathname)) + 1;
|
len = ((pathname == NULL) ? 0 : strlen(pathname)) + 1;
|
||||||
#endif
|
#endif
|
||||||
tp = (struct temp *) alloc(sizeof(struct temp) + len, ap);
|
tp = (struct temp *)alloc(sizeof (struct temp) + len, ap);
|
||||||
tp->name = (char *)&tp[1];
|
tp->name = (char *)&tp[1];
|
||||||
#if !HAVE_MKSTEMP
|
#if !HAVE_MKSTEMP
|
||||||
if (pathname == NULL)
|
if (pathname == NULL)
|
||||||
|
6
misc.c
6
misc.c
@ -6,7 +6,7 @@
|
|||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.78 2008/05/04 02:02:32 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.79 2008/05/17 18:47:00 tg Exp $");
|
||||||
|
|
||||||
#undef USE_CHVT
|
#undef USE_CHVT
|
||||||
#if defined(TIOCSCTTY) && !defined(MKSH_SMALL)
|
#if defined(TIOCSCTTY) && !defined(MKSH_SMALL)
|
||||||
@ -513,7 +513,7 @@ gmatchx(const char *s, const char *p, bool isfile)
|
|||||||
size_t len = pe - p + 1;
|
size_t len = pe - p + 1;
|
||||||
char tbuf[64];
|
char tbuf[64];
|
||||||
char *t = len <= sizeof(tbuf) ? tbuf :
|
char *t = len <= sizeof(tbuf) ? tbuf :
|
||||||
(char *) alloc(len, ATEMP);
|
(char *)alloc(len, ATEMP);
|
||||||
debunk(t, p, len);
|
debunk(t, p, len);
|
||||||
return !strcmp(t, s);
|
return !strcmp(t, s);
|
||||||
}
|
}
|
||||||
@ -953,7 +953,7 @@ print_columns(struct shf *shf, int n,
|
|||||||
char *(*func) (const void *, int, char *, int),
|
char *(*func) (const void *, int, char *, int),
|
||||||
const void *arg, int max_width, int prefcol)
|
const void *arg, int max_width, int prefcol)
|
||||||
{
|
{
|
||||||
char *str = (char *) alloc(max_width + 1, ATEMP);
|
char *str = (char *)alloc(max_width + 1, ATEMP);
|
||||||
int i, r, c, rows, cols, nspace;
|
int i, r, c, rows, cols, nspace;
|
||||||
|
|
||||||
/* max_width + 1 for the space. Note that no space
|
/* max_width + 1 for the space. Note that no space
|
||||||
|
17
sh.h
17
sh.h
@ -96,7 +96,7 @@
|
|||||||
#define __SCCSID(x) __IDSTRING(sccsid,x)
|
#define __SCCSID(x) __IDSTRING(sccsid,x)
|
||||||
|
|
||||||
#ifdef EXTERN
|
#ifdef EXTERN
|
||||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.216 2008/05/17 18:27:57 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.217 2008/05/17 18:47:01 tg Exp $");
|
||||||
#endif
|
#endif
|
||||||
#define MKSH_VERSION "R34 2008/05/17"
|
#define MKSH_VERSION "R34 2008/05/17"
|
||||||
|
|
||||||
@ -1073,7 +1073,7 @@ typedef struct XPtrV {
|
|||||||
|
|
||||||
#define XPinit(x, n) do { \
|
#define XPinit(x, n) do { \
|
||||||
void **vp__; \
|
void **vp__; \
|
||||||
vp__ = (void**) alloc(sizeofN(void*, (n)), ATEMP); \
|
vp__ = (void**)alloc(sizeofN(void*, (n)), ATEMP); \
|
||||||
(x).cur = (x).beg = vp__; \
|
(x).cur = (x).beg = vp__; \
|
||||||
(x).end = vp__ + (n); \
|
(x).end = vp__ + (n); \
|
||||||
} while (0)
|
} while (0)
|
||||||
@ -1209,18 +1209,9 @@ EXTERN struct timeval j_usrtime, j_systime;
|
|||||||
/* alloc.c */
|
/* alloc.c */
|
||||||
Area *ainit(Area *);
|
Area *ainit(Area *);
|
||||||
void afreeall(Area *);
|
void afreeall(Area *);
|
||||||
void *alloc(size_t, Area *);
|
void *alloc(size_t, Area *); /* cannot fail */
|
||||||
void *aresize(void *, size_t, Area *);
|
void *aresize(void *, size_t, Area *);
|
||||||
void afree(void *, Area *);
|
void afree(void *, Area *); /* can take NULL */
|
||||||
#define afreechk(s) do { \
|
|
||||||
void *afree_t = (s); \
|
|
||||||
if (afree_t) \
|
|
||||||
afree(afree_t, ATEMP); \
|
|
||||||
} while (0)
|
|
||||||
#define afreechv(v,s) do { \
|
|
||||||
if (v) \
|
|
||||||
afree(s, ATEMP); \
|
|
||||||
} while (0)
|
|
||||||
/* edit.c */
|
/* edit.c */
|
||||||
void x_init(void);
|
void x_init(void);
|
||||||
int x_read(char *, size_t);
|
int x_read(char *, size_t);
|
||||||
|
8
shf.c
8
shf.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.20 2008/05/02 18:55:37 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.21 2008/05/17 18:47:02 tg Exp $");
|
||||||
|
|
||||||
/* flags to shf_emptybuf() */
|
/* flags to shf_emptybuf() */
|
||||||
#define EB_READSW 0x01 /* about to switch to reading */
|
#define EB_READSW 0x01 /* about to switch to reading */
|
||||||
@ -29,7 +29,7 @@ shf_open(const char *name, int oflags, int mode, int sflags)
|
|||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
/* Done before open so if alloca fails, fd won't be lost. */
|
/* Done before open so if alloca fails, fd won't be lost. */
|
||||||
shf = (struct shf *) alloc(sizeof(struct shf) + bsize, ATEMP);
|
shf = (struct shf *)alloc(sizeof (struct shf) + bsize, ATEMP);
|
||||||
shf->areap = ATEMP;
|
shf->areap = ATEMP;
|
||||||
shf->buf = (unsigned char *)&shf[1];
|
shf->buf = (unsigned char *)&shf[1];
|
||||||
shf->bsize = bsize;
|
shf->bsize = bsize;
|
||||||
@ -97,7 +97,7 @@ shf_fdopen(int fd, int sflags, struct shf *shf)
|
|||||||
} else
|
} else
|
||||||
shf->buf = NULL;
|
shf->buf = NULL;
|
||||||
} else {
|
} else {
|
||||||
shf = (struct shf *)alloc(sizeof(struct shf) + bsize, ATEMP);
|
shf = (struct shf *)alloc(sizeof (struct shf) + bsize, ATEMP);
|
||||||
shf->buf = (unsigned char *)&shf[1];
|
shf->buf = (unsigned char *)&shf[1];
|
||||||
sflags |= SHF_ALLOCS;
|
sflags |= SHF_ALLOCS;
|
||||||
}
|
}
|
||||||
@ -180,7 +180,7 @@ shf_sopen(char *buf, int bsize, int sflags, struct shf *shf)
|
|||||||
internal_errorf("shf_sopen: flags 0x%x", sflags);
|
internal_errorf("shf_sopen: flags 0x%x", sflags);
|
||||||
|
|
||||||
if (!shf) {
|
if (!shf) {
|
||||||
shf = (struct shf *) alloc(sizeof(struct shf), ATEMP);
|
shf = (struct shf *)alloc(sizeof (struct shf), ATEMP);
|
||||||
sflags |= SHF_ALLOCS;
|
sflags |= SHF_ALLOCS;
|
||||||
}
|
}
|
||||||
shf->areap = ATEMP;
|
shf->areap = ATEMP;
|
||||||
|
13
syn.c
13
syn.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.20 2008/04/01 22:20:20 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.21 2008/05/17 18:47:02 tg Exp $");
|
||||||
|
|
||||||
struct nesting_state {
|
struct nesting_state {
|
||||||
int start_token; /* token than began nesting (eg, FOR) */
|
int start_token; /* token than began nesting (eg, FOR) */
|
||||||
@ -186,7 +186,7 @@ get_command(int cf)
|
|||||||
XPtrV args, vars;
|
XPtrV args, vars;
|
||||||
struct nesting_state old_nesting;
|
struct nesting_state old_nesting;
|
||||||
|
|
||||||
iops = (struct ioword **) alloc(sizeofN(struct ioword *, NUFILE+1),
|
iops = (struct ioword **)alloc(sizeofN(struct ioword *, NUFILE+1),
|
||||||
ATEMP);
|
ATEMP);
|
||||||
XPinit(args, 16);
|
XPinit(args, 16);
|
||||||
XPinit(vars, 16);
|
XPinit(vars, 16);
|
||||||
@ -588,13 +588,14 @@ function_body(char *name,
|
|||||||
* be used as input), we pretend there is a colon here.
|
* be used as input), we pretend there is a colon here.
|
||||||
*/
|
*/
|
||||||
t->left = newtp(TCOM);
|
t->left = newtp(TCOM);
|
||||||
t->left->args = (const char **)alloc(sizeof(char *) * 2, ATEMP);
|
t->left->args = (const char **)alloc(sizeof (char *) * 2,
|
||||||
t->left->args[0] = tv = alloc(sizeof(char) * 3, ATEMP);
|
ATEMP);
|
||||||
|
t->left->args[0] = tv = alloc(sizeof (char) * 3, ATEMP);
|
||||||
tv[0] = CHAR;
|
tv[0] = CHAR;
|
||||||
tv[1] = ':';
|
tv[1] = ':';
|
||||||
tv[2] = EOS;
|
tv[2] = EOS;
|
||||||
t->left->args[1] = NULL;
|
t->left->args[1] = NULL;
|
||||||
t->left->vars = (char **)alloc(sizeof(char *), ATEMP);
|
t->left->vars = (char **)alloc(sizeof (char *), ATEMP);
|
||||||
t->left->vars[0] = NULL;
|
t->left->vars[0] = NULL;
|
||||||
t->left->lineno = 1;
|
t->left->lineno = 1;
|
||||||
}
|
}
|
||||||
@ -771,7 +772,7 @@ newtp(int type)
|
|||||||
{
|
{
|
||||||
struct op *t;
|
struct op *t;
|
||||||
|
|
||||||
t = (struct op *)alloc(sizeof(*t), ATEMP);
|
t = (struct op *)alloc(sizeof (*t), ATEMP);
|
||||||
t->type = type;
|
t->type = type;
|
||||||
t->u.evalflags = 0;
|
t->u.evalflags = 0;
|
||||||
t->args = NULL;
|
t->args = NULL;
|
||||||
|
16
tree.c
16
tree.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.16 2008/04/19 22:15:06 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.17 2008/05/17 18:47:02 tg Exp $");
|
||||||
|
|
||||||
#define INDENT 4
|
#define INDENT 4
|
||||||
|
|
||||||
@ -421,7 +421,7 @@ tcopy(struct op *t, Area *ap)
|
|||||||
if (t == NULL)
|
if (t == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
r = (struct op *) alloc(sizeof(struct op), ap);
|
r = (struct op *)alloc(sizeof (struct op), ap);
|
||||||
|
|
||||||
r->type = t->type;
|
r->type = t->type;
|
||||||
r->u.evalflags = t->u.evalflags;
|
r->u.evalflags = t->u.evalflags;
|
||||||
@ -433,8 +433,8 @@ tcopy(struct op *t, Area *ap)
|
|||||||
else {
|
else {
|
||||||
for (tw = (const char **)t->vars; *tw++ != NULL; )
|
for (tw = (const char **)t->vars; *tw++ != NULL; )
|
||||||
;
|
;
|
||||||
rw = r->vars = (char **)
|
rw = r->vars = (char **)alloc((tw -
|
||||||
alloc((tw - (const char **)t->vars + 1) * sizeof(*tw), ap);
|
(const char **)t->vars + 1) * sizeof (*tw), ap);
|
||||||
for (tw = (const char **)t->vars; *tw != NULL; )
|
for (tw = (const char **)t->vars; *tw != NULL; )
|
||||||
*rw++ = wdcopy(*tw++, ap);
|
*rw++ = wdcopy(*tw++, ap);
|
||||||
*rw = NULL;
|
*rw = NULL;
|
||||||
@ -445,8 +445,8 @@ tcopy(struct op *t, Area *ap)
|
|||||||
else {
|
else {
|
||||||
for (tw = t->args; *tw++ != NULL; )
|
for (tw = t->args; *tw++ != NULL; )
|
||||||
;
|
;
|
||||||
r->args = (const char **)(rw = (char **)
|
r->args = (const char **)(rw = (char **)alloc((tw -
|
||||||
alloc((tw - t->args + 1) * sizeof(*tw), ap));
|
t->args + 1) * sizeof (*tw), ap));
|
||||||
for (tw = t->args; *tw != NULL; )
|
for (tw = t->args; *tw != NULL; )
|
||||||
*rw++ = wdcopy(*tw++, ap);
|
*rw++ = wdcopy(*tw++, ap);
|
||||||
*rw = NULL;
|
*rw = NULL;
|
||||||
@ -615,13 +615,13 @@ iocopy(struct ioword **iow, Area *ap)
|
|||||||
|
|
||||||
for (ior = iow; *ior++ != NULL; )
|
for (ior = iow; *ior++ != NULL; )
|
||||||
;
|
;
|
||||||
ior = (struct ioword **) alloc((ior - iow + 1) * sizeof(*ior), ap);
|
ior = (struct ioword **)alloc((ior - iow + 1) * sizeof (*ior), ap);
|
||||||
|
|
||||||
for (i = 0; iow[i] != NULL; i++) {
|
for (i = 0; iow[i] != NULL; i++) {
|
||||||
struct ioword *p, *q;
|
struct ioword *p, *q;
|
||||||
|
|
||||||
p = iow[i];
|
p = iow[i];
|
||||||
q = (struct ioword *) alloc(sizeof(*p), ap);
|
q = (struct ioword *)alloc(sizeof (*p), ap);
|
||||||
ior[i] = q;
|
ior[i] = q;
|
||||||
*q = *p;
|
*q = *p;
|
||||||
if (p->name != NULL)
|
if (p->name != NULL)
|
||||||
|
8
var.c
8
var.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.55 2008/05/02 18:55:37 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.56 2008/05/17 18:47:03 tg Exp $");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Variables
|
* Variables
|
||||||
@ -37,7 +37,7 @@ newblock(void)
|
|||||||
struct block *l;
|
struct block *l;
|
||||||
static const char *empty[] = { null };
|
static const char *empty[] = { null };
|
||||||
|
|
||||||
l = (struct block *) alloc(sizeof(struct block), ATEMP);
|
l = (struct block *)alloc(sizeof (struct block), ATEMP);
|
||||||
l->flags = 0;
|
l->flags = 0;
|
||||||
ainit(&l->area); /* todo: could use e->area (l->area => l->areap) */
|
ainit(&l->area); /* todo: could use e->area (l->area => l->areap) */
|
||||||
if (!e->loc) {
|
if (!e->loc) {
|
||||||
@ -386,7 +386,7 @@ setstr(struct tbl *vq, const char *s, int error_ok)
|
|||||||
vq->flag |= ISSET;
|
vq->flag |= ISSET;
|
||||||
if ((vq->flag&SPECIAL))
|
if ((vq->flag&SPECIAL))
|
||||||
setspec(vq);
|
setspec(vq);
|
||||||
afreechk(salloc);
|
afree(salloc, ATEMP);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1199,7 +1199,7 @@ arraysearch(struct tbl *vp, uint32_t val)
|
|||||||
else
|
else
|
||||||
new = curr;
|
new = curr;
|
||||||
} else
|
} else
|
||||||
new = (struct tbl *)alloc(sizeof(struct tbl) + namelen,
|
new = (struct tbl *)alloc(sizeof (struct tbl) + namelen,
|
||||||
vp->areap);
|
vp->areap);
|
||||||
strlcpy(new->name, vp->name, namelen);
|
strlcpy(new->name, vp->name, namelen);
|
||||||
new->flag = vp->flag & ~(ALLOC|DEFINED|ISSET|SPECIAL);
|
new->flag = vp->flag & ~(ALLOC|DEFINED|ISSET|SPECIAL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user