summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2008-05-05 01:39:22 +0200
committerDan McGee <dan@archlinux.org>2008-05-10 07:51:04 +0200
commitb49fc504acffa470cce31fb889723ecd86b314de (patch)
tree4d33ba65ac2acc007f811c7f29a3b11b4f7d77f5 /src
parent2edd01a973f9695b6bb918ccdbaabd004058f578 (diff)
downloadpacman-b49fc504acffa470cce31fb889723ecd86b314de.tar.gz
pacman-b49fc504acffa470cce31fb889723ecd86b314de.tar.xz
Update makepath to remove PATH_MAX usage
The start of a few commits to remove some PATH_MAX usage from our code. Use a dynamically allocated string instead. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r--src/pacman/util.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 9617e6f2..f1f098f8 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -121,33 +121,38 @@ int getcols()
/* does the same thing as 'mkdir -p' */
int makepath(const char *path)
{
- char *orig, *str, *ptr;
- char full[PATH_MAX+1] = "";
- mode_t oldmask;
-
- oldmask = umask(0000);
+ /* A bit of pointer hell here. Descriptions:
+ * orig - a copy of path so we can safely butcher it with strsep
+ * str - the current position in the path string (after the delimiter)
+ * ptr - the original position of str after calling strsep
+ * incr - incrementally generated path for use in stat/mkdir call
+ */
+ char *orig, *str, *ptr, *incr;
+ mode_t oldmask = umask(0000);
+ int ret = 0;
orig = strdup(path);
+ incr = calloc(strlen(orig) + 1, sizeof(char));
str = orig;
while((ptr = strsep(&str, "/"))) {
if(strlen(ptr)) {
struct stat buf;
-
- /* TODO we should use strncat */
- strcat(full, "/");
- strcat(full, ptr);
- if(stat(full, &buf)) {
- if(mkdir(full, 0755)) {
- free(orig);
- umask(oldmask);
- return(1);
+ /* we have another path component- append the newest component to
+ * existing string and create one more level of dir structure */
+ strcat(incr, "/");
+ strcat(incr, ptr);
+ if(stat(incr, &buf)) {
+ if(mkdir(incr, 0755)) {
+ ret = 1;
+ break;
}
}
}
}
free(orig);
+ free(incr);
umask(oldmask);
- return(0);
+ return(ret);
}
/* does the same thing as 'rm -rf' */