From c29adcee80825d79e7b522ee651360d1b9542539 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Mon, 7 Apr 2008 12:11:16 +0300 Subject: [PATCH] ARGV_t const pendantry - const on typedef'ed ARGV_t doesn't mean a thing, add a new, (exec* compatible) ARGV_const_t and use where appropriate consistently in argv.h, rpmcli.h etc - popt's argv const is the wrong way around for exec() family, add explicit ARGV_t casts on popGetArgs() uses where needed - compiler silence, aaahh... --- build/files.c | 2 +- build/rpmfc.c | 8 ++++---- build/rpmfc.h | 2 +- lib/query.c | 4 ++-- lib/rpmchecksig.c | 9 +++------ lib/rpmcli.h | 16 ++++++++-------- lib/rpmgi.c | 6 +++--- lib/rpmgi.h | 2 +- lib/rpminstall.c | 17 ++++++----------- lib/verify.c | 2 +- rpmio/argv.c | 8 ++++---- rpmio/argv.h | 9 +++++---- rpmio/rpmfileutil.c | 4 ++-- rpmqv.c | 10 +++++----- tools/rpmdeps.c | 2 +- 15 files changed, 47 insertions(+), 54 deletions(-) diff --git a/build/files.c b/build/files.c index 6860a01..868f03c 100644 --- a/build/files.c +++ b/build/files.c @@ -2246,7 +2246,7 @@ int processSourceFiles(rpmSpec spec) */ static int checkFiles(StringBuf fileList) { - static const char * av_ckfile[] = { "%{?__check_files}", NULL }; + static char * const av_ckfile[] = { "%{?__check_files}", NULL }; StringBuf sb_stdout = NULL; char * s; int rc; diff --git a/build/rpmfc.c b/build/rpmfc.c index f8925ed..e7d0d8d 100644 --- a/build/rpmfc.c +++ b/build/rpmfc.c @@ -61,7 +61,7 @@ struct rpmfcTokens_s { /** */ -static int rpmfcExpandAppend(ARGV_t * argvp, const ARGV_t av) +static int rpmfcExpandAppend(ARGV_t * argvp, ARGV_const_t av) { ARGV_t argv = *argvp; int argc = argvCount(argv); @@ -227,7 +227,7 @@ top: return readBuff; } -int rpmfcExec(ARGV_t av, StringBuf sb_stdin, StringBuf * sb_stdoutp, +int rpmfcExec(ARGV_const_t av, StringBuf sb_stdin, StringBuf * sb_stdoutp, int failnonzero) { char * s = NULL; @@ -345,7 +345,7 @@ static int rpmfcHelper(rpmfc fc, unsigned char deptype, const char * nsdep) char *buf = NULL; StringBuf sb_stdout = NULL; StringBuf sb_stdin; - const char *av[2]; + char *av[2]; rpmds * depsp, ds; const char * N; const char * EVR; @@ -1343,7 +1343,7 @@ typedef struct DepMsg_s * DepMsg_t; */ struct DepMsg_s { const char * msg; - const char * argv[4]; + char * const argv[4]; rpmTag ntag; rpmTag vtag; rpmTag ftag; diff --git a/build/rpmfc.h b/build/rpmfc.h index 3af9769..84808a3 100644 --- a/build/rpmfc.h +++ b/build/rpmfc.h @@ -86,7 +86,7 @@ typedef const struct rpmfcTokens_s * rpmfcToken; * @retval *sb_stdoutp helper output * @param failnonzero IS non-zero helper exit status a failure? */ -int rpmfcExec(ARGV_t av, StringBuf sb_stdin, StringBuf * sb_stdoutp, +int rpmfcExec(ARGV_const_t av, StringBuf sb_stdin, StringBuf * sb_stdoutp, int failnonzero); /** \ingroup rpmfc diff --git a/lib/query.c b/lib/query.c index 460e644..2ef0a3a 100644 --- a/lib/query.c +++ b/lib/query.c @@ -675,7 +675,7 @@ int rpmQueryVerify(QVA_t qva, rpmts ts, const char * arg) return res; } -int rpmcliArgIter(rpmts ts, QVA_t qva, ARGV_t argv) +int rpmcliArgIter(rpmts ts, QVA_t qva, ARGV_const_t argv) { rpmRC rpmrc = RPMRC_NOTFOUND; int ec = 0; @@ -755,7 +755,7 @@ int rpmcliArgIter(rpmts ts, QVA_t qva, ARGV_t argv) return ec; } -int rpmcliQuery(rpmts ts, QVA_t qva, const char ** argv) +int rpmcliQuery(rpmts ts, QVA_t qva, char * const * argv) { rpmVSFlags vsflags, ovsflags; int ec = 0; diff --git a/lib/rpmchecksig.c b/lib/rpmchecksig.c index e5b16b8..7946031 100644 --- a/lib/rpmchecksig.c +++ b/lib/rpmchecksig.c @@ -137,8 +137,7 @@ static int getSignid(Header sig, rpmSigTag sigtag, pgpKeyID_t signid) * @param argv array of package file names (NULL terminated) * @return 0 on success */ -static int rpmReSign(rpmts ts, - QVA_t qva, const char ** argv) +static int rpmReSign(rpmts ts, QVA_t qva, ARGV_const_t argv) { FD_t fd = NULL; FD_t ofd = NULL; @@ -398,9 +397,7 @@ exit: * @param argv array of pubkey file names (NULL terminated) * @return 0 on success */ -static int rpmcliImportPubkeys(const rpmts ts, - QVA_t qva, - const char ** argv) +static int rpmcliImportPubkeys(const rpmts ts, QVA_t qva, ARGV_const_t argv) { const char * fn; unsigned char * pkt = NULL; @@ -797,7 +794,7 @@ exit: return res; } -int rpmcliSign(rpmts ts, QVA_t qva, const char ** argv) +int rpmcliSign(rpmts ts, QVA_t qva, ARGV_const_t argv) { const char * arg; int res = 0; diff --git a/lib/rpmcli.h b/lib/rpmcli.h index cd60d07..e8f348e 100644 --- a/lib/rpmcli.h +++ b/lib/rpmcli.h @@ -266,7 +266,7 @@ int showQueryPackage(QVA_t qva, rpmts ts, Header h); * @param argv query argument(s) (or NULL) * @return 0 on success, else no. of failures */ -int rpmcliArgIter(rpmts ts, QVA_t qva, ARGV_t argv); +int rpmcliArgIter(rpmts ts, QVA_t qva, ARGV_const_t argv); /** \ingroup rpmcli * Display package information. @@ -276,7 +276,7 @@ int rpmcliArgIter(rpmts ts, QVA_t qva, ARGV_t argv); * @param argv query argument(s) (or NULL) * @return 0 on success, else no. of failures */ -int rpmcliQuery(rpmts ts, QVA_t qva, const char ** argv); +int rpmcliQuery(rpmts ts, QVA_t qva, ARGV_const_t argv); /** \ingroup rpmcli * Display results of package verify. @@ -305,7 +305,7 @@ int rpmVerifySignatures(QVA_t qva, rpmts ts, FD_t fd, const char * fn); * @param argv verify argument(s) (or NULL) * @return 0 on success, else no. of failures */ -int rpmcliVerify(rpmts ts, QVA_t qva, const char ** argv); +int rpmcliVerify(rpmts ts, QVA_t qva, ARGV_const_t argv); /* ==================================================================== */ /** \name RPMBT */ @@ -436,9 +436,10 @@ struct rpmInstallArguments_s { * @param ia mode flags and parameters * @param fileArgv array of package file names (NULL terminated) * @return 0 on success + * + * @todo fileArgv is modified on errors, should be ARGV_const_t */ -int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, - const char ** fileArgv); +int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_t fileArgv); /** \ingroup rpmcli * Erase binary rpm package. @@ -448,8 +449,7 @@ int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, * @return 0 on success */ -int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, - const char ** argv); +int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv); /** \ingroup rpmcli */ @@ -506,7 +506,7 @@ extern struct poptOption rpmSignPoptTable[]; * @param argv array of arguments (NULL terminated) * @return 0 on success */ -int rpmcliSign(rpmts ts, QVA_t qva, const char ** argv); +int rpmcliSign(rpmts ts, QVA_t qva, ARGV_const_t argv); #ifdef __cplusplus } diff --git a/lib/rpmgi.c b/lib/rpmgi.c index 0adddd1..f4e1443 100644 --- a/lib/rpmgi.c +++ b/lib/rpmgi.c @@ -287,7 +287,7 @@ static rpmRC rpmgiWalkReadHeader(rpmgi gi) * @param argv arg list to be globbed (or NULL) * @returns RPMRC_OK on success */ -static rpmRC rpmgiGlobArgv(rpmgi gi, ARGV_t argv) +static rpmRC rpmgiGlobArgv(rpmgi gi, ARGV_const_t argv) { const char * arg; rpmRC rpmrc = RPMRC_OK; @@ -340,7 +340,7 @@ if (_rpmgi_debug < 0) fprintf(stderr, "*** gi %p\tmi %p\n", gi, gi->mi); if (gi->argv != NULL) - for (av = (const char **) gi->argv; *av != NULL; av++) { + for (av = gi->argv; *av != NULL; av++) { rpmTag tag = RPMTAG_NAME; const char * pat; char * a, * ae; @@ -665,7 +665,7 @@ rpmts rpmgiTs(rpmgi gi) return (gi != NULL ? gi->ts : NULL); } -rpmRC rpmgiSetArgs(rpmgi gi, ARGV_t argv, int ftsOpts, rpmgiFlags flags) +rpmRC rpmgiSetArgs(rpmgi gi, ARGV_const_t argv, int ftsOpts, rpmgiFlags flags) { gi->ftsOpts = ftsOpts; gi->flags = flags; diff --git a/lib/rpmgi.h b/lib/rpmgi.h index e693be0..8dfc6f2 100644 --- a/lib/rpmgi.h +++ b/lib/rpmgi.h @@ -111,7 +111,7 @@ rpmts rpmgiTs(rpmgi gi); * @param flags iterator flags * @return RPMRC_OK on success */ -rpmRC rpmgiSetArgs(rpmgi gi, ARGV_t argv, +rpmRC rpmgiSetArgs(rpmgi gi, ARGV_const_t argv, int ftsOpts, rpmgiFlags flags); diff --git a/lib/rpminstall.c b/lib/rpminstall.c index fb249fa..41a94c5 100644 --- a/lib/rpminstall.c +++ b/lib/rpminstall.c @@ -187,21 +187,19 @@ void * rpmShowProgress(const void * arg, return rc; } -typedef const char * str_t; - struct rpmEIU { Header h; FD_t fd; int numFailed; int numPkgs; char ** pkgURL; - str_t * fnp; + char ** fnp; char * pkgState; int prevx; int pkgx; int numRPMS; int numSRPMS; - str_t * sourceURL; + char ** sourceURL; int isSource; int argc; char ** argv; @@ -210,9 +208,7 @@ struct rpmEIU { }; /** @todo Generalize --freshen policies. */ -int rpmInstall(rpmts ts, - struct rpmInstallArguments_s * ia, - const char ** fileArgv) +int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_t fileArgv) { struct rpmEIU * eiu = memset(alloca(sizeof(*eiu)), 0, sizeof(*eiu)); rpmps ps; @@ -378,7 +374,7 @@ if (fileURL[0] == '=') { if (eiu->numFailed) goto exit; /* Continue processing file arguments, building transaction set. */ - for (eiu->fnp = (const char**) eiu->pkgURL+eiu->prevx; + for (eiu->fnp = eiu->pkgURL+eiu->prevx; *eiu->fnp != NULL; eiu->fnp++, eiu->prevx++) { @@ -649,11 +645,10 @@ exit: return eiu->numFailed; } -int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, - const char ** argv) +int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv) { int count; - const char ** arg; + char * const * arg; int numFailed = 0; int stopUninstall = 0; int numPackages = 0; diff --git a/lib/verify.c b/lib/verify.c index d2d38c9..00f0d69 100644 --- a/lib/verify.c +++ b/lib/verify.c @@ -422,7 +422,7 @@ int showVerifyPackage(QVA_t qva, rpmts ts, Header h) return ec; } -int rpmcliVerify(rpmts ts, QVA_t qva, const char ** argv) +int rpmcliVerify(rpmts ts, QVA_t qva, char * const * argv) { rpmVSFlags vsflags, ovsflags; int ec = 0; diff --git a/rpmio/argv.c b/rpmio/argv.c index 2e26c93..c55ecb0 100644 --- a/rpmio/argv.c +++ b/rpmio/argv.c @@ -60,7 +60,7 @@ ARGint_t argiData(const ARGI_t argi) return vals; } -int argvCount(const ARGV_t argv) +int argvCount(ARGV_const_t argv) { int argc = 0; if (argv) @@ -69,7 +69,7 @@ int argvCount(const ARGV_t argv) return argc; } -ARGV_t argvData(const ARGV_t argv) +ARGV_t argvData(ARGV_t argv) { return argv; } @@ -89,7 +89,7 @@ int argvSort(ARGV_t argv, int (*compar)(const void *, const void *)) return 0; } -ARGV_t argvSearch(ARGV_t argv, const char *val, +ARGV_t argvSearch(ARGV_const_t argv, const char *val, int (*compar)(const void *, const void *)) { if (argv == NULL) @@ -135,7 +135,7 @@ int argvAdd(ARGV_t * argvp, const char *val) return 0; } -int argvAppend(ARGV_t * argvp, const ARGV_t av) +int argvAppend(ARGV_t * argvp, ARGV_const_t av) { ARGV_t argv = *argvp; int argc = argvCount(argv); diff --git a/rpmio/argv.h b/rpmio/argv.h index 840cb19..426c568 100644 --- a/rpmio/argv.h +++ b/rpmio/argv.h @@ -12,6 +12,7 @@ extern "C" { #endif typedef char ** ARGV_t; +typedef char * const *ARGV_const_t; typedef int * ARGint_t; struct ARGI_s { @@ -61,14 +62,14 @@ ARGint_t argiData(const ARGI_t argi); * @param argv argv array * @return no. of elements */ -int argvCount(const ARGV_t argv); +int argvCount(ARGV_const_t argv); /** \ingroup rpmargv * Return data from argv array. * @param argv argv array * @return argv array data address */ -ARGV_t argvData(const ARGV_t argv); +ARGV_t argvData(ARGV_t argv); /** \ingroup rpmargv * Compare argv arrays (qsort/bsearch). @@ -93,7 +94,7 @@ int argvSort(ARGV_t argv, int (*compar)(const void *, const void *)); * @param compar strcmp-like comparison function, or NULL for argvCmp() * @return found string (NULL on failure) */ -ARGV_t argvSearch(ARGV_t argv, const char *val, +ARGV_t argvSearch(ARGV_const_t argv, const char *val, int (*compar)(const void *, const void *)); /** \ingroup rpmargv @@ -119,7 +120,7 @@ int argvAdd(ARGV_t * argvp, const char *val); * @param av argv array to append * @return 0 always */ -int argvAppend(ARGV_t * argvp, const ARGV_t av); +int argvAppend(ARGV_t * argvp, ARGV_const_t av); /** \ingroup rpmargv * Split a string into an argv array. diff --git a/rpmio/rpmfileutil.c b/rpmio/rpmfileutil.c index 93f6dc8..6302901 100644 --- a/rpmio/rpmfileutil.c +++ b/rpmio/rpmfileutil.c @@ -104,9 +104,9 @@ static int open_dso(const char * path, pid_t * pidp, rpm_off_t *fsizep) xx = dup2(pipes[1], STDOUT_FILENO); xx = close(pipes[1]); if ((lib = argvSearch(av, "library", NULL)) != NULL) { - *lib = path; + *lib = (char *) path; unsetenv("MALLOC_CHECK_"); - xx = execve(av[0], (char *const *)av+1, environ); + xx = execve(av[0], av+1, environ); } _exit(127); } diff --git a/rpmqv.c b/rpmqv.c index 4e54aae..400b816 100644 --- a/rpmqv.c +++ b/rpmqv.c @@ -714,7 +714,7 @@ int main(int argc, char *argv[]) if (!poptPeekArg(optCon)) { argerror(_("no packages given for erase")); } else { - ec += rpmErase(ts, ia, (const char **) poptGetArgs(optCon)); + ec += rpmErase(ts, ia, (ARGV_const_t) poptGetArgs(optCon)); } break; @@ -749,7 +749,7 @@ int main(int argc, char *argv[]) argerror(_("no packages given for install")); } else { /* FIX: ia->relocations[0].newPath undefined */ - ec += rpmInstall(ts, ia, (const char **)poptGetArgs(optCon)); + ec += rpmInstall(ts, ia, (ARGV_t) poptGetArgs(optCon)); } break; @@ -762,7 +762,7 @@ int main(int argc, char *argv[]) argerror(_("no arguments given for query")); qva->qva_specQuery = rpmspecQuery; - ec = rpmcliQuery(ts, qva, (const char **) poptGetArgs(optCon)); + ec = rpmcliQuery(ts, qva, (ARGV_const_t) poptGetArgs(optCon)); qva->qva_specQuery = NULL; break; @@ -775,7 +775,7 @@ int main(int argc, char *argv[]) if (!poptPeekArg(optCon) && !(qva->qva_source == RPMQV_ALL || qva->qva_source == RPMQV_HDLIST)) argerror(_("no arguments given for verify")); - ec = rpmcliVerify(ts, qva, (const char **) poptGetArgs(optCon)); + ec = rpmcliVerify(ts, qva, (ARGV_const_t) poptGetArgs(optCon)); } break; #endif /* IAM_RPMQV */ @@ -791,7 +791,7 @@ int main(int argc, char *argv[]) if (!poptPeekArg(optCon)) argerror(_("no arguments given")); ka->passPhrase = passPhrase; - ec = rpmcliSign(ts, ka, (const char **)poptGetArgs(optCon)); + ec = rpmcliSign(ts, ka, (ARGV_const_t) poptGetArgs(optCon)); break; #endif /* IAM_RPMK */ diff --git a/tools/rpmdeps.c b/tools/rpmdeps.c index fb906df..5f34c2b 100644 --- a/tools/rpmdeps.c +++ b/tools/rpmdeps.c @@ -62,7 +62,7 @@ char buf[BUFSIZ]; if (optCon == NULL) goto exit; - av = poptGetArgs(optCon); + av = (ARGV_t) poptGetArgs(optCon); ac = argvCount(av); if (ac == 0) { -- 2.7.4