From 29bf6814f74096e5d8ea22058e638eb362717b8a Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 15 Jun 2008 19:15:36 -0500 Subject: Use access() instead of stat() when possible We were using the stat() system call in quite a few places when we didn't actually need anything the stat struct returned- we were simply checking for file existence. access() will be more efficient in those cases. Before (strace pacman -Ss pacman): % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 33.16 0.005987 0 19016 stat64 After: % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 34.85 0.003863 0 12633 1 access 7.95 0.000881 0 6391 7 stat64 Signed-off-by: Dan McGee --- src/pacman/util.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/pacman/util.c') diff --git a/src/pacman/util.c b/src/pacman/util.c index e702886b..d7ac9e38 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -125,7 +124,7 @@ int makepath(const char *path) * 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 + * incr - incrementally generated path for use in access/mkdir call */ char *orig, *str, *ptr, *incr; mode_t oldmask = umask(0000); @@ -136,12 +135,11 @@ int makepath(const char *path) str = orig; while((ptr = strsep(&str, "/"))) { if(strlen(ptr)) { - struct stat buf; /* 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(access(incr, F_OK)) { if(mkdir(incr, 0755)) { ret = 1; break; -- cgit v1.2.3