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 --- lib/libalpm/be_files.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/libalpm/be_files.c') diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c index 12c60b24..f5d4e826 100644 --- a/lib/libalpm/be_files.c +++ b/lib/libalpm/be_files.c @@ -355,7 +355,6 @@ static char *get_pkgpath(pmdb_t *db, pmpkg_t *info) int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq) { FILE *fp = NULL; - struct stat buf; char path[PATH_MAX]; char line[513]; char *pkgpath = NULL; @@ -393,7 +392,7 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq) pkgpath = get_pkgpath(db, info); - if(stat(pkgpath, &buf)) { + if(access(pkgpath, F_OK)) { /* directory doesn't exist or can't be opened */ _alpm_log(PM_LOG_DEBUG, "cannot find '%s-%s' in db '%s'\n", info->name, info->version, db->treename); @@ -631,7 +630,7 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq) /* INSTALL */ if(inforeq & INFRQ_SCRIPTLET) { snprintf(path, PATH_MAX, "%sinstall", pkgpath); - if(!stat(path, &buf)) { + if(access(path, F_OK) == 0) { info->scriptlet = 1; } } -- cgit v1.2.3