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...
This commit is contained in:
Panu Matilainen 2008-04-07 12:11:16 +03:00
parent d728ec28dc
commit c29adcee80
15 changed files with 47 additions and 54 deletions

View File

@ -2246,7 +2246,7 @@ int processSourceFiles(rpmSpec spec)
*/ */
static int checkFiles(StringBuf fileList) 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; StringBuf sb_stdout = NULL;
char * s; char * s;
int rc; int rc;

View File

@ -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; ARGV_t argv = *argvp;
int argc = argvCount(argv); int argc = argvCount(argv);
@ -227,7 +227,7 @@ top:
return readBuff; 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) int failnonzero)
{ {
char * s = NULL; char * s = NULL;
@ -345,7 +345,7 @@ static int rpmfcHelper(rpmfc fc, unsigned char deptype, const char * nsdep)
char *buf = NULL; char *buf = NULL;
StringBuf sb_stdout = NULL; StringBuf sb_stdout = NULL;
StringBuf sb_stdin; StringBuf sb_stdin;
const char *av[2]; char *av[2];
rpmds * depsp, ds; rpmds * depsp, ds;
const char * N; const char * N;
const char * EVR; const char * EVR;
@ -1343,7 +1343,7 @@ typedef struct DepMsg_s * DepMsg_t;
*/ */
struct DepMsg_s { struct DepMsg_s {
const char * msg; const char * msg;
const char * argv[4]; char * const argv[4];
rpmTag ntag; rpmTag ntag;
rpmTag vtag; rpmTag vtag;
rpmTag ftag; rpmTag ftag;

View File

@ -86,7 +86,7 @@ typedef const struct rpmfcTokens_s * rpmfcToken;
* @retval *sb_stdoutp helper output * @retval *sb_stdoutp helper output
* @param failnonzero IS non-zero helper exit status a failure? * @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); int failnonzero);
/** \ingroup rpmfc /** \ingroup rpmfc

View File

@ -675,7 +675,7 @@ int rpmQueryVerify(QVA_t qva, rpmts ts, const char * arg)
return res; 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; rpmRC rpmrc = RPMRC_NOTFOUND;
int ec = 0; int ec = 0;
@ -755,7 +755,7 @@ int rpmcliArgIter(rpmts ts, QVA_t qva, ARGV_t argv)
return ec; 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; rpmVSFlags vsflags, ovsflags;
int ec = 0; int ec = 0;

View File

@ -137,8 +137,7 @@ static int getSignid(Header sig, rpmSigTag sigtag, pgpKeyID_t signid)
* @param argv array of package file names (NULL terminated) * @param argv array of package file names (NULL terminated)
* @return 0 on success * @return 0 on success
*/ */
static int rpmReSign(rpmts ts, static int rpmReSign(rpmts ts, QVA_t qva, ARGV_const_t argv)
QVA_t qva, const char ** argv)
{ {
FD_t fd = NULL; FD_t fd = NULL;
FD_t ofd = NULL; FD_t ofd = NULL;
@ -398,9 +397,7 @@ exit:
* @param argv array of pubkey file names (NULL terminated) * @param argv array of pubkey file names (NULL terminated)
* @return 0 on success * @return 0 on success
*/ */
static int rpmcliImportPubkeys(const rpmts ts, static int rpmcliImportPubkeys(const rpmts ts, QVA_t qva, ARGV_const_t argv)
QVA_t qva,
const char ** argv)
{ {
const char * fn; const char * fn;
unsigned char * pkt = NULL; unsigned char * pkt = NULL;
@ -797,7 +794,7 @@ exit:
return res; 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; const char * arg;
int res = 0; int res = 0;

View File

@ -266,7 +266,7 @@ int showQueryPackage(QVA_t qva, rpmts ts, Header h);
* @param argv query argument(s) (or NULL) * @param argv query argument(s) (or NULL)
* @return 0 on success, else no. of failures * @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 /** \ingroup rpmcli
* Display package information. * Display package information.
@ -276,7 +276,7 @@ int rpmcliArgIter(rpmts ts, QVA_t qva, ARGV_t argv);
* @param argv query argument(s) (or NULL) * @param argv query argument(s) (or NULL)
* @return 0 on success, else no. of failures * @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 /** \ingroup rpmcli
* Display results of package verify. * 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) * @param argv verify argument(s) (or NULL)
* @return 0 on success, else no. of failures * @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 */ /** \name RPMBT */
@ -436,9 +436,10 @@ struct rpmInstallArguments_s {
* @param ia mode flags and parameters * @param ia mode flags and parameters
* @param fileArgv array of package file names (NULL terminated) * @param fileArgv array of package file names (NULL terminated)
* @return 0 on success * @return 0 on success
*
* @todo fileArgv is modified on errors, should be ARGV_const_t
*/ */
int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_t fileArgv);
const char ** fileArgv);
/** \ingroup rpmcli /** \ingroup rpmcli
* Erase binary rpm package. * Erase binary rpm package.
@ -448,8 +449,7 @@ int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia,
* @return 0 on success * @return 0 on success
*/ */
int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv);
const char ** argv);
/** \ingroup rpmcli /** \ingroup rpmcli
*/ */
@ -506,7 +506,7 @@ extern struct poptOption rpmSignPoptTable[];
* @param argv array of arguments (NULL terminated) * @param argv array of arguments (NULL terminated)
* @return 0 on success * @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 #ifdef __cplusplus
} }

View File

@ -287,7 +287,7 @@ static rpmRC rpmgiWalkReadHeader(rpmgi gi)
* @param argv arg list to be globbed (or NULL) * @param argv arg list to be globbed (or NULL)
* @returns RPMRC_OK on success * @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; const char * arg;
rpmRC rpmrc = RPMRC_OK; rpmRC rpmrc = RPMRC_OK;
@ -340,7 +340,7 @@ if (_rpmgi_debug < 0)
fprintf(stderr, "*** gi %p\tmi %p\n", gi, gi->mi); fprintf(stderr, "*** gi %p\tmi %p\n", gi, gi->mi);
if (gi->argv != NULL) if (gi->argv != NULL)
for (av = (const char **) gi->argv; *av != NULL; av++) { for (av = gi->argv; *av != NULL; av++) {
rpmTag tag = RPMTAG_NAME; rpmTag tag = RPMTAG_NAME;
const char * pat; const char * pat;
char * a, * ae; char * a, * ae;
@ -665,7 +665,7 @@ rpmts rpmgiTs(rpmgi gi)
return (gi != NULL ? gi->ts : NULL); 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->ftsOpts = ftsOpts;
gi->flags = flags; gi->flags = flags;

View File

@ -111,7 +111,7 @@ rpmts rpmgiTs(rpmgi gi);
* @param flags iterator flags * @param flags iterator flags
* @return RPMRC_OK on success * @return RPMRC_OK on success
*/ */
rpmRC rpmgiSetArgs(rpmgi gi, ARGV_t argv, rpmRC rpmgiSetArgs(rpmgi gi, ARGV_const_t argv,
int ftsOpts, rpmgiFlags flags); int ftsOpts, rpmgiFlags flags);

View File

@ -187,21 +187,19 @@ void * rpmShowProgress(const void * arg,
return rc; return rc;
} }
typedef const char * str_t;
struct rpmEIU { struct rpmEIU {
Header h; Header h;
FD_t fd; FD_t fd;
int numFailed; int numFailed;
int numPkgs; int numPkgs;
char ** pkgURL; char ** pkgURL;
str_t * fnp; char ** fnp;
char * pkgState; char * pkgState;
int prevx; int prevx;
int pkgx; int pkgx;
int numRPMS; int numRPMS;
int numSRPMS; int numSRPMS;
str_t * sourceURL; char ** sourceURL;
int isSource; int isSource;
int argc; int argc;
char ** argv; char ** argv;
@ -210,9 +208,7 @@ struct rpmEIU {
}; };
/** @todo Generalize --freshen policies. */ /** @todo Generalize --freshen policies. */
int rpmInstall(rpmts ts, int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_t fileArgv)
struct rpmInstallArguments_s * ia,
const char ** fileArgv)
{ {
struct rpmEIU * eiu = memset(alloca(sizeof(*eiu)), 0, sizeof(*eiu)); struct rpmEIU * eiu = memset(alloca(sizeof(*eiu)), 0, sizeof(*eiu));
rpmps ps; rpmps ps;
@ -378,7 +374,7 @@ if (fileURL[0] == '=') {
if (eiu->numFailed) goto exit; if (eiu->numFailed) goto exit;
/* Continue processing file arguments, building transaction set. */ /* 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 != NULL;
eiu->fnp++, eiu->prevx++) eiu->fnp++, eiu->prevx++)
{ {
@ -649,11 +645,10 @@ exit:
return eiu->numFailed; return eiu->numFailed;
} }
int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv)
const char ** argv)
{ {
int count; int count;
const char ** arg; char * const * arg;
int numFailed = 0; int numFailed = 0;
int stopUninstall = 0; int stopUninstall = 0;
int numPackages = 0; int numPackages = 0;

View File

@ -422,7 +422,7 @@ int showVerifyPackage(QVA_t qva, rpmts ts, Header h)
return ec; 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; rpmVSFlags vsflags, ovsflags;
int ec = 0; int ec = 0;

View File

@ -60,7 +60,7 @@ ARGint_t argiData(const ARGI_t argi)
return vals; return vals;
} }
int argvCount(const ARGV_t argv) int argvCount(ARGV_const_t argv)
{ {
int argc = 0; int argc = 0;
if (argv) if (argv)
@ -69,7 +69,7 @@ int argvCount(const ARGV_t argv)
return argc; return argc;
} }
ARGV_t argvData(const ARGV_t argv) ARGV_t argvData(ARGV_t argv)
{ {
return argv; return argv;
} }
@ -89,7 +89,7 @@ int argvSort(ARGV_t argv, int (*compar)(const void *, const void *))
return 0; 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 *)) int (*compar)(const void *, const void *))
{ {
if (argv == NULL) if (argv == NULL)
@ -135,7 +135,7 @@ int argvAdd(ARGV_t * argvp, const char *val)
return 0; return 0;
} }
int argvAppend(ARGV_t * argvp, const ARGV_t av) int argvAppend(ARGV_t * argvp, ARGV_const_t av)
{ {
ARGV_t argv = *argvp; ARGV_t argv = *argvp;
int argc = argvCount(argv); int argc = argvCount(argv);

View File

@ -12,6 +12,7 @@ extern "C" {
#endif #endif
typedef char ** ARGV_t; typedef char ** ARGV_t;
typedef char * const *ARGV_const_t;
typedef int * ARGint_t; typedef int * ARGint_t;
struct ARGI_s { struct ARGI_s {
@ -61,14 +62,14 @@ ARGint_t argiData(const ARGI_t argi);
* @param argv argv array * @param argv argv array
* @return no. of elements * @return no. of elements
*/ */
int argvCount(const ARGV_t argv); int argvCount(ARGV_const_t argv);
/** \ingroup rpmargv /** \ingroup rpmargv
* Return data from argv array. * Return data from argv array.
* @param argv argv array * @param argv argv array
* @return argv array data address * @return argv array data address
*/ */
ARGV_t argvData(const ARGV_t argv); ARGV_t argvData(ARGV_t argv);
/** \ingroup rpmargv /** \ingroup rpmargv
* Compare argv arrays (qsort/bsearch). * 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() * @param compar strcmp-like comparison function, or NULL for argvCmp()
* @return found string (NULL on failure) * @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 *)); int (*compar)(const void *, const void *));
/** \ingroup rpmargv /** \ingroup rpmargv
@ -119,7 +120,7 @@ int argvAdd(ARGV_t * argvp, const char *val);
* @param av argv array to append * @param av argv array to append
* @return 0 always * @return 0 always
*/ */
int argvAppend(ARGV_t * argvp, const ARGV_t av); int argvAppend(ARGV_t * argvp, ARGV_const_t av);
/** \ingroup rpmargv /** \ingroup rpmargv
* Split a string into an argv array. * Split a string into an argv array.

View File

@ -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 = dup2(pipes[1], STDOUT_FILENO);
xx = close(pipes[1]); xx = close(pipes[1]);
if ((lib = argvSearch(av, "library", NULL)) != NULL) { if ((lib = argvSearch(av, "library", NULL)) != NULL) {
*lib = path; *lib = (char *) path;
unsetenv("MALLOC_CHECK_"); unsetenv("MALLOC_CHECK_");
xx = execve(av[0], (char *const *)av+1, environ); xx = execve(av[0], av+1, environ);
} }
_exit(127); _exit(127);
} }

10
rpmqv.c
View File

@ -714,7 +714,7 @@ int main(int argc, char *argv[])
if (!poptPeekArg(optCon)) { if (!poptPeekArg(optCon)) {
argerror(_("no packages given for erase")); argerror(_("no packages given for erase"));
} else { } else {
ec += rpmErase(ts, ia, (const char **) poptGetArgs(optCon)); ec += rpmErase(ts, ia, (ARGV_const_t) poptGetArgs(optCon));
} }
break; break;
@ -749,7 +749,7 @@ int main(int argc, char *argv[])
argerror(_("no packages given for install")); argerror(_("no packages given for install"));
} else { } else {
/* FIX: ia->relocations[0].newPath undefined */ /* FIX: ia->relocations[0].newPath undefined */
ec += rpmInstall(ts, ia, (const char **)poptGetArgs(optCon)); ec += rpmInstall(ts, ia, (ARGV_t) poptGetArgs(optCon));
} }
break; break;
@ -762,7 +762,7 @@ int main(int argc, char *argv[])
argerror(_("no arguments given for query")); argerror(_("no arguments given for query"));
qva->qva_specQuery = rpmspecQuery; 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; qva->qva_specQuery = NULL;
break; break;
@ -775,7 +775,7 @@ int main(int argc, char *argv[])
if (!poptPeekArg(optCon) if (!poptPeekArg(optCon)
&& !(qva->qva_source == RPMQV_ALL || qva->qva_source == RPMQV_HDLIST)) && !(qva->qva_source == RPMQV_ALL || qva->qva_source == RPMQV_HDLIST))
argerror(_("no arguments given for verify")); argerror(_("no arguments given for verify"));
ec = rpmcliVerify(ts, qva, (const char **) poptGetArgs(optCon)); ec = rpmcliVerify(ts, qva, (ARGV_const_t) poptGetArgs(optCon));
} break; } break;
#endif /* IAM_RPMQV */ #endif /* IAM_RPMQV */
@ -791,7 +791,7 @@ int main(int argc, char *argv[])
if (!poptPeekArg(optCon)) if (!poptPeekArg(optCon))
argerror(_("no arguments given")); argerror(_("no arguments given"));
ka->passPhrase = passPhrase; ka->passPhrase = passPhrase;
ec = rpmcliSign(ts, ka, (const char **)poptGetArgs(optCon)); ec = rpmcliSign(ts, ka, (ARGV_const_t) poptGetArgs(optCon));
break; break;
#endif /* IAM_RPMK */ #endif /* IAM_RPMK */

View File

@ -62,7 +62,7 @@ char buf[BUFSIZ];
if (optCon == NULL) if (optCon == NULL)
goto exit; goto exit;
av = poptGetArgs(optCon); av = (ARGV_t) poptGetArgs(optCon);
ac = argvCount(av); ac = argvCount(av);
if (ac == 0) { if (ac == 0) {