From 2c6905dd9f10589e80eb9292992510a1e070cfe4 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 23 Nov 2007 10:20:19 +0200 Subject: [PATCH] Move rpmGetPath and rpmGenPath to rpmfileutil.h --- build/parseFiles.c | 1 + build/parsePreamble.c | 1 + build/parseSpec.c | 1 + build/spec.c | 1 + lib/fs.c | 2 +- lib/rpminstall.c | 4 +-- lib/rpmlock.c | 1 + lib/rpmrc.c | 1 + lib/rpmts.c | 3 +- rpmio/macro.c | 81 --------------------------------------------------- rpmio/rpmfileutil.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ rpmio/rpmfileutil.h | 23 +++++++++++++++ rpmio/rpmio.c | 1 + rpmio/rpmmacro.h | 23 --------------- 14 files changed, 116 insertions(+), 108 deletions(-) diff --git a/build/parseFiles.c b/build/parseFiles.c index 8549b44..bd12c05 100644 --- a/build/parseFiles.c +++ b/build/parseFiles.c @@ -7,6 +7,7 @@ #include #include +#include #include "debug.h" /* These have to be global scope to make up for *stupid* compilers */ diff --git a/build/parsePreamble.c b/build/parsePreamble.c index 226ddd1..2593313 100644 --- a/build/parsePreamble.c +++ b/build/parsePreamble.c @@ -7,6 +7,7 @@ #include #include +#include #include "debug.h" #define SKIPSPACE(s) { while (*(s) && xisspace(*(s))) (s)++; } diff --git a/build/parseSpec.c b/build/parseSpec.c index ddc29b8..50230ac 100644 --- a/build/parseSpec.c +++ b/build/parseSpec.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "debug.h" #define SKIPSPACE(s) { while (*(s) && xisspace(*(s))) (s)++; } diff --git a/build/spec.c b/build/spec.c index 558837c..ff7697e 100644 --- a/build/spec.c +++ b/build/spec.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "debug.h" diff --git a/lib/fs.c b/lib/fs.c index 8e1b34c..9489acc 100644 --- a/lib/fs.c +++ b/lib/fs.c @@ -4,7 +4,7 @@ #include "system.h" #include -#include /* XXX for rpmGetPath */ +#include /* for rpmGetPath */ #include #include "debug.h" diff --git a/lib/rpminstall.c b/lib/rpminstall.c index bd7a5ee..39c91aa 100644 --- a/lib/rpminstall.c +++ b/lib/rpminstall.c @@ -8,11 +8,11 @@ #include #include - #include +#include +#include #include "manifest.h" -#include #include "debug.h" int rpmcliPackagesTotal = 0; diff --git a/lib/rpmlock.c b/lib/rpmlock.c index 2d917b7..c92ef44 100644 --- a/lib/rpmlock.c +++ b/lib/rpmlock.c @@ -3,6 +3,7 @@ #include #include +#include #include #include "rpmlock.h" diff --git a/lib/rpmrc.c b/lib/rpmrc.c index 20107ad..2bd77b3 100644 --- a/lib/rpmrc.c +++ b/lib/rpmrc.c @@ -16,6 +16,7 @@ #include "rpmio_internal.h" /* XXX for rpmioSlurp */ #include #include +#include #include #include "rpmlua.h" diff --git a/lib/rpmts.c b/lib/rpmts.c index 547acec..7b54128 100644 --- a/lib/rpmts.c +++ b/lib/rpmts.c @@ -7,7 +7,8 @@ #include #include "digest.h" #include -#include /* XXX rpmtsOpenDB() needs rpmGetPath */ +#include +#include /* rpmtsOpenDB() needs rpmGetPath */ #include #include diff --git a/rpmio/macro.c b/rpmio/macro.c index 2ab92c2..5143aee 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -1905,84 +1905,3 @@ rpmExpandNumeric(const char *arg) return rc; } -/* Return concatenated and expanded canonical path. */ - -const char * -rpmGetPath(const char *path, ...) -{ - char buf[BUFSIZ]; - const char * s; - char * t, * te; - va_list ap; - - if (path == NULL) - return xstrdup(""); - - buf[0] = '\0'; - t = buf; - te = stpcpy(t, path); - *te = '\0'; - - va_start(ap, path); - while ((s = va_arg(ap, const char *)) != NULL) { - te = stpcpy(te, s); - *te = '\0'; - } - va_end(ap); - (void) expandMacros(NULL, NULL, buf, sizeof(buf)); - - (void) rpmCleanPath(buf); - return xstrdup(buf); /* XXX xstrdup has side effects. */ -} - -/* Merge 3 args into path, any or all of which may be a url. */ - -const char * rpmGenPath(const char * urlroot, const char * urlmdir, - const char *urlfile) -{ -const char * xroot = rpmGetPath(urlroot, NULL); -const char * root = xroot; -const char * xmdir = rpmGetPath(urlmdir, NULL); -const char * mdir = xmdir; -const char * xfile = rpmGetPath(urlfile, NULL); -const char * file = xfile; - const char * result; - const char * url = NULL; - int nurl = 0; - int ut; - - ut = urlPath(xroot, &root); - if (url == NULL && ut > URL_IS_DASH) { - url = xroot; - nurl = root - xroot; - } - if (root == NULL || *root == '\0') root = "/"; - - ut = urlPath(xmdir, &mdir); - if (url == NULL && ut > URL_IS_DASH) { - url = xmdir; - nurl = mdir - xmdir; - } - if (mdir == NULL || *mdir == '\0') mdir = "/"; - - ut = urlPath(xfile, &file); - if (url == NULL && ut > URL_IS_DASH) { - url = xfile; - nurl = file - xfile; - } - - if (url && nurl > 0) { - char *t = strncpy(alloca(nurl+1), url, nurl); - t[nurl] = '\0'; - url = t; - } else - url = ""; - - result = rpmGetPath(url, root, "/", mdir, "/", file, NULL); - - xroot = _free(xroot); - xmdir = _free(xmdir); - xfile = _free(xfile); - return result; -} - diff --git a/rpmio/rpmfileutil.c b/rpmio/rpmfileutil.c index af5d57b..c9c0fba 100644 --- a/rpmio/rpmfileutil.c +++ b/rpmio/rpmfileutil.c @@ -508,3 +508,84 @@ char *rpmCleanPath(char * path) return path; } +/* Merge 3 args into path, any or all of which may be a url. */ + +const char * rpmGenPath(const char * urlroot, const char * urlmdir, + const char *urlfile) +{ +const char * xroot = rpmGetPath(urlroot, NULL); +const char * root = xroot; +const char * xmdir = rpmGetPath(urlmdir, NULL); +const char * mdir = xmdir; +const char * xfile = rpmGetPath(urlfile, NULL); +const char * file = xfile; + const char * result; + const char * url = NULL; + int nurl = 0; + int ut; + + ut = urlPath(xroot, &root); + if (url == NULL && ut > URL_IS_DASH) { + url = xroot; + nurl = root - xroot; + } + if (root == NULL || *root == '\0') root = "/"; + + ut = urlPath(xmdir, &mdir); + if (url == NULL && ut > URL_IS_DASH) { + url = xmdir; + nurl = mdir - xmdir; + } + if (mdir == NULL || *mdir == '\0') mdir = "/"; + + ut = urlPath(xfile, &file); + if (url == NULL && ut > URL_IS_DASH) { + url = xfile; + nurl = file - xfile; + } + + if (url && nurl > 0) { + char *t = strncpy(alloca(nurl+1), url, nurl); + t[nurl] = '\0'; + url = t; + } else + url = ""; + + result = rpmGetPath(url, root, "/", mdir, "/", file, NULL); + + xroot = _free(xroot); + xmdir = _free(xmdir); + xfile = _free(xfile); + return result; +} + +/* Return concatenated and expanded canonical path. */ + +const char * +rpmGetPath(const char *path, ...) +{ + char buf[BUFSIZ]; + const char * s; + char * t, * te; + va_list ap; + + if (path == NULL) + return xstrdup(""); + + buf[0] = '\0'; + t = buf; + te = stpcpy(t, path); + *te = '\0'; + + va_start(ap, path); + while ((s = va_arg(ap, const char *)) != NULL) { + te = stpcpy(te, s); + *te = '\0'; + } + va_end(ap); + (void) expandMacros(NULL, NULL, buf, sizeof(buf)); + + (void) rpmCleanPath(buf); + return xstrdup(buf); /* XXX xstrdup has side effects. */ +} + diff --git a/rpmio/rpmfileutil.h b/rpmio/rpmfileutil.h index 32644a4..94df451 100644 --- a/rpmio/rpmfileutil.h +++ b/rpmio/rpmfileutil.h @@ -65,4 +65,27 @@ int isCompressed (const char * file, */ char * rpmCleanPath (char * path); +/** + * Merge 3 args into path, any or all of which may be a url. + * The leading part of the first URL encountered is used + * for the result, other URL prefixes are discarded, permitting + * a primitive form of URL inheiritance. + * @param urlroot root URL (often path to chroot, or NULL) + * @param urlmdir directory URL (often a directory, or NULL) + * @param urlfile file URL (often a file, or NULL) + * @return expanded, merged, canonicalized path (malloc'ed) + */ +/* LCL: shrug */ +const char * rpmGenPath (const char * urlroot, + const char * urlmdir, + const char * urlfile); + +/** + * Return (malloc'ed) expanded, canonicalized, file path. + * @param path macro(s) to expand (NULL terminates list) + * @return canonicalized path (malloc'ed) + */ +/* LCL: shrug */ +const char * rpmGetPath (const char * path, ...); + #endif /* _RPMFILEUTIL_H */ diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index 29d8c7b..fe399c2 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c @@ -28,6 +28,7 @@ extern int h_errno; #include #include #include +#include #include "debug.h" diff --git a/rpmio/rpmmacro.h b/rpmio/rpmmacro.h index 0e86ded..067e29c 100644 --- a/rpmio/rpmmacro.h +++ b/rpmio/rpmmacro.h @@ -134,29 +134,6 @@ void rpmFreeMacros (rpmMacroContext mc); char * rpmExpand (const char * arg, ...); /** - * Return (malloc'ed) expanded, canonicalized, file path. - * @param path macro(s) to expand (NULL terminates list) - * @return canonicalized path (malloc'ed) - */ -/* LCL: shrug */ -const char * rpmGetPath (const char * path, ...); - -/** - * Merge 3 args into path, any or all of which may be a url. - * The leading part of the first URL encountered is used - * for the result, other URL prefixes are discarded, permitting - * a primitive form of URL inheiritance. - * @param urlroot root URL (often path to chroot, or NULL) - * @param urlmdir directory URL (often a directory, or NULL) - * @param urlfile file URL (often a file, or NULL) - * @return expanded, merged, canonicalized path (malloc'ed) - */ -/* LCL: shrug */ -const char * rpmGenPath (const char * urlroot, - const char * urlmdir, - const char * urlfile); - -/** * Return macro expansion as a numeric value. * Boolean values ('Y' or 'y' returns 1, 'N' or 'n' returns 0) * are permitted as well. An undefined macro returns 0. -- 2.7.4