diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2007-11-23 10:20:19 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2007-11-23 10:20:19 +0200 |
commit | 2c6905dd9f10589e80eb9292992510a1e070cfe4 (patch) | |
tree | c8d671da613dcb8c34f34ad488131bd61ba44739 /rpmio | |
parent | 178e32a0baf9759035e6f4b633b0396623eba80b (diff) | |
download | rpm-2c6905dd9f10589e80eb9292992510a1e070cfe4.tar.gz rpm-2c6905dd9f10589e80eb9292992510a1e070cfe4.tar.bz2 rpm-2c6905dd9f10589e80eb9292992510a1e070cfe4.zip |
Move rpmGetPath and rpmGenPath to rpmfileutil.h
Diffstat (limited to 'rpmio')
-rw-r--r-- | rpmio/macro.c | 81 | ||||
-rw-r--r-- | rpmio/rpmfileutil.c | 81 | ||||
-rw-r--r-- | rpmio/rpmfileutil.h | 23 | ||||
-rw-r--r-- | rpmio/rpmio.c | 1 | ||||
-rw-r--r-- | rpmio/rpmmacro.h | 23 |
5 files changed, 105 insertions, 104 deletions
diff --git a/rpmio/macro.c b/rpmio/macro.c index 2ab92c2c2..5143aee3d 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 af5d57b5e..c9c0fbac7 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 32644a45d..94df451c8 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 29d8c7bc3..fe399c2b1 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c @@ -28,6 +28,7 @@ extern int h_errno; #include <argv.h> #include <rpmlog.h> #include <rpmmacro.h> +#include <rpmfileutil.h> #include "debug.h" diff --git a/rpmio/rpmmacro.h b/rpmio/rpmmacro.h index 0e86dedd0..067e29cb8 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. |