From: Panu Matilainen Date: Fri, 4 Apr 2008 06:53:17 +0000 (+0300) Subject: Rename currentDirectory() to rpmGetCwd() and move to librpmio X-Git-Tag: tznext/4.11.0.1.tizen20130304~4494 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a5a3cfc3ed67083eaca0af0ffa48565a3e99bf57;p=tools%2Flibrpm-tizen.git Rename currentDirectory() to rpmGetCwd() and move to librpmio --- diff --git a/lib/misc.c b/lib/misc.c index 14b5ae4..3a2cb03 100644 --- a/lib/misc.c +++ b/lib/misc.c @@ -70,17 +70,3 @@ int dosetenv(const char * name, const char * value, int overwrite) return putenv(a); } -char * currentDirectory(void) -{ - int currDirLen = 0; - char * currDir = NULL; - - do { - currDirLen += 128; - currDir = xrealloc(currDir, currDirLen); - memset(currDir, 0, currDirLen); - } while (getcwd(currDir, currDirLen) == NULL && errno == ERANGE); - - return currDir; -} - diff --git a/lib/misc.h b/lib/misc.h index 6881574..049b2ca 100644 --- a/lib/misc.h +++ b/lib/misc.h @@ -38,12 +38,6 @@ int dosetenv(const char * name, const char * value, int overwrite); */ int doputenv(const char * str); -/** - * Return (malloc'd) current working directory. - * @return current working directory (malloc'ed) - */ -char * currentDirectory(void); - #ifdef __cplusplus } #endif diff --git a/lib/query.c b/lib/query.c index c365b19..460e644 100644 --- a/lib/query.c +++ b/lib/query.c @@ -20,7 +20,6 @@ #include /* rpmCleanPath */ #include "lib/manifest.h" -#include "lib/misc.h" /* XXX for currentDirectory */ #include "debug.h" @@ -596,7 +595,7 @@ int rpmQueryVerify(QVA_t qva, rpmts ts, const char * arg) fn = realpath(arg, fnbuf); fn = xstrdup( (fn != NULL ? fn : arg) ); } else if (*arg != '/') { - char *curDir = currentDirectory(); + char *curDir = rpmGetCwd(); fn = (char *) rpmGetPath(curDir, "/", arg, NULL); curDir = _free(curDir); } else diff --git a/lib/transaction.c b/lib/transaction.c index 8550353..dcb6573 100644 --- a/lib/transaction.c +++ b/lib/transaction.c @@ -20,7 +20,6 @@ #include "lib/rpmte_internal.h" /* XXX te->h, te->fd, te->h */ #include "lib/rpmts_internal.h" #include "lib/cpio.h" -#include "lib/misc.h" /* currentDirectory */ #include "debug.h" @@ -1037,7 +1036,7 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet) } ts->ignoreSet = ignoreSet; - { char * currDir = currentDirectory(); + { char * currDir = rpmGetCwd(); rpmtsSetCurrDir(ts, currDir); currDir = _free(currDir); } diff --git a/rpmio/rpmfileutil.c b/rpmio/rpmfileutil.c index ddd1b6f..93f6dc8 100644 --- a/rpmio/rpmfileutil.c +++ b/rpmio/rpmfileutil.c @@ -766,3 +766,18 @@ int rpmFileHasSuffix(const char *path, const char *suffix) return (plen >= slen && strcmp(path+plen-slen, suffix) == 0); } + +char * rpmGetCwd(void) +{ + int currDirLen = 0; + char * currDir = NULL; + + do { + currDirLen += 128; + currDir = xrealloc(currDir, currDirLen); + memset(currDir, 0, currDirLen); + } while (getcwd(currDir, currDirLen) == NULL && errno == ERANGE); + + return currDir; +} + diff --git a/rpmio/rpmfileutil.h b/rpmio/rpmfileutil.h index 7c36484..37dd26a 100644 --- a/rpmio/rpmfileutil.h +++ b/rpmio/rpmfileutil.h @@ -118,4 +118,10 @@ int rpmFileIsCompressed (const char * file, rpmCompressedMagic * compressed); */ int rpmFileHasSuffix(const char *path, const char *suffix); +/** \ingroup rpmfileutil + * Like getcwd() but the result is malloced. + * @return current working directory (malloc'ed) + */ +char * rpmGetCwd(void); + #endif /* _RPMFILEUTIL_H */