diff options
author | jilles <jilles@FreeBSD.org> | 2009-12-24 18:41:14 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2009-12-24 18:41:14 +0000 |
commit | 8e458de8523a07bb3be5f06ed227236cb12be7f4 (patch) | |
tree | 3810323287749c3a09fadeeed64429a5bf2fbb4d /bin/sh | |
parent | ff49e8168bd001a89cc6ca577b7b33399eb2c409 (diff) | |
download | FreeBSD-src-8e458de8523a07bb3be5f06ed227236cb12be7f4.zip FreeBSD-src-8e458de8523a07bb3be5f06ed227236cb12be7f4.tar.gz |
sh: Constify various strings.
Most of this is adding const keywords, but setvar() in var.c had to be
changed somewhat more.
Diffstat (limited to 'bin/sh')
-rw-r--r-- | bin/sh/alias.c | 6 | ||||
-rw-r--r-- | bin/sh/alias.h | 2 | ||||
-rw-r--r-- | bin/sh/arith.h | 4 | ||||
-rw-r--r-- | bin/sh/arith.y | 8 | ||||
-rw-r--r-- | bin/sh/cd.c | 2 | ||||
-rw-r--r-- | bin/sh/exec.c | 32 | ||||
-rw-r--r-- | bin/sh/exec.h | 16 | ||||
-rw-r--r-- | bin/sh/expand.c | 12 | ||||
-rw-r--r-- | bin/sh/expand.h | 4 | ||||
-rw-r--r-- | bin/sh/histedit.c | 6 | ||||
-rw-r--r-- | bin/sh/input.c | 2 | ||||
-rw-r--r-- | bin/sh/input.h | 2 | ||||
-rw-r--r-- | bin/sh/mail.c | 2 | ||||
-rw-r--r-- | bin/sh/main.c | 4 | ||||
-rw-r--r-- | bin/sh/main.h | 2 | ||||
-rw-r--r-- | bin/sh/memalloc.c | 2 | ||||
-rw-r--r-- | bin/sh/memalloc.h | 2 | ||||
-rw-r--r-- | bin/sh/myhistedit.h | 4 | ||||
-rw-r--r-- | bin/sh/options.c | 5 | ||||
-rw-r--r-- | bin/sh/options.h | 2 | ||||
-rw-r--r-- | bin/sh/output.c | 2 | ||||
-rw-r--r-- | bin/sh/output.h | 2 | ||||
-rw-r--r-- | bin/sh/parser.c | 4 | ||||
-rw-r--r-- | bin/sh/parser.h | 2 | ||||
-rw-r--r-- | bin/sh/show.c | 2 | ||||
-rw-r--r-- | bin/sh/show.h | 2 | ||||
-rw-r--r-- | bin/sh/var.c | 39 | ||||
-rw-r--r-- | bin/sh/var.h | 10 |
28 files changed, 92 insertions, 90 deletions
diff --git a/bin/sh/alias.c b/bin/sh/alias.c index 2edfe95..00b7fa7 100644 --- a/bin/sh/alias.c +++ b/bin/sh/alias.c @@ -52,13 +52,13 @@ __FBSDID("$FreeBSD$"); STATIC struct alias *atab[ATABSIZE]; STATIC int aliases; -STATIC void setalias(char *, char *); +STATIC void setalias(const char *, const char *); STATIC int unalias(const char *); STATIC struct alias **hashalias(const char *); STATIC void -setalias(char *name, char *val) +setalias(const char *name, const char *val) { struct alias *ap, **app; @@ -176,7 +176,7 @@ rmaliases(void) } struct alias * -lookupalias(char *name, int check) +lookupalias(const char *name, int check) { struct alias *ap = *hashalias(name); diff --git a/bin/sh/alias.h b/bin/sh/alias.h index a6bd23d..d8f0308 100644 --- a/bin/sh/alias.h +++ b/bin/sh/alias.h @@ -42,7 +42,7 @@ struct alias { int flag; }; -struct alias *lookupalias(char *, int); +struct alias *lookupalias(const char *, int); int aliascmd(int, char **); int unaliascmd(int, char **); void rmaliases(void); diff --git a/bin/sh/arith.h b/bin/sh/arith.h index 41bc76f..6a143a4 100644 --- a/bin/sh/arith.h +++ b/bin/sh/arith.h @@ -34,8 +34,8 @@ #define DIGITS(var) (3 + (2 + CHAR_BIT * sizeof((var))) / 3) -extern char *arith_buf, *arith_startbuf; +extern const char *arith_buf, *arith_startbuf; -arith_t arith(char *); +arith_t arith(const char *); void arith_lex_reset(void); int expcmd(int, char **); diff --git a/bin/sh/arith.y b/bin/sh/arith.y index 542fc44..133a1b8 100644 --- a/bin/sh/arith.y +++ b/bin/sh/arith.y @@ -265,7 +265,7 @@ expr: #define YYPARSE_PARAM_TYPE arith_t * #define YYPARSE_PARAM result -char *arith_buf, *arith_startbuf; +const char *arith_buf, *arith_startbuf; int yylex(void); int yyparse(YYPARSE_PARAM_TYPE); @@ -284,7 +284,7 @@ arith_assign(char *name, arith_t value) } arith_t -arith(char *s) +arith(const char *s) { arith_t result; @@ -299,7 +299,7 @@ arith(char *s) } static void -yyerror(char *s) +yyerror(const char *s) { yyerrok; @@ -354,7 +354,7 @@ main(int argc, char *argv[]) printf("%d\n", exp(argv[1])); } -error(char *s) +error(const char *s) { fprintf(stderr, "exp: %s\n", s); exit(1); diff --git a/bin/sh/cd.c b/bin/sh/cd.c index 66c1908..392ce44 100644 --- a/bin/sh/cd.c +++ b/bin/sh/cd.c @@ -80,7 +80,7 @@ int cdcmd(int argc, char **argv) { char *dest; - char *path; + const char *path; char *p; struct stat statb; int ch, phys, print = 0; diff --git a/bin/sh/exec.c b/bin/sh/exec.c index f9d3c22..f7096d8 100644 --- a/bin/sh/exec.c +++ b/bin/sh/exec.c @@ -98,7 +98,7 @@ int exerrno = 0; /* Last exec error */ STATIC void tryexec(char *, char **, char **); STATIC void printentry(struct tblentry *, int); -STATIC struct tblentry *cmdlookup(char *, int); +STATIC struct tblentry *cmdlookup(const char *, int); STATIC void delete_cmd_entry(void); @@ -109,7 +109,7 @@ STATIC void delete_cmd_entry(void); */ void -shellexec(char **argv, char **envp, char *path, int index) +shellexec(char **argv, char **envp, const char *path, int index) { char *cmdname; int e; @@ -175,13 +175,13 @@ tryexec(char *cmd, char **argv, char **envp) * NULL. */ -char *pathopt; +const char *pathopt; char * -padvance(char **path, char *name) +padvance(const char **path, const char *name) { - char *p, *q; - char *start; + const char *p, *start; + char *q; int len; if (*path == NULL) @@ -269,7 +269,7 @@ STATIC void printentry(struct tblentry *cmdp, int verbose) { int index; - char *path; + const char *path; char *name; if (cmdp->cmdtype == CMDNORMAL) { @@ -310,7 +310,8 @@ printentry(struct tblentry *cmdp, int verbose) */ void -find_command(char *name, struct cmdentry *entry, int printerr, char *path) +find_command(const char *name, struct cmdentry *entry, int printerr, + const char *path) { struct tblentry *cmdp; int index; @@ -446,7 +447,7 @@ success: */ int -find_builtin(char *name, int *special) +find_builtin(const char *name, int *special) { const struct builtincmd *bp; @@ -608,10 +609,10 @@ STATIC struct tblentry **lastcmdentry; STATIC struct tblentry * -cmdlookup(char *name, int add) +cmdlookup(const char *name, int add) { int hashval; - char *p; + const char *p; struct tblentry *cmdp; struct tblentry **pp; @@ -664,7 +665,7 @@ delete_cmd_entry(void) */ void -addcmdentry(char *name, struct cmdentry *entry) +addcmdentry(const char *name, struct cmdentry *entry) { struct tblentry *cmdp; @@ -684,7 +685,7 @@ addcmdentry(char *name, struct cmdentry *entry) */ void -defun(char *name, union node *func) +defun(const char *name, union node *func) { struct cmdentry entry; @@ -701,7 +702,7 @@ defun(char *name, union node *func) */ int -unsetfunc(char *name) +unsetfunc(const char *name) { struct tblentry *cmdp; @@ -767,7 +768,8 @@ typecmd_impl(int argc, char **argv, int cmd) switch (entry.cmdtype) { case CMDNORMAL: { if (strchr(argv[i], '/') == NULL) { - char *path = pathval(), *name; + const char *path = pathval(); + char *name; int j = entry.u.index; do { name = padvance(&path, argv[i]); diff --git a/bin/sh/exec.h b/bin/sh/exec.h index e3b9acd..9803a5e 100644 --- a/bin/sh/exec.h +++ b/bin/sh/exec.h @@ -57,20 +57,20 @@ struct cmdentry { }; -extern char *pathopt; /* set by padvance */ +extern const char *pathopt; /* set by padvance */ extern int exerrno; /* last exec error */ -void shellexec(char **, char **, char *, int); -char *padvance(char **, char *); +void shellexec(char **, char **, const char *, int); +char *padvance(const char **, const char *); int hashcmd(int, char **); -void find_command(char *, struct cmdentry *, int, char *); -int find_builtin(char *, int *); +void find_command(const char *, struct cmdentry *, int, const char *); +int find_builtin(const char *, int *); void hashcd(void); void changepath(const char *); void deletefuncs(void); -void addcmdentry(char *, struct cmdentry *); -void defun(char *, union node *); -int unsetfunc(char *); +void addcmdentry(const char *, struct cmdentry *); +void defun(const char *, union node *); +int unsetfunc(const char *); int typecmd_impl(int, char **, int); int typecmd(int, char **); void clearcmdentry(int); diff --git a/bin/sh/expand.c b/bin/sh/expand.c index af79e8c..db86dac 100644 --- a/bin/sh/expand.c +++ b/bin/sh/expand.c @@ -107,7 +107,7 @@ STATIC void expmeta(char *, char *); STATIC void addfname(char *); STATIC struct strlist *expsort(struct strlist *); STATIC struct strlist *msort(struct strlist *, int); -STATIC int pmatch(char *, char *, int); +STATIC int pmatch(const char *, const char *, int); STATIC char *cvtnum(int, char *); STATIC int collate_range_cmp(int, int); @@ -1338,7 +1338,7 @@ msort(struct strlist *list, int len) */ int -patmatch(char *pattern, char *string, int squoted) +patmatch(const char *pattern, const char *string, int squoted) { #ifdef notdef if (pattern[0] == '!' && pattern[1] == '!') @@ -1350,9 +1350,9 @@ patmatch(char *pattern, char *string, int squoted) STATIC int -pmatch(char *pattern, char *string, int squoted) +pmatch(const char *pattern, const char *string, int squoted) { - char *p, *q; + const char *p, *q; char c; p = pattern; @@ -1400,7 +1400,7 @@ pmatch(char *pattern, char *string, int squoted) } while (*q++ != '\0'); return 0; case '[': { - char *endp; + const char *endp; int invert, found; char chr; @@ -1504,7 +1504,7 @@ rmescapes(char *str) */ int -casematch(union node *pattern, char *val) +casematch(union node *pattern, const char *val) { struct stackmark smark; int result; diff --git a/bin/sh/expand.h b/bin/sh/expand.h index 2b89519..a3e079a 100644 --- a/bin/sh/expand.h +++ b/bin/sh/expand.h @@ -58,7 +58,7 @@ union node; void expandhere(union node *, int); void expandarg(union node *, struct arglist *, int); void expari(int); -int patmatch(char *, char *, int); +int patmatch(const char *, const char *, int); void rmescapes(char *); -int casematch(union node *, char *); +int casematch(union node *, const char *); int wordexpcmd(int, char **); diff --git a/bin/sh/histedit.c b/bin/sh/histedit.c index 0c2def8..8240a96 100644 --- a/bin/sh/histedit.c +++ b/bin/sh/histedit.c @@ -406,7 +406,7 @@ fc_replace(const char *s, char *p, char *r) } int -not_fcnumber(char *s) +not_fcnumber(const char *s) { if (s == NULL) return (0); @@ -416,10 +416,10 @@ not_fcnumber(char *s) } int -str_to_event(char *str, int last) +str_to_event(const char *str, int last) { HistEvent he; - char *s = str; + const char *s = str; int relative = 0; int i, retval; diff --git a/bin/sh/input.c b/bin/sh/input.c index 548ae92..74ab48f 100644 --- a/bin/sh/input.c +++ b/bin/sh/input.c @@ -401,7 +401,7 @@ popstring(void) */ void -setinputfile(char *fname, int push) +setinputfile(const char *fname, int push) { int fd; int fd2; diff --git a/bin/sh/input.h b/bin/sh/input.h index 067d011..abbb2ce 100644 --- a/bin/sh/input.h +++ b/bin/sh/input.h @@ -54,7 +54,7 @@ int preadateof(void); void pungetc(void); void pushstring(char *, int, void *); void popstring(void); -void setinputfile(char *, int); +void setinputfile(const char *, int); void setinputfd(int, int); void setinputstring(char *, int); void popfile(void); diff --git a/bin/sh/mail.c b/bin/sh/mail.c index fe03a73..0ba7be5 100644 --- a/bin/sh/mail.c +++ b/bin/sh/mail.c @@ -72,7 +72,7 @@ void chkmail(int silent) { int i; - char *mpath; + const char *mpath; char *p; char *q; struct stackmark smark; diff --git a/bin/sh/main.c b/bin/sh/main.c index b27d0cf..547aad9 100644 --- a/bin/sh/main.c +++ b/bin/sh/main.c @@ -269,7 +269,7 @@ read_profile(char *name) */ void -readcmdfile(char *name) +readcmdfile(const char *name) { int fd; @@ -296,7 +296,7 @@ find_dot_file(char *basename) { static char localname[FILENAME_MAX+1]; char *fullname; - char *path = pathval(); + const char *path = pathval(); struct stat statb; /* don't try this for absolute or relative paths */ diff --git a/bin/sh/main.h b/bin/sh/main.h index 7f8c394..b6dadc3 100644 --- a/bin/sh/main.h +++ b/bin/sh/main.h @@ -36,7 +36,7 @@ extern int rootpid; /* pid of main shell */ extern int rootshell; /* true if we aren't a child of the main shell */ -void readcmdfile(char *); +void readcmdfile(const char *); void cmdloop(int); int dotcmd(int, char **); int exitcmd(int, char **); diff --git a/bin/sh/memalloc.c b/bin/sh/memalloc.c index fa03632..9d5332f 100644 --- a/bin/sh/memalloc.c +++ b/bin/sh/memalloc.c @@ -95,7 +95,7 @@ ckfree(pointer p) */ char * -savestr(char *s) +savestr(const char *s) { char *p; diff --git a/bin/sh/memalloc.h b/bin/sh/memalloc.h index 4652e54..187d4c8 100644 --- a/bin/sh/memalloc.h +++ b/bin/sh/memalloc.h @@ -51,7 +51,7 @@ extern int herefd; pointer ckmalloc(size_t); pointer ckrealloc(pointer, int); void ckfree(pointer); -char *savestr(char *); +char *savestr(const char *); pointer stalloc(int); void stunalloc(pointer); void setstackmark(struct stackmark *); diff --git a/bin/sh/myhistedit.h b/bin/sh/myhistedit.h index 5d96587..f4fa374 100644 --- a/bin/sh/myhistedit.h +++ b/bin/sh/myhistedit.h @@ -39,7 +39,7 @@ extern int displayhist; void histedit(void); void sethistsize(const char *); int histcmd(int, char **); -int not_fcnumber(char *); -int str_to_event(char *, int); +int not_fcnumber(const char *); +int str_to_event(const char *, int); int bindcmd(int, char **); diff --git a/bin/sh/options.c b/bin/sh/options.c index fea95ca..8582f79 100644 --- a/bin/sh/options.c +++ b/bin/sh/options.c @@ -554,9 +554,10 @@ out: */ int -nextopt(char *optstring) +nextopt(const char *optstring) { - char *p, *q; + char *p; + const char *q; char c; if ((p = optptr) == NULL || *p == '\0') { diff --git a/bin/sh/options.h b/bin/sh/options.h index 3b827d1..fc9085e 100644 --- a/bin/sh/options.h +++ b/bin/sh/options.h @@ -111,5 +111,5 @@ void freeparam(struct shparam *); int shiftcmd(int, char **); int setcmd(int, char **); int getoptscmd(int, char **); -int nextopt(char *); +int nextopt(const char *); void getoptsreset(const char *); diff --git a/bin/sh/output.c b/bin/sh/output.c index f1d2072..fd03e23 100644 --- a/bin/sh/output.c +++ b/bin/sh/output.c @@ -314,7 +314,7 @@ doformat(struct output *dest, const char *f, va_list ap) */ int -xwrite(int fd, char *buf, int nbytes) +xwrite(int fd, const char *buf, int nbytes) { int ntry; int i; diff --git a/bin/sh/output.h b/bin/sh/output.h index d34c792..6bf7e2b 100644 --- a/bin/sh/output.h +++ b/bin/sh/output.h @@ -68,7 +68,7 @@ void out1fmt(const char *, ...) __printflike(1, 2); void out2fmt_flush(const char *, ...) __printflike(1, 2); void fmtstr(char *, int, const char *, ...) __printflike(3, 4); void doformat(struct output *, const char *, va_list) __printflike(2, 0); -int xwrite(int, char *, int); +int xwrite(int, const char *, int); #define outc(c, file) (--(file)->nleft < 0? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c))) #define out1c(c) outc(c, out1); diff --git a/bin/sh/parser.c b/bin/sh/parser.c index 855becc..de7b130 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -1510,9 +1510,9 @@ noexpand(char *text) */ int -goodname(char *name) +goodname(const char *name) { - char *p; + const char *p; p = name; if (! is_name(*p)) diff --git a/bin/sh/parser.h b/bin/sh/parser.h index 40dd8bd..668043e 100644 --- a/bin/sh/parser.h +++ b/bin/sh/parser.h @@ -77,5 +77,5 @@ extern int whichprompt; /* 1 == PS1, 2 == PS2 */ union node *parsecmd(int); void fixredir(union node *, const char *, int); -int goodname(char *); +int goodname(const char *); char *getprompt(void *); diff --git a/bin/sh/show.c b/bin/sh/show.c index baae549..f11cfce 100644 --- a/bin/sh/show.c +++ b/bin/sh/show.c @@ -307,7 +307,7 @@ sh_trace(const char *fmt, ...) void -trputs(char *s) +trputs(const char *s) { if (tracefile == NULL) return; diff --git a/bin/sh/show.h b/bin/sh/show.h index 83f84af..4528fb1 100644 --- a/bin/sh/show.h +++ b/bin/sh/show.h @@ -35,6 +35,6 @@ void showtree(union node *); void sh_trace(const char *, ...) __printflike(1, 2); void trargs(char **); void trputc(int); -void trputs(char *); +void trputs(const char *); void opentrace(void); #endif diff --git a/bin/sh/var.c b/bin/sh/var.c index 8fa3b5c..900a483 100644 --- a/bin/sh/var.c +++ b/bin/sh/var.c @@ -122,9 +122,9 @@ STATIC const struct varinit varinit[] = { STATIC struct var *vartab[VTABSIZE]; -STATIC struct var **hashvar(char *); -STATIC int varequal(char *, char *); -STATIC int localevar(char *); +STATIC struct var **hashvar(const char *); +STATIC int varequal(const char *, const char *); +STATIC int localevar(const char *); /* * Initialize the variable symbol tables and import the environment. @@ -190,7 +190,7 @@ initvar(void) */ int -setvarsafe(char *name, char *val, int flags) +setvarsafe(const char *name, const char *val, int flags) { struct jmploc jmploc; struct jmploc *const savehandler = handler; @@ -215,9 +215,9 @@ setvarsafe(char *name, char *val, int flags) */ void -setvar(char *name, char *val, int flags) +setvar(const char *name, const char *val, int flags) { - char *p, *q; + const char *p; int len; int namelen; char *nameeq; @@ -245,19 +245,18 @@ setvar(char *name, char *val, int flags) } else { len += strlen(val); } - p = nameeq = ckmalloc(len); - q = name; - while (--namelen >= 0) - *p++ = *q++; - *p++ = '='; - *p = '\0'; + nameeq = ckmalloc(len); + memcpy(nameeq, name, namelen); + nameeq[namelen] = '='; if (val) - scopy(val, p); + scopy(val, nameeq + namelen + 1); + else + nameeq[namelen + 1] = '\0'; setvareq(nameeq, flags); } STATIC int -localevar(char *s) +localevar(const char *s) { static char *lnames[7] = { "ALL", "COLLATE", "CTYPE", "MONETARY", @@ -283,7 +282,7 @@ localevar(char *s) * pointer into environ where the string should not be manipulated. */ static void -change_env(char *s, int set) +change_env(const char *s, int set) { char *eqp; char *ss; @@ -389,7 +388,7 @@ listsetvar(struct strlist *list) */ char * -lookupvar(char *name) +lookupvar(const char *name) { struct var *v; @@ -412,7 +411,7 @@ lookupvar(char *name) */ char * -bltinlookup(char *name, int doall) +bltinlookup(const char *name, int doall) { struct strlist *sp; struct var *v; @@ -796,7 +795,7 @@ unsetcmd(int argc __unused, char **argv __unused) */ int -unsetvar(char *s) +unsetvar(const char *s) { struct var **vpp; struct var *vp; @@ -836,7 +835,7 @@ unsetvar(char *s) */ STATIC struct var ** -hashvar(char *p) +hashvar(const char *p) { unsigned int hashval; @@ -855,7 +854,7 @@ hashvar(char *p) */ STATIC int -varequal(char *p, char *q) +varequal(const char *p, const char *q) { while (*p == *q++) { if (*p++ == '=') diff --git a/bin/sh/var.h b/bin/sh/var.h index c1f994b..4dafa2c 100644 --- a/bin/sh/var.h +++ b/bin/sh/var.h @@ -101,12 +101,12 @@ extern struct var vhistsize; #define mpathset() ((vmpath.flags & VUNSET) == 0) void initvar(void); -void setvar(char *, char *, int); +void setvar(const char *, const char *, int); void setvareq(char *, int); struct strlist; void listsetvar(struct strlist *); -char *lookupvar(char *); -char *bltinlookup(char *, int); +char *lookupvar(const char *); +char *bltinlookup(const char *, int); char **environment(void); void shprocvar(void); int showvarscmd(int, char **); @@ -116,5 +116,5 @@ void mklocal(char *); void poplocalvars(void); int setvarcmd(int, char **); int unsetcmd(int, char **); -int unsetvar(char *); -int setvarsafe(char *, char *, int); +int unsetvar(const char *); +int setvarsafe(const char *, const char *, int); |