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/util/testdb.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/util') diff --git a/src/util/testdb.c b/src/util/testdb.c index f354ecab..87bfcf96 100644 --- a/src/util/testdb.c +++ b/src/util/testdb.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -61,7 +60,6 @@ static int db_test(char *dbpath) { struct dirent *ent; char path[PATH_MAX]; - struct stat buf; int ret = 0; DIR *dir; @@ -77,17 +75,17 @@ static int db_test(char *dbpath) } /* check for desc, depends, and files */ snprintf(path, PATH_MAX, "%s/%s/desc", dbpath, ent->d_name); - if(stat(path, &buf)) { + if(access(path, F_OK)) { printf("%s: description file is missing\n", ent->d_name); ret++; } snprintf(path, PATH_MAX, "%s/%s/depends", dbpath, ent->d_name); - if(stat(path, &buf)) { + if(access(path, F_OK)) { printf("%s: dependency file is missing\n", ent->d_name); ret++; } snprintf(path, PATH_MAX, "%s/%s/files", dbpath, ent->d_name); - if(stat(path, &buf)) { + if(access(path, F_OK)) { printf("%s: file list is missing\n", ent->d_name); ret++; } -- cgit v1.2.3-24-g4f1b