summaryrefslogtreecommitdiffstats
path: root/src/pacman/package.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2008-06-16 02:15:36 +0200
committerDan McGee <dan@archlinux.org>2008-06-16 05:52:27 +0200
commit29bf6814f74096e5d8ea22058e638eb362717b8a (patch)
tree1b608ba8071c1c7e52808a4b178ba8225ef6d2b1 /src/pacman/package.c
parent7ff5a917fd0a91cd03ba61419a57053e4ae17e92 (diff)
downloadpacman-29bf6814f74096e5d8ea22058e638eb362717b8a.tar.gz
pacman-29bf6814f74096e5d8ea22058e638eb362717b8a.tar.xz
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 <dan@archlinux.org>
Diffstat (limited to 'src/pacman/package.c')
-rw-r--r--src/pacman/package.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/pacman/package.c b/src/pacman/package.c
index 1698806f..06800378 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -22,8 +22,8 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
#include <limits.h>
-#include <sys/stat.h>
#include <wchar.h>
#include <alpm.h>
@@ -176,7 +176,6 @@ void dump_pkg_backups(pmpkg_t *pkg)
if(alpm_pkg_get_backup(pkg)) {
/* package has backup files, so print them */
for(i = alpm_pkg_get_backup(pkg); i; i = alpm_list_next(i)) {
- struct stat buf;
char path[PATH_MAX];
char *str = strdup(alpm_list_getdata(i));
char *ptr = index(str, '\t');
@@ -188,7 +187,7 @@ void dump_pkg_backups(pmpkg_t *pkg)
ptr++;
snprintf(path, PATH_MAX-1, "%s%s", root, str);
/* if we find the file, calculate checksums, otherwise it is missing */
- if(!stat(path, &buf)) {
+ if(access(path, R_OK) == 0) {
char *md5sum = alpm_get_md5sum(path);
if(md5sum == NULL) {