From 271e747f05d94d60fba93c323f21c6553020c551 Mon Sep 17 00:00:00 2001 From: Max Okumoto Date: Sat, 8 Jan 2005 21:58:23 +0000 Subject: [PATCH] Constifying functions. --- usr.bin/make/arch.c | 21 ++++++++++----------- usr.bin/make/compat.c | 16 +++++++++------- usr.bin/make/cond.c | 30 ++++++++++++++++-------------- usr.bin/make/dir.c | 6 +++--- usr.bin/make/dir.h | 6 +++--- usr.bin/make/job.c | 32 ++++++++++++++++---------------- usr.bin/make/main.c | 26 +++++++++++++++----------- usr.bin/make/nonints.h | 4 ++-- usr.bin/make/suff.c | 4 ++-- 9 files changed, 76 insertions(+), 69 deletions(-) diff --git a/usr.bin/make/arch.c b/usr.bin/make/arch.c index 364ce759a4..cae8de78c8 100644 --- a/usr.bin/make/arch.c +++ b/usr.bin/make/arch.c @@ -37,7 +37,7 @@ * * @(#)arch.c 8.2 (Berkeley) 1/2/94 * $FreeBSD: src/usr.bin/make/arch.c,v 1.15.2.1 2001/02/13 03:13:57 will Exp $ - * $DragonFly: src/usr.bin/make/arch.c,v 1.24 2005/01/06 10:52:59 okumoto Exp $ + * $DragonFly: src/usr.bin/make/arch.c,v 1.25 2005/01/08 21:58:23 okumoto Exp $ */ /*- @@ -117,8 +117,8 @@ typedef struct Arch { size_t fnamesize; /* Size of the string table */ } Arch; -static struct ar_hdr *ArchStatMember(char *, char *, Boolean); -static FILE *ArchFindMember(char *, char *, struct ar_hdr *, char *); +static struct ar_hdr *ArchStatMember(const char *, const char *, Boolean); +static FILE *ArchFindMember(const char *, const char *, struct ar_hdr *, const char *); #if defined(__svr4__) || defined(__SVR4) || defined(__ELF__) #define SVR4ARCHIVES static int ArchSVR4Entry(Arch *, char *, size_t, FILE *); @@ -406,7 +406,6 @@ Arch_ParseArchive(char **linePtr, Lst *nodeLst, GNode *ctxt) static int ArchFindArchive(const void *ar, const void *archName) { - return (strcmp(archName, ((const Arch *)ar)->name)); } @@ -429,7 +428,7 @@ ArchFindArchive(const void *ar, const void *archName) *----------------------------------------------------------------------- */ static struct ar_hdr * -ArchStatMember(char *archive, char *member, Boolean hash) +ArchStatMember(const char *archive, const char *member, Boolean hash) { #define AR_MAX_NAME_LEN (sizeof(arh.ar_name) - 1) FILE * arch; /* Stream to archive */ @@ -733,13 +732,13 @@ ArchSVR4Entry(Arch *ar, char *name, size_t size, FILE *arch) *----------------------------------------------------------------------- */ static FILE * -ArchFindMember(char *archive, char *member, struct ar_hdr *arhPtr, char *mode) +ArchFindMember(const char *archive, const char *member, struct ar_hdr *arhPtr, const char *mode) { - FILE * arch; /* Stream to archive */ - int size; /* Size of archive member */ - char *cp; /* Useful character pointer */ - char magic[SARMAG]; - size_t len, tlen; + FILE *arch; /* Stream to archive */ + int size; /* Size of archive member */ + const char *cp; /* Useful character pointer */ + char magic[SARMAG]; + size_t len, tlen; arch = fopen(archive, mode); if (arch == NULL) { diff --git a/usr.bin/make/compat.c b/usr.bin/make/compat.c index 46c77fe7f7..71c28247f2 100644 --- a/usr.bin/make/compat.c +++ b/usr.bin/make/compat.c @@ -38,7 +38,7 @@ * * @(#)compat.c 8.2 (Berkeley) 3/19/94 * $FreeBSD: src/usr.bin/make/compat.c,v 1.16.2.2 2000/07/01 12:24:21 ps Exp $ - * $DragonFly: src/usr.bin/make/Attic/compat.c,v 1.20 2005/01/06 10:52:59 okumoto Exp $ + * $DragonFly: src/usr.bin/make/Attic/compat.c,v 1.21 2005/01/08 21:58:23 okumoto Exp $ */ /*- @@ -93,14 +93,15 @@ static void CompatInterrupt(int); static int CompatMake(void *, void *); static int shellneed(char *); -static char *sh_builtin[] = { +static const char *sh_builtin[] = { "alias", "cd", "eval", "exec", "exit", "read", "set", "ulimit", - "unalias", "umask", "unset", "wait", ":", 0}; + "unalias", "umask", "unset", "wait", ":", NULL +}; static void CompatInit(void) { - char *cp; /* Pointer to string of shell meta-characters */ + const char *cp; /* Pointer to string of shell meta-characters */ for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) { meta[(unsigned char)*cp] = 1; @@ -194,10 +195,11 @@ CompatInterrupt (int signo) *----------------------------------------------------------------------- */ static int -shellneed (char *cmd) +shellneed(char *cmd) { - char **av, **p; - int ac; + char **av; + const char **p; + int ac; av = brk_string(cmd, &ac, TRUE); for(p = sh_builtin; *p != 0; p++) diff --git a/usr.bin/make/cond.c b/usr.bin/make/cond.c index dc461130ca..f5084d3279 100644 --- a/usr.bin/make/cond.c +++ b/usr.bin/make/cond.c @@ -38,7 +38,7 @@ * * @(#)cond.c 8.2 (Berkeley) 1/2/94 * $FreeBSD: src/usr.bin/make/cond.c,v 1.12.2.1 2003/07/22 08:03:13 ru Exp $ - * $DragonFly: src/usr.bin/make/cond.c,v 1.20 2005/01/06 13:18:58 okumoto Exp $ + * $DragonFly: src/usr.bin/make/cond.c,v 1.21 2005/01/08 21:58:23 okumoto Exp $ */ /*- @@ -102,27 +102,29 @@ typedef enum { And, Or, Not, True, False, LParen, RParen, EndOfFile, None, Err } Token; +typedef Boolean CondProc(int, char *); + /*- * Structures to handle elegantly the different forms of #if's. The * last two fields are stored in condInvert and condDefProc, respectively. */ static void CondPushBack(Token); static int CondGetArg(char **, char **, char *, Boolean); -static Boolean CondDoDefined(int, char *); -static Boolean CondDoMake(int, char *); -static Boolean CondDoExists(int, char *); -static Boolean CondDoTarget(int, char *); -static char * CondCvtArg(char *, double *); +static CondProc CondDoDefined; +static CondProc CondDoMake; +static CondProc CondDoExists; +static CondProc CondDoTarget; +static char *CondCvtArg(char *, double *); static Token CondToken(Boolean); static Token CondT(Boolean); static Token CondF(Boolean); static Token CondE(Boolean); static struct If { - char *form; /* Form of if */ - int formlen; /* Length of form */ - Boolean doNot; /* TRUE if default function should be negated */ - Boolean (*defProc)(int, char *); /* Default function to apply */ + const char *form; /* Form of if */ + int formlen; /* Length of form */ + Boolean doNot; /* TRUE if default function should be negated */ + CondProc *defProc; /* Default function to apply */ } ifs[] = { { "ifdef", 5, FALSE, CondDoDefined }, { "ifndef", 6, TRUE, CondDoDefined }, @@ -754,10 +756,10 @@ error: break; } default: { - Boolean (*evalProc)(int, char *); - Boolean invert = FALSE; - char *arg; - int arglen; + CondProc *evalProc; + Boolean invert = FALSE; + char *arg; + int arglen; if (strncmp(condExpr, "defined", 7) == 0) { /* diff --git a/usr.bin/make/dir.c b/usr.bin/make/dir.c index df3e5a3895..f65965ca51 100644 --- a/usr.bin/make/dir.c +++ b/usr.bin/make/dir.c @@ -38,7 +38,7 @@ * * @(#)dir.c 8.2 (Berkeley) 1/2/94 * $$FreeBSD: src/usr.bin/make/dir.c,v 1.10.2.2 2003/10/08 08:14:22 ru Exp $ - * $DragonFly: src/usr.bin/make/dir.c,v 1.28 2005/01/06 10:53:00 okumoto Exp $ + * $DragonFly: src/usr.bin/make/dir.c,v 1.29 2005/01/08 21:58:23 okumoto Exp $ */ /*- @@ -976,7 +976,7 @@ Dir_MTime(GNode *gn) *----------------------------------------------------------------------- */ void -Dir_AddDir(Lst *path, char *name) +Dir_AddDir(Lst *path, const char *name) { LstNode *ln; /* node in case Path structure is found */ Path *p; /* pointer to new Path structure */ @@ -1075,7 +1075,7 @@ Dir_CopyDir(void *p) *----------------------------------------------------------------------- */ char * -Dir_MakeFlags(char *flag, Lst *path) +Dir_MakeFlags(const char *flag, Lst *path) { char *str; /* the string which will be returned */ char *tstr; /* the current directory preceded by 'flag' */ diff --git a/usr.bin/make/dir.h b/usr.bin/make/dir.h index 54d5b9de9a..73dccbeb5d 100644 --- a/usr.bin/make/dir.h +++ b/usr.bin/make/dir.h @@ -40,7 +40,7 @@ * * from: @(#)dir.h 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.bin/make/dir.h,v 1.7 1999/08/28 01:03:29 peter Exp $ - * $DragonFly: src/usr.bin/make/dir.h,v 1.12 2005/01/06 10:53:00 okumoto Exp $ + * $DragonFly: src/usr.bin/make/dir.h,v 1.13 2005/01/08 21:58:23 okumoto Exp $ */ /* dir.h -- @@ -65,8 +65,8 @@ Boolean Dir_HasWildcards(const char *); void Dir_Expand(char *, struct Lst *, struct Lst *); char *Dir_FindFile(char *, struct Lst *); int Dir_MTime(struct GNode *); -void Dir_AddDir(struct Lst *, char *); -char *Dir_MakeFlags(char *, struct Lst *); +void Dir_AddDir(struct Lst *, const char *); +char *Dir_MakeFlags(const char *, struct Lst *); void Dir_ClearPath(struct Lst *); void Dir_Concat(struct Lst *, struct Lst *); void Dir_PrintDirectories(void); diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c index ba6278d471..88e789243d 100644 --- a/usr.bin/make/job.c +++ b/usr.bin/make/job.c @@ -38,7 +38,7 @@ * * @(#)job.c 8.2 (Berkeley) 3/19/94 * $FreeBSD: src/usr.bin/make/job.c,v 1.17.2.2 2001/02/13 03:13:57 will Exp $ - * $DragonFly: src/usr.bin/make/job.c,v 1.38 2005/01/06 10:53:00 okumoto Exp $ + * $DragonFly: src/usr.bin/make/job.c,v 1.39 2005/01/08 21:58:23 okumoto Exp $ */ #ifndef OLD_JOKE @@ -238,7 +238,7 @@ static fd_set outputs; /* Set of descriptors of pipes connected to STATIC GNode *lastNode; /* The node for which output was most recently * produced. */ -STATIC char *targFmt; /* Format string to use to head output from a +STATIC const char *targFmt; /* Format string to use to head output from a * job when it's not the most-recent job heard * from */ @@ -471,20 +471,20 @@ JobCmpPid(const void *job, const void *pid) static int JobPrintCommand(void *cmdp, void *jobp) { - Boolean noSpecials; /* true if we shouldn't worry about - * inserting special commands into - * the input stream. */ - Boolean shutUp = FALSE; /* true if we put a no echo command - * into the command file */ - Boolean errOff = FALSE; /* true if we turned error checking - * off before printing the command - * and need to turn it back on */ - char *cmdTemplate; /* Template to use when printing the - * command */ - char *cmdStart; /* Start of expanded command */ - LstNode *cmdNode; /* Node for replacing the command */ - char *cmd = cmdp; - Job *job = jobp; + Boolean noSpecials; /* true if we shouldn't worry about + * inserting special commands into + * the input stream. */ + Boolean shutUp = FALSE; /* true if we put a no echo command + * into the command file */ + Boolean errOff = FALSE; /* true if we turned error checking + * off before printing the command + * and need to turn it back on */ + const char *cmdTemplate; /* Template to use when printing the + * command */ + char *cmdStart; /* Start of expanded command */ + LstNode *cmdNode; /* Node for replacing the command */ + char *cmd = cmdp; + Job *job = jobp; noSpecials = (noExecute && !(job->node->type & OP_MAKE)); diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index 5f5bb42346..1b405af1e6 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -38,7 +38,7 @@ * @(#) Copyright (c) 1988, 1989, 1990, 1993 The Regents of the University of California. All rights reserved. * @(#)main.c 8.3 (Berkeley) 3/19/94 * $FreeBSD: src/usr.bin/make/main.c,v 1.35.2.10 2003/12/16 08:34:11 des Exp $ - * $DragonFly: src/usr.bin/make/main.c,v 1.43 2005/01/08 13:13:22 okumoto Exp $ + * $DragonFly: src/usr.bin/make/main.c,v 1.44 2005/01/08 21:58:23 okumoto Exp $ */ /*- @@ -67,6 +67,7 @@ #include #include #include +#include #include "arch.h" #include "buf.h" @@ -131,7 +132,7 @@ Lst envFirstVars = Lst_Initializer(envFirstVars); Boolean jobsRunning; /* TRUE if the jobs might be running */ static void MainParseArgs(int, char **); -char * chdir_verify_path(char *, char *); +char *chdir_verify_path(const char *, char *); static int ReadMakefile(const void *, const void *); static void usage(void); @@ -142,7 +143,7 @@ static char *objdir; /* where we chdir'ed to */ * Append a flag with an optional argument to MAKEFLAGS and MFLAGS */ static void -MFLAGS_append(char *flag, char *arg) +MFLAGS_append(const char *flag, char *arg) { Var_Append(MAKEFLAGS, flag, VAR_GLOBAL); @@ -393,7 +394,7 @@ Main_ParseArgLine(char *line) } char * -chdir_verify_path(char *path, char *obpath) +chdir_verify_path(const char *path, char *obpath) { struct stat sb; @@ -405,7 +406,7 @@ chdir_verify_path(char *path, char *obpath) return (obpath); } - return (0); + return (NULL); } static void @@ -459,14 +460,14 @@ int main(int argc, char **argv) { Boolean outOfDate = TRUE; /* FALSE if all targets up to date */ - struct stat sa; - char *p, *p1, *path, *pathp; + char *p, *p1, *pathp; + const char *path; char mdpath[MAXPATHLEN]; char obpath[MAXPATHLEN]; char cdpath[MAXPATHLEN]; - char *machine = getenv("MACHINE"); - char *machine_arch = getenv("MACHINE_ARCH"); - char *machine_cpu = getenv("MACHINE_CPU"); + const char *machine = getenv("MACHINE"); + const char *machine_arch = getenv("MACHINE_ARCH"); + const char *machine_cpu = getenv("MACHINE_CPU"); char *cp = NULL, *start; /* avoid faults on read-only strings */ static char syspath[] = _PATH_DEFSYSPATH; @@ -635,8 +636,11 @@ main(int argc, char **argv) if (getcwd(curdir, MAXPATHLEN) == NULL) err(2, NULL); + { + struct stat sa; if (stat(curdir, &sa) == -1) err(2, "%s", curdir); + } /* * The object directory location is determined using the @@ -997,7 +1001,7 @@ found: * The string must be freed by the caller. */ char * -Cmd_Exec(char *cmd, char **error) +Cmd_Exec(char *cmd, const char **error) { char *args[4]; /* Args for invoking the shell */ int fds[2]; /* Pipe streams */ diff --git a/usr.bin/make/nonints.h b/usr.bin/make/nonints.h index 55d0670f42..64fd1aade8 100644 --- a/usr.bin/make/nonints.h +++ b/usr.bin/make/nonints.h @@ -39,10 +39,10 @@ * * from: @(#)nonints.h 8.3 (Berkeley) 3/19/94 * $FreeBSD: src/usr.bin/make/nonints.h,v 1.8 1999/08/28 01:03:35 peter Exp $ - * $DragonFly: src/usr.bin/make/Attic/nonints.h,v 1.23 2005/01/06 10:53:00 okumoto Exp $ + * $DragonFly: src/usr.bin/make/Attic/nonints.h,v 1.24 2005/01/08 21:58:23 okumoto Exp $ */ /* main.c */ void Main_ParseArgLine(char *); -char *Cmd_Exec(char *, char **); +char *Cmd_Exec(char *, const char **); #endif /* nonints_h_33c5dafb */ diff --git a/usr.bin/make/suff.c b/usr.bin/make/suff.c index 1b70622145..fc11f04302 100644 --- a/usr.bin/make/suff.c +++ b/usr.bin/make/suff.c @@ -37,7 +37,7 @@ * * @(#)suff.c 8.4 (Berkeley) 3/21/94 * $FreeBSD: src/usr.bin/make/suff.c,v 1.12.2.2 2004/06/10 13:07:53 ru Exp $ - * $DragonFly: src/usr.bin/make/suff.c,v 1.25 2005/01/06 10:53:00 okumoto Exp $ + * $DragonFly: src/usr.bin/make/suff.c,v 1.26 2005/01/08 21:58:23 okumoto Exp $ */ /*- @@ -1608,7 +1608,7 @@ SuffFindArchiveDeps(GNode *gn, Lst *slst) char *eoarch; /* End of archive portion */ char *eoname; /* End of member portion */ GNode *mem; /* Node for member */ - static char *copy[] = { /* Variables to be copied from the member node */ + static const char *copy[] = { /* Variables to be copied from the member node */ TARGET, /* Must be first */ PREFIX, /* Must be second */ }; -- 2.41.0