aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Lehmann <aaronl@vitelius.com>2001-12-06 03:37:38 +0000
committerAaron Lehmann <aaronl@vitelius.com>2001-12-06 03:37:38 +0000
commitb6ecbdc07dc444fb94e2024131df2f51d17399dd (patch)
treea28446df7aee588e5e647653a7b07ac11d6e0d61
parentebd8065f387e24f9a9562377dcabbf7eb0165c79 (diff)
downloadbusybox-w32-b6ecbdc07dc444fb94e2024131df2f51d17399dd.tar.gz
busybox-w32-b6ecbdc07dc444fb94e2024131df2f51d17399dd.tar.bz2
busybox-w32-b6ecbdc07dc444fb94e2024131df2f51d17399dd.zip
The ash ansification diff!
Please tell me if you notice any problems resulting from this.
-rw-r--r--shell/ash.c547
1 files changed, 191 insertions, 356 deletions
diff --git a/shell/ash.c b/shell/ash.c
index c1603d790..16c5ec0f2 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -211,10 +211,6 @@
211#define digit_val(c) ((c) - '0') 211#define digit_val(c) ((c) - '0')
212 212
213 213
214#define _DIAGASSERT(x)
215
216
217
218#define S_DFL 1 /* default signal handling (SIG_DFL) */ 214#define S_DFL 1 /* default signal handling (SIG_DFL) */
219#define S_CATCH 2 /* signal is caught */ 215#define S_CATCH 2 /* signal is caught */
220#define S_IGN 3 /* signal is ignored (SIG_IGN) */ 216#define S_IGN 3 /* signal is ignored (SIG_IGN) */
@@ -304,10 +300,6 @@ typedef void *pointer;
304#define NULL (void *)0 300#define NULL (void *)0
305#endif 301#endif
306 302
307static inline pointer ckmalloc (int sz) { return xmalloc(sz); }
308static inline pointer ckrealloc(void *p, int sz) { return xrealloc(p, sz); }
309static inline char * savestr (const char *s) { return xstrdup(s); }
310
311static pointer stalloc (int); 303static pointer stalloc (int);
312static void stunalloc (pointer); 304static void stunalloc (pointer);
313static void ungrabstackstr (char *, char *); 305static void ungrabstackstr (char *, char *);
@@ -1128,6 +1120,10 @@ static void deletefuncs(void);
1128static void setparam (char **); 1120static void setparam (char **);
1129static void freeparam (volatile struct shparam *); 1121static void freeparam (volatile struct shparam *);
1130 1122
1123static void find_command (const char *, struct cmdentry *, int, const char *);
1124
1125static inline void hashcd (void);
1126
1131/* reasons for skipping commands (see comment on breakcmd routine) */ 1127/* reasons for skipping commands (see comment on breakcmd routine) */
1132#define SKIPBREAK 1 1128#define SKIPBREAK 1
1133#define SKIPCONT 2 1129#define SKIPCONT 2
@@ -1339,8 +1335,7 @@ static struct alias *freealias (struct alias *);
1339static struct alias **__lookupalias (const char *); 1335static struct alias **__lookupalias (const char *);
1340 1336
1341static void 1337static void
1342setalias(name, val) 1338setalias(char *name, char *val)
1343 char *name, *val;
1344{ 1339{
1345 struct alias *ap, **app; 1340 struct alias *ap, **app;
1346 1341
@@ -1351,13 +1346,13 @@ setalias(name, val)
1351 if (!(ap->flag & ALIASINUSE)) { 1346 if (!(ap->flag & ALIASINUSE)) {
1352 ckfree(ap->val); 1347 ckfree(ap->val);
1353 } 1348 }
1354 ap->val = savestr(val); 1349 ap->val = xstrdup(val);
1355 ap->flag &= ~ALIASDEAD; 1350 ap->flag &= ~ALIASDEAD;
1356 } else { 1351 } else {
1357 /* not found */ 1352 /* not found */
1358 ap = ckmalloc(sizeof (struct alias)); 1353 ap = xmalloc(sizeof (struct alias));
1359 ap->name = savestr(name); 1354 ap->name = xstrdup(name);
1360 ap->val = savestr(val); 1355 ap->val = xstrdup(val);
1361 ap->flag = 0; 1356 ap->flag = 0;
1362 ap->next = 0; 1357 ap->next = 0;
1363 *app = ap; 1358 *app = ap;
@@ -1469,9 +1464,8 @@ unaliascmd(int argc, char **argv)
1469} 1464}
1470 1465
1471static struct alias ** 1466static struct alias **
1472hashalias(p) 1467hashalias(const char *p)
1473 const char *p; 1468{
1474 {
1475 unsigned int hashval; 1469 unsigned int hashval;
1476 1470
1477 hashval = *p << 4; 1471 hashval = *p << 4;
@@ -1481,7 +1475,8 @@ hashalias(p)
1481} 1475}
1482 1476
1483static struct alias * 1477static struct alias *
1484freealias(struct alias *ap) { 1478freealias(struct alias *ap)
1479{
1485 struct alias *next; 1480 struct alias *next;
1486 1481
1487 if (ap->flag & ALIASINUSE) { 1482 if (ap->flag & ALIASINUSE) {
@@ -1498,7 +1493,8 @@ freealias(struct alias *ap) {
1498 1493
1499 1494
1500static struct alias ** 1495static struct alias **
1501__lookupalias(const char *name) { 1496__lookupalias(const char *name)
1497{
1502 struct alias **app = hashalias(name); 1498 struct alias **app = hashalias(name);
1503 1499
1504 for (; *app; app = &(*app)->next) { 1500 for (; *app; app = &(*app)->next) {
@@ -1727,7 +1723,6 @@ static int forkshell (struct job *, const union node *, int);
1727static int waitforjob (struct job *); 1723static int waitforjob (struct job *);
1728 1724
1729static int docd (char *, int); 1725static int docd (char *, int);
1730static void updatepwd (const char *);
1731static void getpwd (void); 1726static void getpwd (void);
1732 1727
1733static char *padvance (const char **, const char *); 1728static char *padvance (const char **, const char *);
@@ -1736,9 +1731,7 @@ static char nullstr[1]; /* zero length string */
1736static char *curdir = nullstr; /* current working directory */ 1731static char *curdir = nullstr; /* current working directory */
1737 1732
1738static int 1733static int
1739cdcmd(argc, argv) 1734cdcmd(int argc, char **argv)
1740 int argc;
1741 char **argv;
1742{ 1735{
1743 const char *dest; 1736 const char *dest;
1744 const char *path; 1737 const char *path;
@@ -1798,40 +1791,29 @@ docd(char *dest, int print)
1798 INTON; 1791 INTON;
1799 return -1; 1792 return -1;
1800 } 1793 }
1801 updatepwd(dest); 1794 hashcd();
1795 /*
1796 * Update curdir (the name of the current directory) in response to a
1797 * cd command. We also call hashcd to let the routines in exec.c know
1798 * that the current directory has changed.
1799 */
1800 /* If dest is NULL, we don't know the current directory */
1801 if (dest == NULL || curdir == nullstr)
1802 setpwd(0, 1);
1803 else
1804 setpwd(dest, 1);
1805
1802 INTON; 1806 INTON;
1803 if (print && iflag) 1807 if (print && iflag)
1804 printf(snlfmt, curdir); 1808 puts(curdir);
1805 return 0; 1809 return 0;
1806} 1810}
1807 1811
1808 1812
1809/*
1810 * Update curdir (the name of the current directory) in response to a
1811 * cd command. We also call hashcd to let the routines in exec.c know
1812 * that the current directory has changed.
1813 */
1814
1815static void hashcd (void);
1816
1817static void
1818updatepwd(const char *dir)
1819{
1820 hashcd(); /* update command hash table */
1821
1822 /* If our argument is NULL, we don't know the current directory */
1823 if (dir == NULL || curdir == nullstr) {
1824 setpwd(0, 1);
1825 return;
1826 }
1827 setpwd(dir, 1);
1828}
1829
1830
1831static int 1813static int
1832pwdcmd(int argc, char **argv) 1814pwdcmd(int argc, char **argv)
1833{ 1815{
1834 printf(snlfmt, curdir); 1816 puts(curdir);
1835 return 0; 1817 return 0;
1836} 1818}
1837 1819
@@ -2134,7 +2116,6 @@ static int oexitstatus; /* saved exit status */
2134 2116
2135static void evalsubshell (const union node *, int); 2117static void evalsubshell (const union node *, int);
2136static void expredir (union node *); 2118static void expredir (union node *);
2137static void prehash (union node *);
2138static void eprintlist (struct strlist *); 2119static void eprintlist (struct strlist *);
2139 2120
2140static union node *parsecmd(int); 2121static union node *parsecmd(int);
@@ -2148,9 +2129,7 @@ static union node *parsecmd(int);
2148static void evalstring (char *, int); 2129static void evalstring (char *, int);
2149 2130
2150static int 2131static int
2151evalcmd(argc, argv) 2132evalcmd(int argc, char **argv)
2152 int argc;
2153 char **argv;
2154{ 2133{
2155 char *p; 2134 char *p;
2156 char *concat; 2135 char *concat;
@@ -2226,7 +2205,7 @@ copyfunc(union node *n)
2226 funcblocksize = 0; 2205 funcblocksize = 0;
2227 funcstringsize = 0; 2206 funcstringsize = 0;
2228 calcsize(n); 2207 calcsize(n);
2229 funcblock = ckmalloc(funcblocksize + funcstringsize); 2208 funcblock = xmalloc(funcblocksize + funcstringsize);
2230 funcstring = (char *) funcblock + funcblocksize; 2209 funcstring = (char *) funcblock + funcblocksize;
2231 return copynode(n); 2210 return copynode(n);
2232} 2211}
@@ -2384,7 +2363,18 @@ static inline void evalpipe(union node *n)
2384 jp = makejob(n, pipelen); 2363 jp = makejob(n, pipelen);
2385 prevfd = -1; 2364 prevfd = -1;
2386 for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) { 2365 for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
2387 prehash(lp->n); 2366 /*
2367 * Search for a command. This is called before we fork so that the
2368 * location of the command will be available in the parent as well as
2369 * the child. The check for "goodname" is an overly conservative
2370 * check that the name will not be subject to expansion.
2371 */
2372
2373 struct cmdentry entry;
2374 union node *lpn = lp->n;
2375 if (lpn->type == NCMD && lpn->ncmd.args && goodname(lpn->ncmd.args->narg.text))
2376 find_command(lpn->ncmd.args->narg.text, &entry, 0, pathval());
2377
2388 pip[1] = -1; 2378 pip[1] = -1;
2389 if (lp->next) { 2379 if (lp->next) {
2390 if (pipe(pip) < 0) { 2380 if (pipe(pip) < 0) {
@@ -2428,8 +2418,6 @@ static inline void evalpipe(union node *n)
2428 } 2418 }
2429} 2419}
2430 2420
2431static void find_command (const char *, struct cmdentry *, int, const char *);
2432
2433static int 2421static int
2434isassignment(const char *word) { 2422isassignment(const char *word) {
2435 if (!is_name(*word)) { 2423 if (!is_name(*word)) {
@@ -2750,9 +2738,7 @@ out:
2750 * exitstatus. 2738 * exitstatus.
2751 */ 2739 */
2752static void 2740static void
2753evaltree(n, flags) 2741evaltree(union node *n, int flags)
2754 union node *n;
2755 int flags;
2756{ 2742{
2757 int checkexit = 0; 2743 int checkexit = 0;
2758 if (n == NULL) { 2744 if (n == NULL) {
@@ -2972,25 +2958,6 @@ out:
2972 * Execute a simple command. 2958 * Execute a simple command.
2973 */ 2959 */
2974 2960
2975/*
2976 * Search for a command. This is called before we fork so that the
2977 * location of the command will be available in the parent as well as
2978 * the child. The check for "goodname" is an overly conservative
2979 * check that the name will not be subject to expansion.
2980 */
2981
2982static void
2983prehash(n)
2984 union node *n;
2985{
2986 struct cmdentry entry;
2987
2988 if (n->type == NCMD && n->ncmd.args)
2989 if (goodname(n->ncmd.args->narg.text))
2990 find_command(n->ncmd.args->narg.text, &entry, 0,
2991 pathval());
2992}
2993
2994 2961
2995/* 2962/*
2996 * Builtin commands. Builtin commands whose functions are closely 2963 * Builtin commands. Builtin commands whose functions are closely
@@ -3003,9 +2970,7 @@ prehash(n)
3003 */ 2970 */
3004 2971
3005int 2972int
3006bltincmd(argc, argv) 2973bltincmd(int argc, char **argv)
3007 int argc;
3008 char **argv;
3009{ 2974{
3010 /* 2975 /*
3011 * Preserve exitstatus of a previous possible redirection 2976 * Preserve exitstatus of a previous possible redirection
@@ -3027,9 +2992,7 @@ bltincmd(argc, argv)
3027 */ 2992 */
3028 2993
3029static int 2994static int
3030breakcmd(argc, argv) 2995breakcmd(int argc, char **argv)
3031 int argc;
3032 char **argv;
3033{ 2996{
3034 int n = argc > 1 ? number(argv[1]) : 1; 2997 int n = argc > 1 ? number(argv[1]) : 1;
3035 2998
@@ -3048,9 +3011,7 @@ breakcmd(argc, argv)
3048 */ 3011 */
3049 3012
3050static int 3013static int
3051returncmd(argc, argv) 3014returncmd(int argc, char **argv)
3052 int argc;
3053 char **argv;
3054{ 3015{
3055 int ret = argc > 1 ? number(argv[1]) : oexitstatus; 3016 int ret = argc > 1 ? number(argv[1]) : oexitstatus;
3056 3017
@@ -3070,9 +3031,7 @@ returncmd(argc, argv)
3070 3031
3071#ifndef CONFIG_FALSE 3032#ifndef CONFIG_FALSE
3072static int 3033static int
3073false_main(argc, argv) 3034false_main(int argc, char **argv)
3074 int argc;
3075 char **argv;
3076{ 3035{
3077 return 1; 3036 return 1;
3078} 3037}
@@ -3080,9 +3039,7 @@ false_main(argc, argv)
3080 3039
3081#ifndef CONFIG_TRUE 3040#ifndef CONFIG_TRUE
3082static int 3041static int
3083true_main(argc, argv) 3042true_main(int argc, char **argv)
3084 int argc;
3085 char **argv;
3086{ 3043{
3087 return 0; 3044 return 0;
3088} 3045}
@@ -3132,9 +3089,7 @@ optschanged(void)
3132 3089
3133 3090
3134static int 3091static int
3135execcmd(argc, argv) 3092execcmd(int argc, char **argv)
3136 int argc;
3137 char **argv;
3138{ 3093{
3139 if (argc > 1) { 3094 if (argc > 1) {
3140 struct strlist *sp; 3095 struct strlist *sp;
@@ -3165,10 +3120,7 @@ eprintlist(struct strlist *sp)
3165static const char *pathopt; /* set by padvance */ 3120static const char *pathopt; /* set by padvance */
3166 3121
3167static void 3122static void
3168shellexec(argv, envp, path, idx) 3123shellexec(char **argv, char **envp, const char *path, int idx)
3169 char **argv, **envp;
3170 const char *path;
3171 int idx;
3172{ 3124{
3173 char *cmdname; 3125 char *cmdname;
3174 int e; 3126 int e;
@@ -3208,7 +3160,8 @@ shellexec(argv, envp, path, idx)
3208 * Clear traps on a fork. 3160 * Clear traps on a fork.
3209 */ 3161 */
3210static void 3162static void
3211clear_traps(void) { 3163clear_traps(void)
3164{
3212 char **tp; 3165 char **tp;
3213 3166
3214 for (tp = trap ; tp < &trap[NSIG] ; tp++) { 3167 for (tp = trap ; tp < &trap[NSIG] ; tp++) {
@@ -3225,7 +3178,8 @@ clear_traps(void) {
3225 3178
3226 3179
3227static void 3180static void
3228initshellproc(void) { 3181initshellproc(void)
3182{
3229 3183
3230#ifdef ASH_ALIAS 3184#ifdef ASH_ALIAS
3231 /* from alias.c: */ 3185 /* from alias.c: */
@@ -3326,7 +3280,8 @@ static void pungetc(void)
3326 3280
3327 3281
3328static void 3282static void
3329popfile(void) { 3283popfile(void)
3284{
3330 struct parsefile *pf = parsefile; 3285 struct parsefile *pf = parsefile;
3331 3286
3332 INTOFF; 3287 INTOFF;
@@ -3351,7 +3306,8 @@ popfile(void) {
3351 */ 3306 */
3352 3307
3353static void 3308static void
3354popallfiles(void) { 3309popallfiles(void)
3310{
3355 while (parsefile != &basepf) 3311 while (parsefile != &basepf)
3356 popfile(); 3312 popfile();
3357} 3313}
@@ -3389,7 +3345,7 @@ static void setinputfd(int fd, int push)
3389 } 3345 }
3390 parsefile->fd = fd; 3346 parsefile->fd = fd;
3391 if (parsefile->buf == NULL) 3347 if (parsefile->buf == NULL)
3392 parsefile->buf = ckmalloc(BUFSIZ); 3348 parsefile->buf = xmalloc(BUFSIZ);
3393 parselleft = parsenleft = 0; 3349 parselleft = parsenleft = 0;
3394 plinno = 1; 3350 plinno = 1;
3395} 3351}
@@ -3447,7 +3403,7 @@ tryexec(char *cmd, char **argv, char **envp)
3447 INTOFF; 3403 INTOFF;
3448 initshellproc(); 3404 initshellproc();
3449 setinputfile(cmd, 0); 3405 setinputfile(cmd, 0);
3450 commandname = arg0 = savestr(argv[0]); 3406 commandname = arg0 = xstrdup(argv[0]);
3451 setparam(argv + 1); 3407 setparam(argv + 1);
3452 exraise(EXSHELLPROC); 3408 exraise(EXSHELLPROC);
3453 } 3409 }
@@ -3531,9 +3487,7 @@ findkwd(const char *s)
3531 3487
3532 3488
3533static int 3489static int
3534hashcmd(argc, argv) 3490hashcmd(int argc, char **argv)
3535 int argc;
3536 char **argv;
3537{ 3491{
3538 struct tblentry **pp; 3492 struct tblentry **pp;
3539 struct tblentry *cmdp; 3493 struct tblentry *cmdp;
@@ -3585,7 +3539,7 @@ hashcmd(argc, argv)
3585 if (verbose=='v') 3539 if (verbose=='v')
3586 printf("%s is a shell keyword\n", name); 3540 printf("%s is a shell keyword\n", name);
3587 else 3541 else
3588 printf(snlfmt, name); 3542 puts(name);
3589 continue; 3543 continue;
3590 } 3544 }
3591 3545
@@ -3601,10 +3555,8 @@ hashcmd(argc, argv)
3601} 3555}
3602 3556
3603static void 3557static void
3604printentry(cmdp, verbose) 3558printentry(struct tblentry *cmdp, int verbose)
3605 struct tblentry *cmdp; 3559{
3606 int verbose;
3607 {
3608 int idx; 3560 int idx;
3609 const char *path; 3561 const char *path;
3610 char *name; 3562 char *name;
@@ -3636,7 +3588,7 @@ printentry(cmdp, verbose)
3636 error("internal error: cmdtype %d", cmdp->cmdtype); 3588 error("internal error: cmdtype %d", cmdp->cmdtype);
3637#endif 3589#endif
3638 } 3590 }
3639 printf(snlfmt, cmdp->rehash ? "*" : nullstr); 3591 puts(cmdp->rehash ? "*" : nullstr);
3640} 3592}
3641 3593
3642 3594
@@ -3892,8 +3844,9 @@ find_builtin(const char *name)
3892 * are executed they will be rehashed. 3844 * are executed they will be rehashed.
3893 */ 3845 */
3894 3846
3895static void 3847static inline void
3896hashcd(void) { 3848hashcd(void)
3849{
3897 struct tblentry **pp; 3850 struct tblentry **pp;
3898 struct tblentry *cmdp; 3851 struct tblentry *cmdp;
3899 3852
@@ -3934,8 +3887,7 @@ changepath(const char *newval)
3934 */ 3887 */
3935 3888
3936static void 3889static void
3937clearcmdentry(firstchange) 3890clearcmdentry(int firstchange)
3938 int firstchange;
3939{ 3891{
3940 struct tblentry **tblp; 3892 struct tblentry **tblp;
3941 struct tblentry **pp; 3893 struct tblentry **pp;
@@ -3965,7 +3917,8 @@ clearcmdentry(firstchange)
3965 */ 3917 */
3966 3918
3967static void 3919static void
3968deletefuncs(void) { 3920deletefuncs(void)
3921{
3969 struct tblentry **tblp; 3922 struct tblentry **tblp;
3970 struct tblentry **pp; 3923 struct tblentry **pp;
3971 struct tblentry *cmdp; 3924 struct tblentry *cmdp;
@@ -4019,7 +3972,7 @@ cmdlookup(const char *name, int add)
4019 } 3972 }
4020 if (add && cmdp == NULL) { 3973 if (add && cmdp == NULL) {
4021 INTOFF; 3974 INTOFF;
4022 cmdp = *pp = ckmalloc(sizeof (struct tblentry) - ARB 3975 cmdp = *pp = xmalloc(sizeof (struct tblentry) - ARB
4023 + strlen(name) + 1); 3976 + strlen(name) + 1);
4024 cmdp->next = NULL; 3977 cmdp->next = NULL;
4025 cmdp->cmdtype = CMDUNKNOWN; 3978 cmdp->cmdtype = CMDUNKNOWN;
@@ -4036,7 +3989,8 @@ cmdlookup(const char *name, int add)
4036 */ 3989 */
4037 3990
4038static void 3991static void
4039delete_cmd_entry() { 3992delete_cmd_entry()
3993{
4040 struct tblentry *cmdp; 3994 struct tblentry *cmdp;
4041 3995
4042 INTOFF; 3996 INTOFF;
@@ -4121,9 +4075,7 @@ typecmd(int argc, char **argv)
4121 4075
4122#ifdef ASH_CMDCMD 4076#ifdef ASH_CMDCMD
4123static int 4077static int
4124commandcmd(argc, argv) 4078commandcmd(int argc, char **argv)
4125 int argc;
4126 char **argv;
4127{ 4079{
4128 int c; 4080 int c;
4129 int default_path = 0; 4081 int default_path = 0;
@@ -4166,9 +4118,7 @@ commandcmd(argc, argv)
4166#endif 4118#endif
4167 4119
4168static int 4120static int
4169path_change(newval, bltin) 4121path_change(const char *newval, int *bltin)
4170 const char *newval;
4171 int *bltin;
4172{ 4122{
4173 const char *old, *new; 4123 const char *old, *new;
4174 int idx; 4124 int idx;
@@ -4235,7 +4185,7 @@ static void expbackq (union node *, int, int);
4235static int subevalvar (char *, char *, int, int, int, int, int); 4185static int subevalvar (char *, char *, int, int, int, int, int);
4236static int varisset (char *, int); 4186static int varisset (char *, int);
4237static void strtodest (const char *, int, int); 4187static void strtodest (const char *, int, int);
4238static void varvalue (char *, int, int); 4188static inline void varvalue (char *, int, int);
4239static void recordregion (int, int, int); 4189static void recordregion (int, int, int);
4240static void removerecordregions (int); 4190static void removerecordregions (int);
4241static void ifsbreakup (char *, struct arglist *); 4191static void ifsbreakup (char *, struct arglist *);
@@ -4244,7 +4194,7 @@ static void expandmeta (struct strlist *, int);
4244#if defined(__GLIBC__) && __GLIBC__ >= 2 && !defined(FNMATCH_BROKEN) 4194#if defined(__GLIBC__) && __GLIBC__ >= 2 && !defined(FNMATCH_BROKEN)
4245#define preglob(p) _rmescapes((p), RMESCAPE_ALLOC | RMESCAPE_GLOB) 4195#define preglob(p) _rmescapes((p), RMESCAPE_ALLOC | RMESCAPE_GLOB)
4246#if !defined(GLOB_BROKEN) 4196#if !defined(GLOB_BROKEN)
4247static void addglob (const glob_t *); 4197static inline void addglob (const glob_t *);
4248#endif 4198#endif
4249#endif 4199#endif
4250#if !(defined(__GLIBC__) && __GLIBC__ >= 2 && !defined(FNMATCH_BROKEN) && !defined(GLOB_BROKEN)) 4200#if !(defined(__GLIBC__) && __GLIBC__ >= 2 && !defined(FNMATCH_BROKEN) && !defined(GLOB_BROKEN))
@@ -4285,10 +4235,7 @@ expandhere(union node *arg, int fd)
4285 */ 4235 */
4286 4236
4287static void 4237static void
4288expandarg(arg, arglist, flag) 4238expandarg(union node *arg, struct arglist *arglist, int flag)
4289 union node *arg;
4290 struct arglist *arglist;
4291 int flag;
4292{ 4239{
4293 struct strlist *sp; 4240 struct strlist *sp;
4294 char *p; 4241 char *p;
@@ -4496,9 +4443,7 @@ record:
4496 */ 4443 */
4497 4444
4498static void 4445static void
4499argstr(p, flag) 4446argstr(char *p, int flag)
4500 char *p;
4501 int flag;
4502{ 4447{
4503 char c; 4448 char c;
4504 int quotes = flag & (EXP_FULL | EXP_CASE); /* do CTLESC */ 4449 int quotes = flag & (EXP_FULL | EXP_CASE); /* do CTLESC */
@@ -4510,7 +4455,7 @@ argstr(p, flag)
4510 switch (c = *p++) { 4455 switch (c = *p++) {
4511 case '\0': 4456 case '\0':
4512 case CTLENDVAR: /* ??? */ 4457 case CTLENDVAR: /* ??? */
4513 goto breakloop; 4458 return;
4514 case CTLQUOTEMARK: 4459 case CTLQUOTEMARK:
4515 /* "$@" syntax adherence hack */ 4460 /* "$@" syntax adherence hack */
4516 if (p[0] == CTLVAR && p[2] == '@' && p[3] == '=') 4461 if (p[0] == CTLVAR && p[2] == '@' && p[3] == '=')
@@ -4558,14 +4503,11 @@ argstr(p, flag)
4558 STPUTC(c, expdest); 4503 STPUTC(c, expdest);
4559 } 4504 }
4560 } 4505 }
4561breakloop:;
4562 return; 4506 return;
4563} 4507}
4564 4508
4565static char * 4509static char *
4566exptilde(p, flag) 4510exptilde(char *p, int flag)
4567 char *p;
4568 int flag;
4569{ 4511{
4570 char c, *startp = p; 4512 char c, *startp = p;
4571 struct passwd *pw; 4513 struct passwd *pw;
@@ -4720,10 +4662,7 @@ expari(int flag)
4720 */ 4662 */
4721 4663
4722static void 4664static void
4723expbackq(cmd, quoted, flag) 4665expbackq(union node *cmd, int quoted, int flag)
4724 union node *cmd;
4725 int quoted;
4726 int flag;
4727{ 4666{
4728 volatile struct backcmd in; 4667 volatile struct backcmd in;
4729 int i; 4668 int i;
@@ -4824,14 +4763,7 @@ err2:
4824} 4763}
4825 4764
4826static int 4765static int
4827subevalvar(p, str, strloc, subtype, startloc, varflags, quotes) 4766subevalvar(char *p, char *str, int strloc, int subtype, int startloc, int varflags, int quotes)
4828 char *p;
4829 char *str;
4830 int strloc;
4831 int subtype;
4832 int startloc;
4833 int varflags;
4834 int quotes;
4835{ 4767{
4836 char *startp; 4768 char *startp;
4837 char *loc = NULL; 4769 char *loc = NULL;
@@ -4952,9 +4884,7 @@ recordright:
4952 */ 4884 */
4953 4885
4954static int 4886static int
4955varisset(name, nulok) 4887varisset(char *name, int nulok)
4956 char *name;
4957 int nulok;
4958{ 4888{
4959 if (*name == '!') 4889 if (*name == '!')
4960 return backgndpid != -1; 4890 return backgndpid != -1;
@@ -5006,7 +4936,7 @@ strtodest(const char *p, int syntax, int quotes)
5006 * Add the value of a specialized variable to the stack string. 4936 * Add the value of a specialized variable to the stack string.
5007 */ 4937 */
5008 4938
5009static void 4939static inline void
5010varvalue(char *name, int quoted, int flags) 4940varvalue(char *name, int quoted, int flags)
5011{ 4941{
5012 int num; 4942 int num;
@@ -5081,10 +5011,7 @@ param:
5081 */ 5011 */
5082 5012
5083static void 5013static void
5084recordregion(start, end, nulonly) 5014recordregion(int start, int end, int nulonly)
5085 int start;
5086 int end;
5087 int nulonly;
5088{ 5015{
5089 struct ifsregion *ifsp; 5016 struct ifsregion *ifsp;
5090 5017
@@ -5092,7 +5019,7 @@ recordregion(start, end, nulonly)
5092 ifsp = &ifsfirst; 5019 ifsp = &ifsfirst;
5093 } else { 5020 } else {
5094 INTOFF; 5021 INTOFF;
5095 ifsp = (struct ifsregion *)ckmalloc(sizeof (struct ifsregion)); 5022 ifsp = (struct ifsregion *)xmalloc(sizeof (struct ifsregion));
5096 ifsp->next = NULL; 5023 ifsp->next = NULL;
5097 ifslastp->next = ifsp; 5024 ifslastp->next = ifsp;
5098 INTON; 5025 INTON;
@@ -5111,10 +5038,8 @@ recordregion(start, end, nulonly)
5111 * searched for IFS characters have been stored by recordregion. 5038 * searched for IFS characters have been stored by recordregion.
5112 */ 5039 */
5113static void 5040static void
5114ifsbreakup(string, arglist) 5041ifsbreakup(char *string, struct arglist *arglist)
5115 char *string; 5042{
5116 struct arglist *arglist;
5117 {
5118 struct ifsregion *ifsp; 5043 struct ifsregion *ifsp;
5119 struct strlist *sp; 5044 struct strlist *sp;
5120 char *start; 5045 char *start;
@@ -5195,7 +5120,7 @@ ifsbreakup(string, arglist)
5195} 5120}
5196 5121
5197static void 5122static void
5198ifsfree() 5123ifsfree(void)
5199{ 5124{
5200 while (ifsfirst.next != NULL) { 5125 while (ifsfirst.next != NULL) {
5201 struct ifsregion *ifsp; 5126 struct ifsregion *ifsp;
@@ -5233,9 +5158,7 @@ addfname(const char *name)
5233 5158
5234#if defined(__GLIBC__) && __GLIBC__ >= 2 && !defined(FNMATCH_BROKEN) && !defined(GLOB_BROKEN) 5159#if defined(__GLIBC__) && __GLIBC__ >= 2 && !defined(FNMATCH_BROKEN) && !defined(GLOB_BROKEN)
5235static void 5160static void
5236expandmeta(str, flag) 5161expandmeta(struct strlist *str, int flag)
5237 struct strlist *str;
5238 int flag;
5239{ 5162{
5240 const char *p; 5163 const char *p;
5241 glob_t pglob; 5164 glob_t pglob;
@@ -5275,9 +5198,8 @@ nometa:
5275 * Add the result of glob(3) to the list. 5198 * Add the result of glob(3) to the list.
5276 */ 5199 */
5277 5200
5278static void 5201static inline void
5279addglob(pglob) 5202addglob(const glob_t *pglob)
5280 const glob_t *pglob;
5281{ 5203{
5282 char **p = pglob->gl_pathv; 5204 char **p = pglob->gl_pathv;
5283 5205
@@ -5292,9 +5214,7 @@ static char *expdir;
5292 5214
5293 5215
5294static void 5216static void
5295expandmeta(str, flag) 5217expandmeta(struct strlist str, int flag)
5296 struct strlist *str;
5297 int flag;
5298{ 5218{
5299 char *p; 5219 char *p;
5300 struct strlist **savelastp; 5220 struct strlist **savelastp;
@@ -5316,7 +5236,7 @@ expandmeta(str, flag)
5316 INTOFF; 5236 INTOFF;
5317 if (expdir == NULL) { 5237 if (expdir == NULL) {
5318 int i = strlen(str->text); 5238 int i = strlen(str->text);
5319 expdir = ckmalloc(i < 2048 ? 2048 : i); /* XXX */ 5239 expdir = xmalloc(i < 2048 ? 2048 : i); /* XXX */
5320 } 5240 }
5321 5241
5322 expmeta(expdir, str->text); 5242 expmeta(expdir, str->text);
@@ -5348,10 +5268,8 @@ nometa:
5348 */ 5268 */
5349 5269
5350static void 5270static void
5351expmeta(enddir, name) 5271expmeta(char *enddir, char *name)
5352 char *enddir; 5272{
5353 char *name;
5354 {
5355 char *p; 5273 char *p;
5356 const char *cp; 5274 const char *cp;
5357 char *q; 5275 char *q;
@@ -5484,9 +5402,8 @@ expmeta(enddir, name)
5484 */ 5402 */
5485 5403
5486static struct strlist * 5404static struct strlist *
5487expsort(str) 5405expsort(struct strlist *str)
5488 struct strlist *str; 5406{
5489 {
5490 int len; 5407 int len;
5491 struct strlist *sp; 5408 struct strlist *sp;
5492 5409
@@ -5498,9 +5415,7 @@ expsort(str)
5498 5415
5499 5416
5500static struct strlist * 5417static struct strlist *
5501msort(list, len) 5418msort(struct strlist *list, int len)
5502 struct strlist *list;
5503 int len;
5504{ 5419{
5505 struct strlist *p, *q = NULL; 5420 struct strlist *p, *q = NULL;
5506 struct strlist **lpp; 5421 struct strlist **lpp;
@@ -5743,8 +5658,7 @@ _rmescapes(char *str, int flag)
5743} 5658}
5744#else 5659#else
5745static void 5660static void
5746rmescapes(str) 5661rmescapes(char *str)
5747 char *str;
5748{ 5662{
5749 char *p, *q; 5663 char *p, *q;
5750 5664
@@ -5797,10 +5711,8 @@ casematch(union node *pattern, const char *val)
5797 */ 5711 */
5798 5712
5799static char * 5713static char *
5800cvtnum(num, buf) 5714cvtnum(int num, char *buf)
5801 int num; 5715{
5802 char *buf;
5803 {
5804 int len; 5716 int len;
5805 5717
5806 CHECKSTRSPACE(32, buf); 5718 CHECKSTRSPACE(32, buf);
@@ -5811,9 +5723,7 @@ cvtnum(num, buf)
5811/* 5723/*
5812 * Editline and history functions (and glue). 5724 * Editline and history functions (and glue).
5813 */ 5725 */
5814static int histcmd(argc, argv) 5726static int histcmd(int argc, char **argv)
5815 int argc;
5816 char **argv;
5817{ 5727{
5818 error("not compiled with history support"); 5728 error("not compiled with history support");
5819 /* NOTREACHED */ 5729 /* NOTREACHED */
@@ -6133,7 +6043,7 @@ pushstring(char *s, int len, void *ap)
6133 INTOFF; 6043 INTOFF;
6134/*dprintf("*** calling pushstring: %s, %d\n", s, len);*/ 6044/*dprintf("*** calling pushstring: %s, %d\n", s, len);*/
6135 if (parsefile->strpush) { 6045 if (parsefile->strpush) {
6136 sp = ckmalloc(sizeof (struct strpush)); 6046 sp = xmalloc(sizeof (struct strpush));
6137 sp->prev = parsefile->strpush; 6047 sp->prev = parsefile->strpush;
6138 parsefile->strpush = sp; 6048 parsefile->strpush = sp;
6139 } else 6049 } else
@@ -6177,14 +6087,15 @@ setinputstring(char *string)
6177 */ 6087 */
6178 6088
6179static void 6089static void
6180pushfile(void) { 6090pushfile(void)
6091{
6181 struct parsefile *pf; 6092 struct parsefile *pf;
6182 6093
6183 parsefile->nleft = parsenleft; 6094 parsefile->nleft = parsenleft;
6184 parsefile->lleft = parselleft; 6095 parsefile->lleft = parselleft;
6185 parsefile->nextc = parsenextc; 6096 parsefile->nextc = parsenextc;
6186 parsefile->linno = plinno; 6097 parsefile->linno = plinno;
6187 pf = (struct parsefile *)ckmalloc(sizeof (struct parsefile)); 6098 pf = (struct parsefile *)xmalloc(sizeof (struct parsefile));
6188 pf->prev = parsefile; 6099 pf->prev = parsefile;
6189 pf->fd = -1; 6100 pf->fd = -1;
6190 pf->strpush = NULL; 6101 pf->strpush = NULL;
@@ -6289,9 +6200,7 @@ static void setjobctl(int enable)
6289 6200
6290#ifdef JOBS 6201#ifdef JOBS
6291static int 6202static int
6292killcmd(argc, argv) 6203killcmd(int argc, char **argv)
6293 int argc;
6294 char **argv;
6295{ 6204{
6296 int signo = -1; 6205 int signo = -1;
6297 int list = 0; 6206 int list = 0;
@@ -6351,13 +6260,13 @@ usage:
6351 for (i = 1; i < NSIG; i++) { 6260 for (i = 1; i < NSIG; i++) {
6352 name = u_signal_names(0, &i, 1); 6261 name = u_signal_names(0, &i, 1);
6353 if(name) 6262 if(name)
6354 printf(snlfmt, name); 6263 puts(name);
6355 } 6264 }
6356 return 0; 6265 return 0;
6357 } 6266 }
6358 name = u_signal_names(*argptr, &signo, -1); 6267 name = u_signal_names(*argptr, &signo, -1);
6359 if (name) 6268 if (name)
6360 printf(snlfmt, name); 6269 puts(name);
6361 else 6270 else
6362 error("invalid signal number or exit status: %s", 6271 error("invalid signal number or exit status: %s",
6363 *argptr); 6272 *argptr);
@@ -6381,9 +6290,7 @@ usage:
6381} 6290}
6382 6291
6383static int 6292static int
6384fgcmd(argc, argv) 6293fgcmd(int argc, char **argv)
6385 int argc;
6386 char **argv;
6387{ 6294{
6388 struct job *jp; 6295 struct job *jp;
6389 int pgrp; 6296 int pgrp;
@@ -6407,9 +6314,7 @@ fgcmd(argc, argv)
6407 6314
6408 6315
6409static int 6316static int
6410bgcmd(argc, argv) 6317bgcmd(int argc, char **argv)
6411 int argc;
6412 char **argv;
6413{ 6318{
6414 struct job *jp; 6319 struct job *jp;
6415 6320
@@ -6424,8 +6329,7 @@ bgcmd(argc, argv)
6424 6329
6425 6330
6426static void 6331static void
6427restartjob(jp) 6332restartjob(struct job *jp)
6428 struct job *jp;
6429{ 6333{
6430 struct procstat *ps; 6334 struct procstat *ps;
6431 int i; 6335 int i;
@@ -6448,9 +6352,7 @@ static void showjobs(int change);
6448 6352
6449 6353
6450static int 6354static int
6451jobscmd(argc, argv) 6355jobscmd(int argc, char **argv)
6452 int argc;
6453 char **argv;
6454{ 6356{
6455 showjobs(0); 6357 showjobs(0);
6456 return 0; 6358 return 0;
@@ -6467,8 +6369,7 @@ jobscmd(argc, argv)
6467 */ 6369 */
6468 6370
6469static void 6371static void
6470showjobs(change) 6372showjobs(int change)
6471 int change;
6472{ 6373{
6473 int jobno; 6374 int jobno;
6474 int procno; 6375 int procno;
@@ -6564,9 +6465,7 @@ freejob(struct job *jp)
6564 6465
6565 6466
6566static int 6467static int
6567waitcmd(argc, argv) 6468waitcmd(int argc, char **argv)
6568 int argc;
6569 char **argv;
6570{ 6469{
6571 struct job *job; 6470 struct job *job;
6572 int status, retval; 6471 int status, retval;
@@ -6687,9 +6586,9 @@ makejob(const union node *node, int nprocs)
6687 if (--i < 0) { 6586 if (--i < 0) {
6688 INTOFF; 6587 INTOFF;
6689 if (njobs == 0) { 6588 if (njobs == 0) {
6690 jobtab = ckmalloc(4 * sizeof jobtab[0]); 6589 jobtab = xmalloc(4 * sizeof jobtab[0]);
6691 } else { 6590 } else {
6692 jp = ckmalloc((njobs + 4) * sizeof jobtab[0]); 6591 jp = xmalloc((njobs + 4) * sizeof jobtab[0]);
6693 memcpy(jp, jobtab, njobs * sizeof jp[0]); 6592 memcpy(jp, jobtab, njobs * sizeof jp[0]);
6694 /* Relocate `ps' pointers */ 6593 /* Relocate `ps' pointers */
6695 for (i = 0; i < njobs; i++) 6594 for (i = 0; i < njobs; i++)
@@ -6715,7 +6614,7 @@ makejob(const union node *node, int nprocs)
6715 jp->jobctl = jobctl; 6614 jp->jobctl = jobctl;
6716#endif 6615#endif
6717 if (nprocs > 1) { 6616 if (nprocs > 1) {
6718 jp->ps = ckmalloc(nprocs * sizeof (struct procstat)); 6617 jp->ps = xmalloc(nprocs * sizeof (struct procstat));
6719 } else { 6618 } else {
6720 jp->ps = &jp->ps0; 6619 jp->ps = &jp->ps0;
6721 } 6620 }
@@ -7507,7 +7406,7 @@ commandtext(const union node *n)
7507{ 7406{
7508 char *name; 7407 char *name;
7509 7408
7510 cmdnextc = name = ckmalloc(MAXCMDTEXT); 7409 cmdnextc = name = xmalloc(MAXCMDTEXT);
7511 cmdnleft = MAXCMDTEXT - 4; 7410 cmdnleft = MAXCMDTEXT - 4;
7512 cmdtxt(n); 7411 cmdtxt(n);
7513 *cmdnextc = '\0'; 7412 *cmdnextc = '\0';
@@ -7606,9 +7505,7 @@ static void procargs (int, char **);
7606 */ 7505 */
7607 7506
7608int 7507int
7609ash_main(argc, argv) 7508ash_main(int argc, char **argv)
7610 int argc;
7611 char **argv;
7612{ 7509{
7613 struct jmploc jmploc; 7510 struct jmploc jmploc;
7614 struct stackmark smark; 7511 struct stackmark smark;
@@ -7788,8 +7685,7 @@ cmdloop(int top)
7788 */ 7685 */
7789 7686
7790static void 7687static void
7791read_profile(name) 7688read_profile(const char *name)
7792 const char *name;
7793{ 7689{
7794 int fd; 7690 int fd;
7795 int xflag_save; 7691 int xflag_save;
@@ -7870,16 +7766,14 @@ find_dot_file(char *mybasename)
7870} 7766}
7871 7767
7872static int 7768static int
7873dotcmd(argc, argv) 7769dotcmd(int argc, char **argv)
7874 int argc;
7875 char **argv;
7876{ 7770{
7877 struct strlist *sp; 7771 struct strlist *sp;
7878 volatile struct shparam saveparam; 7772 volatile struct shparam saveparam;
7879 exitstatus = 0; 7773 exitstatus = 0;
7880 7774
7881 for (sp = cmdenviron; sp ; sp = sp->next) 7775 for (sp = cmdenviron; sp ; sp = sp->next)
7882 setvareq(savestr(sp->text), VSTRFIXED|VTEXTFIXED); 7776 setvareq(xstrdup(sp->text), VSTRFIXED|VTEXTFIXED);
7883 7777
7884 if (argc >= 2) { /* That's what SVR2 does */ 7778 if (argc >= 2) { /* That's what SVR2 does */
7885 char *fullname; 7779 char *fullname;
@@ -7912,9 +7806,7 @@ dotcmd(argc, argv)
7912 7806
7913 7807
7914static int 7808static int
7915exitcmd(argc, argv) 7809exitcmd(int argc, char **argv)
7916 int argc;
7917 char **argv;
7918{ 7810{
7919 if (stoppedjobs()) 7811 if (stoppedjobs())
7920 return 0; 7812 return 0;
@@ -7940,7 +7832,7 @@ stalloc(int nbytes)
7940 if (blocksize < MINSIZE) 7832 if (blocksize < MINSIZE)
7941 blocksize = MINSIZE; 7833 blocksize = MINSIZE;
7942 INTOFF; 7834 INTOFF;
7943 sp = ckmalloc(sizeof(struct stack_block) - MINSIZE + blocksize); 7835 sp = xmalloc(sizeof(struct stack_block) - MINSIZE + blocksize);
7944 sp->prev = stackp; 7836 sp->prev = stackp;
7945 stacknxt = sp->space; 7837 stacknxt = sp->space;
7946 stacknleft = blocksize; 7838 stacknleft = blocksize;
@@ -8024,7 +7916,7 @@ growstackblock(void) {
8024 oldstackp = stackp; 7916 oldstackp = stackp;
8025 sp = stackp; 7917 sp = stackp;
8026 stackp = sp->prev; 7918 stackp = sp->prev;
8027 sp = ckrealloc((pointer)sp, sizeof(struct stack_block) - MINSIZE + newlen); 7919 sp = xrealloc((pointer)sp, sizeof(struct stack_block) - MINSIZE + newlen);
8028 sp->prev = stackp; 7920 sp->prev = stackp;
8029 stackp = sp; 7921 stackp = sp;
8030 stacknxt = sp->space; 7922 stacknxt = sp->space;
@@ -8225,9 +8117,7 @@ readcmd(int argc, char **argv)
8225 8117
8226 8118
8227static int 8119static int
8228umaskcmd(argc, argv) 8120umaskcmd(int argc, char **argv)
8229 int argc;
8230 char **argv;
8231{ 8121{
8232 static const char permuser[3] = "ugo"; 8122 static const char permuser[3] = "ugo";
8233 static const char permmode[3] = "rwx"; 8123 static const char permmode[3] = "rwx";
@@ -8345,9 +8235,7 @@ static const struct limits limits[] = {
8345}; 8235};
8346 8236
8347static int 8237static int
8348ulimitcmd(argc, argv) 8238ulimitcmd(int argc, char **argv)
8349 int argc;
8350 char **argv;
8351{ 8239{
8352 static const char unlimited_string[] = "unlimited"; 8240 static const char unlimited_string[] = "unlimited";
8353 int c; 8241 int c;
@@ -8530,7 +8418,8 @@ number(const char *s)
8530 */ 8418 */
8531 8419
8532static char * 8420static char *
8533single_quote(const char *s) { 8421single_quote(const char *s)
8422{
8534 char *p; 8423 char *p;
8535 8424
8536 STARTSTACKSTR(p); 8425 STARTSTACKSTR(p);
@@ -8594,7 +8483,7 @@ sstrdup(const char *p)
8594 8483
8595static void sizenodelist (const struct nodelist *); 8484static void sizenodelist (const struct nodelist *);
8596static struct nodelist *copynodelist (const struct nodelist *); 8485static struct nodelist *copynodelist (const struct nodelist *);
8597static char *nodesavestr (const char *); 8486static char *nodexstrdup (const char *);
8598 8487
8599#define CALCSIZE_TABLE 8488#define CALCSIZE_TABLE
8600#define COPYNODE_TABLE 8489#define COPYNODE_TABLE
@@ -8736,7 +8625,7 @@ copynode(const union node *n)
8736 if (!(*p & NODE_MBRMASK)) { /* standard node */ 8625 if (!(*p & NODE_MBRMASK)) { /* standard node */
8737 *((union node **)nn) = copynode(*((const union node **) no)); 8626 *((union node **)nn) = copynode(*((const union node **) no));
8738 } else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */ 8627 } else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
8739 *((const char **)nn) = nodesavestr(*((const char **)no)); 8628 *((const char **)nn) = nodexstrdup(*((const char **)no));
8740 } else if (*p & NODE_NODELIST) { /* nodelist */ 8629 } else if (*p & NODE_NODELIST) { /* nodelist */
8741 *((struct nodelist **)nn) 8630 *((struct nodelist **)nn)
8742 = copynodelist(*((const struct nodelist **) no)); 8631 = copynodelist(*((const struct nodelist **) no));
@@ -8787,7 +8676,7 @@ copynode(const union node *n)
8787 new->nif.test = copynode(n->nif.test); 8676 new->nif.test = copynode(n->nif.test);
8788 break; 8677 break;
8789 case NFOR: 8678 case NFOR:
8790 new->nfor.var = nodesavestr(n->nfor.var); 8679 new->nfor.var = nodexstrdup(n->nfor.var);
8791 new->nfor.body = copynode(n->nfor.body); 8680 new->nfor.body = copynode(n->nfor.body);
8792 new->nfor.args = copynode(n->nfor.args); 8681 new->nfor.args = copynode(n->nfor.args);
8793 break; 8682 break;
@@ -8803,7 +8692,7 @@ copynode(const union node *n)
8803 case NDEFUN: 8692 case NDEFUN:
8804 case NARG: 8693 case NARG:
8805 new->narg.backquote = copynodelist(n->narg.backquote); 8694 new->narg.backquote = copynodelist(n->narg.backquote);
8806 new->narg.text = nodesavestr(n->narg.text); 8695 new->narg.text = nodexstrdup(n->narg.text);
8807 new->narg.next = copynode(n->narg.next); 8696 new->narg.next = copynode(n->narg.next);
8808 break; 8697 break;
8809 case NTO: 8698 case NTO:
@@ -8971,7 +8860,7 @@ copynodelist(const struct nodelist *lp)
8971 8860
8972 8861
8973static char * 8862static char *
8974nodesavestr(const char *s) 8863nodexstrdup(const char *s)
8975{ 8864{
8976 const char *p = s; 8865 const char *p = s;
8977 char *q = funcstring; 8866 char *q = funcstring;
@@ -8993,9 +8882,7 @@ static int getopts (char *, char *, char **, int *, int *);
8993 */ 8882 */
8994 8883
8995static void 8884static void
8996procargs(argc, argv) 8885procargs(int argc, char **argv)
8997 int argc;
8998 char **argv;
8999{ 8886{
9000 int i; 8887 int i;
9001 8888
@@ -9154,9 +9041,9 @@ setparam(char **argv)
9154 int nparam; 9041 int nparam;
9155 9042
9156 for (nparam = 0 ; argv[nparam] ; nparam++); 9043 for (nparam = 0 ; argv[nparam] ; nparam++);
9157 ap = newparam = ckmalloc((nparam + 1) * sizeof *ap); 9044 ap = newparam = xmalloc((nparam + 1) * sizeof *ap);
9158 while (*argv) { 9045 while (*argv) {
9159 *ap++ = savestr(*argv++); 9046 *ap++ = xstrdup(*argv++);
9160 } 9047 }
9161 *ap = NULL; 9048 *ap = NULL;
9162 freeparam(&shellparam); 9049 freeparam(&shellparam);
@@ -9191,9 +9078,7 @@ freeparam(volatile struct shparam *param)
9191 */ 9078 */
9192 9079
9193static int 9080static int
9194shiftcmd(argc, argv) 9081shiftcmd(int argc, char **argv)
9195 int argc;
9196 char **argv;
9197{ 9082{
9198 int n; 9083 int n;
9199 char **ap1, **ap2; 9084 char **ap1, **ap2;
@@ -9224,9 +9109,7 @@ shiftcmd(argc, argv)
9224 */ 9109 */
9225 9110
9226static int 9111static int
9227setcmd(argc, argv) 9112setcmd(int argc, char **argv)
9228 int argc;
9229 char **argv;
9230{ 9113{
9231 if (argc == 1) 9114 if (argc == 1)
9232 return showvarscmd(argc, argv); 9115 return showvarscmd(argc, argv);
@@ -9272,9 +9155,7 @@ static void change_lc_ctype(const char *value)
9272 */ 9155 */
9273 9156
9274static int 9157static int
9275getoptscmd(argc, argv) 9158getoptscmd(int argc, char **argv)
9276 int argc;
9277 char **argv;
9278{ 9159{
9279 char **optbase; 9160 char **optbase;
9280 9161
@@ -9304,9 +9185,7 @@ getoptscmd(argc, argv)
9304 */ 9185 */
9305 9186
9306static int 9187static int
9307setvarsafe(name, val, flags) 9188setvarsafe(const char *name, const char *val, int flags)
9308 const char *name, *val;
9309 int flags;
9310{ 9189{
9311 struct jmploc jmploc; 9190 struct jmploc jmploc;
9312 struct jmploc *volatile savehandler = handler; 9191 struct jmploc *volatile savehandler = handler;
@@ -9326,12 +9205,7 @@ setvarsafe(name, val, flags)
9326} 9205}
9327 9206
9328static int 9207static int
9329getopts(optstr, optvar, optfirst, myoptind, optoff) 9208getopts(char *optstr, char *optvar, char **optfirst, int *myoptind, int *optoff)
9330 char *optstr;
9331 char *optvar;
9332 char **optfirst;
9333 int *myoptind;
9334 int *optoff;
9335{ 9209{
9336 char *p, *q; 9210 char *p, *q;
9337 char c = '?'; 9211 char c = '?';
@@ -9591,8 +9465,7 @@ parsecmd(int interact)
9591 9465
9592 9466
9593static union node * 9467static union node *
9594list(nlflag) 9468list(int nlflag)
9595 int nlflag;
9596{ 9469{
9597 union node *n1, *n2, *n3; 9470 union node *n1, *n2, *n3;
9598 int tok; 9471 int tok;
@@ -10853,7 +10726,7 @@ parsebackq: {
10853 str = NULL; 10726 str = NULL;
10854 savelen = out - stackblock(); 10727 savelen = out - stackblock();
10855 if (savelen > 0) { 10728 if (savelen > 0) {
10856 str = ckmalloc(savelen); 10729 str = xmalloc(savelen);
10857 memcpy(str, stackblock(), savelen); 10730 memcpy(str, stackblock(), savelen);
10858 } 10731 }
10859 savehandler = handler; 10732 savehandler = handler;
@@ -11012,9 +10885,8 @@ parsearith: {
11012 */ 10885 */
11013 10886
11014static int 10887static int
11015noexpand(text) 10888noexpand(char *text)
11016 char *text; 10889{
11017 {
11018 char *p; 10890 char *p;
11019 char c; 10891 char c;
11020 10892
@@ -11059,8 +10931,7 @@ goodname(const char *name)
11059 */ 10931 */
11060 10932
11061static void 10933static void
11062synexpect(token) 10934synexpect(int token)
11063 int token;
11064{ 10935{
11065 char msg[64]; 10936 char msg[64];
11066 int l; 10937 int l;
@@ -11308,7 +11179,7 @@ redirect(union node *redir, int flags)
11308 int fd1dup = flags & REDIR_BACKQ;; /* stdout `cmd` redir to pipe */ 11179 int fd1dup = flags & REDIR_BACKQ;; /* stdout `cmd` redir to pipe */
11309 11180
11310 if (flags & REDIR_PUSH) { 11181 if (flags & REDIR_PUSH) {
11311 sv = ckmalloc(sizeof (struct redirtab)); 11182 sv = xmalloc(sizeof (struct redirtab));
11312 for (i = 0 ; i < 10 ; i++) 11183 for (i = 0 ; i < 10 ; i++)
11313 sv->renamed[i] = EMPTY; 11184 sv->renamed[i] = EMPTY;
11314 sv->next = redirlist; 11185 sv->next = redirlist;
@@ -11440,9 +11311,7 @@ clearredir(void) {
11440 */ 11311 */
11441 11312
11442static int 11313static int
11443dup_as_newfd(from, to) 11314dup_as_newfd(int from, int to)
11444 int from;
11445 int to;
11446{ 11315{
11447 int newfd; 11316 int newfd;
11448 11317
@@ -11477,11 +11346,7 @@ showtree(n)
11477 11346
11478 11347
11479static void 11348static void
11480shtree(n, ind, pfx, fp) 11349shtree(union node *n, int ind, char *pfx, FILE *fp)
11481 union node *n;
11482 int ind;
11483 char *pfx;
11484 FILE *fp;
11485{ 11350{
11486 struct nodelist *lp; 11351 struct nodelist *lp;
11487 const char *s; 11352 const char *s;
@@ -11532,9 +11397,7 @@ binop:
11532 11397
11533 11398
11534static void 11399static void
11535shcmd(cmd, fp) 11400shcmd(union node *cmd, FILE *fp)
11536 union node *cmd;
11537 FILE *fp;
11538{ 11401{
11539 union node *np; 11402 union node *np;
11540 int first; 11403 int first;
@@ -11585,10 +11448,8 @@ shcmd(cmd, fp)
11585} 11448}
11586 11449
11587static void 11450static void
11588sharg(arg, fp) 11451sharg(union node *arg, FILE *fp)
11589 union node *arg; 11452{
11590 FILE *fp;
11591 {
11592 char *p; 11453 char *p;
11593 struct nodelist *bqlist; 11454 struct nodelist *bqlist;
11594 int subtype; 11455 int subtype;
@@ -11672,10 +11533,7 @@ sharg(arg, fp)
11672 11533
11673 11534
11674static void 11535static void
11675indent(amount, pfx, fp) 11536indent(int amount, char *pfx, FILE *fp)
11676 int amount;
11677 char *pfx;
11678 FILE *fp;
11679{ 11537{
11680 int i; 11538 int i;
11681 11539
@@ -11697,8 +11555,7 @@ static int debug = 0;
11697 11555
11698 11556
11699static void 11557static void
11700trputc(c) 11558trputc(int c)
11701 int c;
11702{ 11559{
11703 if (tracefile == NULL) 11560 if (tracefile == NULL)
11704 return; 11561 return;
@@ -11722,8 +11579,7 @@ trace(const char *fmt, ...)
11722 11579
11723 11580
11724static void 11581static void
11725trputs(s) 11582trputs(const char *s)
11726 const char *s;
11727{ 11583{
11728 if (tracefile == NULL) 11584 if (tracefile == NULL)
11729 return; 11585 return;
@@ -11734,8 +11590,7 @@ trputs(s)
11734 11590
11735 11591
11736static void 11592static void
11737trstring(s) 11593trstring(char *s)
11738 char *s;
11739{ 11594{
11740 char *p; 11595 char *p;
11741 char c; 11596 char c;
@@ -11775,8 +11630,7 @@ backslash: putc('\\', tracefile);
11775 11630
11776 11631
11777static void 11632static void
11778trargs(ap) 11633trargs(char **ap)
11779 char **ap;
11780{ 11634{
11781 if (tracefile == NULL) 11635 if (tracefile == NULL)
11782 return; 11636 return;
@@ -11792,7 +11646,8 @@ trargs(ap)
11792 11646
11793 11647
11794static void 11648static void
11795opentrace() { 11649opentrace()
11650{
11796 char s[100]; 11651 char s[100];
11797#ifdef O_APPEND 11652#ifdef O_APPEND
11798 int flags; 11653 int flags;
@@ -11832,9 +11687,7 @@ opentrace() {
11832 */ 11687 */
11833 11688
11834static int 11689static int
11835trapcmd(argc, argv) 11690trapcmd(int argc, char **argv)
11836 int argc;
11837 char **argv;
11838{ 11691{
11839 char *action; 11692 char *action;
11840 char **ap; 11693 char **ap;
@@ -11871,7 +11724,7 @@ trapcmd(argc, argv)
11871 if (action[0] == '-' && action[1] == '\0') 11724 if (action[0] == '-' && action[1] == '\0')
11872 action = NULL; 11725 action = NULL;
11873 else 11726 else
11874 action = savestr(action); 11727 action = xstrdup(action);
11875 } 11728 }
11876 if (trap[signo]) 11729 if (trap[signo])
11877 ckfree(trap[signo]); 11730 ckfree(trap[signo]);
@@ -11974,8 +11827,7 @@ setsignal(int signo)
11974 */ 11827 */
11975 11828
11976static void 11829static void
11977ignoresig(signo) 11830ignoresig(int signo)
11978 int signo;
11979{ 11831{
11980 if (sigmode[signo - 1] != S_IGN && sigmode[signo - 1] != S_HARD_IGN) { 11832 if (sigmode[signo - 1] != S_IGN && sigmode[signo - 1] != S_HARD_IGN) {
11981 signal(signo, SIG_IGN); 11833 signal(signo, SIG_IGN);
@@ -12113,9 +11965,7 @@ initvar() {
12113 */ 11965 */
12114 11966
12115static void 11967static void
12116setvar(name, val, flags) 11968setvar(const char *name, const char *val, int flags)
12117 const char *name, *val;
12118 int flags;
12119{ 11969{
12120 const char *p; 11970 const char *p;
12121 int len; 11971 int len;
@@ -12147,7 +11997,7 @@ setvar(name, val, flags)
12147 len += vallen = strlen(val); 11997 len += vallen = strlen(val);
12148 } 11998 }
12149 INTOFF; 11999 INTOFF;
12150 nameeq = ckmalloc(len); 12000 nameeq = xmalloc(len);
12151 memcpy(nameeq, name, namelen); 12001 memcpy(nameeq, name, namelen);
12152 nameeq[namelen] = '='; 12002 nameeq[namelen] = '=';
12153 if (val) { 12003 if (val) {
@@ -12169,9 +12019,7 @@ setvar(name, val, flags)
12169 */ 12019 */
12170 12020
12171static void 12021static void
12172setvareq(s, flags) 12022setvareq(char *s, int flags)
12173 char *s;
12174 int flags;
12175{ 12023{
12176 struct var *vp, **vpp; 12024 struct var *vp, **vpp;
12177 12025
@@ -12206,7 +12054,7 @@ setvareq(s, flags)
12206 return; 12054 return;
12207 } 12055 }
12208 /* not found */ 12056 /* not found */
12209 vp = ckmalloc(sizeof (*vp)); 12057 vp = xmalloc(sizeof (*vp));
12210 vp->flags = flags; 12058 vp->flags = flags;
12211 vp->text = s; 12059 vp->text = s;
12212 vp->next = *vpp; 12060 vp->next = *vpp;
@@ -12221,14 +12069,13 @@ setvareq(s, flags)
12221 */ 12069 */
12222 12070
12223static void 12071static void
12224listsetvar(mylist) 12072listsetvar(struct strlist *mylist)
12225 struct strlist *mylist; 12073{
12226 {
12227 struct strlist *lp; 12074 struct strlist *lp;
12228 12075
12229 INTOFF; 12076 INTOFF;
12230 for (lp = mylist ; lp ; lp = lp->next) { 12077 for (lp = mylist ; lp ; lp = lp->next) {
12231 setvareq(savestr(lp->text), 0); 12078 setvareq(xstrdup(lp->text), 0);
12232 } 12079 }
12233 INTON; 12080 INTON;
12234} 12081}
@@ -12240,8 +12087,7 @@ listsetvar(mylist)
12240 */ 12087 */
12241 12088
12242static const char * 12089static const char *
12243lookupvar(name) 12090lookupvar(const char *name)
12244 const char *name;
12245{ 12091{
12246 struct var *v; 12092 struct var *v;
12247 12093
@@ -12322,7 +12168,7 @@ shprocvar(void) {
12322 ckfree(vp); 12168 ckfree(vp);
12323 } else { 12169 } else {
12324 if (vp->flags & VSTACK) { 12170 if (vp->flags & VSTACK) {
12325 vp->text = savestr(vp->text); 12171 vp->text = xstrdup(vp->text);
12326 vp->flags &=~ VSTACK; 12172 vp->flags &=~ VSTACK;
12327 } 12173 }
12328 prev = &vp->next; 12174 prev = &vp->next;
@@ -12341,9 +12187,7 @@ shprocvar(void) {
12341 */ 12187 */
12342 12188
12343static int 12189static int
12344showvarscmd(argc, argv) 12190showvarscmd(int argc, char **argv)
12345 int argc;
12346 char **argv;
12347{ 12191{
12348 showvars(nullstr, VUNSET, VUNSET); 12192 showvars(nullstr, VUNSET, VUNSET);
12349 return 0; 12193 return 0;
@@ -12356,9 +12200,7 @@ showvarscmd(argc, argv)
12356 */ 12200 */
12357 12201
12358static int 12202static int
12359exportcmd(argc, argv) 12203exportcmd(int argc, char **argv)
12360 int argc;
12361 char **argv;
12362{ 12204{
12363 struct var *vp; 12205 struct var *vp;
12364 char *name; 12206 char *name;
@@ -12395,9 +12237,7 @@ found:;
12395/* funcnest nonzero if we are currently evaluating a function */ 12237/* funcnest nonzero if we are currently evaluating a function */
12396 12238
12397static int 12239static int
12398localcmd(argc, argv) 12240localcmd(int argc, char **argv)
12399 int argc;
12400 char **argv;
12401{ 12241{
12402 char *name; 12242 char *name;
12403 12243
@@ -12418,18 +12258,17 @@ localcmd(argc, argv)
12418 */ 12258 */
12419 12259
12420static void 12260static void
12421mklocal(name) 12261mklocal(char *name)
12422 char *name; 12262{
12423 {
12424 struct localvar *lvp; 12263 struct localvar *lvp;
12425 struct var **vpp; 12264 struct var **vpp;
12426 struct var *vp; 12265 struct var *vp;
12427 12266
12428 INTOFF; 12267 INTOFF;
12429 lvp = ckmalloc(sizeof (struct localvar)); 12268 lvp = xmalloc(sizeof (struct localvar));
12430 if (name[0] == '-' && name[1] == '\0') { 12269 if (name[0] == '-' && name[1] == '\0') {
12431 char *p; 12270 char *p;
12432 p = ckmalloc(sizeof optet_vals); 12271 p = xmalloc(sizeof optet_vals);
12433 lvp->text = memcpy(p, optet_vals, sizeof optet_vals); 12272 lvp->text = memcpy(p, optet_vals, sizeof optet_vals);
12434 vp = NULL; 12273 vp = NULL;
12435 } else { 12274 } else {
@@ -12437,7 +12276,7 @@ mklocal(name)
12437 vp = *findvar(vpp, name); 12276 vp = *findvar(vpp, name);
12438 if (vp == NULL) { 12277 if (vp == NULL) {
12439 if (strchr(name, '=')) 12278 if (strchr(name, '='))
12440 setvareq(savestr(name), VSTRFIXED); 12279 setvareq(xstrdup(name), VSTRFIXED);
12441 else 12280 else
12442 setvar(name, NULL, VSTRFIXED); 12281 setvar(name, NULL, VSTRFIXED);
12443 vp = *vpp; /* the new variable */ 12282 vp = *vpp; /* the new variable */
@@ -12448,7 +12287,7 @@ mklocal(name)
12448 lvp->flags = vp->flags; 12287 lvp->flags = vp->flags;
12449 vp->flags |= VSTRFIXED|VTEXTFIXED; 12288 vp->flags |= VSTRFIXED|VTEXTFIXED;
12450 if (strchr(name, '=')) 12289 if (strchr(name, '='))
12451 setvareq(savestr(name), 0); 12290 setvareq(xstrdup(name), 0);
12452 } 12291 }
12453 } 12292 }
12454 lvp->vp = vp; 12293 lvp->vp = vp;
@@ -12487,9 +12326,7 @@ poplocalvars() {
12487 12326
12488 12327
12489static int 12328static int
12490setvarcmd(argc, argv) 12329setvarcmd(int argc, char **argv)
12491 int argc;
12492 char **argv;
12493{ 12330{
12494 if (argc <= 2) 12331 if (argc <= 2)
12495 return unsetcmd(argc, argv); 12332 return unsetcmd(argc, argv);
@@ -12508,9 +12345,7 @@ setvarcmd(argc, argv)
12508 */ 12345 */
12509 12346
12510static int 12347static int
12511unsetcmd(argc, argv) 12348unsetcmd(int argc, char **argv)
12512 int argc;
12513 char **argv;
12514{ 12349{
12515 char **ap; 12350 char **ap;
12516 int i; 12351 int i;
@@ -12646,7 +12481,7 @@ findvar(struct var **vpp, const char *name)
12646/* 12481/*
12647 * Copyright (c) 1999 Herbert Xu <herbert@debian.org> 12482 * Copyright (c) 1999 Herbert Xu <herbert@debian.org>
12648 * This file contains code for the times builtin. 12483 * This file contains code for the times builtin.
12649 * $Id: ash.c,v 1.36 2001/11/12 16:57:26 kraai Exp $ 12484 * $Id: ash.c,v 1.37 2001/12/06 03:37:38 aaronl Exp $
12650 */ 12485 */
12651static int timescmd (int argc, char **argv) 12486static int timescmd (int argc, char **argv)
12652{ 12487{
@@ -12695,7 +12530,7 @@ int letcmd(int argc, char **argv)
12695 return 0; 12530 return 0;
12696 } 12531 }
12697 snprintf(p, 12, "%ld", result); 12532 snprintf(p, 12, "%ld", result);
12698 setvar(argv[1], savestr(p), 0); 12533 setvar(argv[1], xstrdup(p), 0);
12699 } else if (argc >= 3) 12534 } else if (argc >= 3)
12700 synerror("invalid operand"); 12535 synerror("invalid operand");
12701 return !result; 12536 return !result;