Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/util.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2008-06-15 19:15:36 -0500
committerDan McGee <dan@archlinux.org>2008-06-15 22:52:27 -0500
commit29bf6814f74096e5d8ea22058e638eb362717b8a (patch)
tree1b608ba8071c1c7e52808a4b178ba8225ef6d2b1 /lib/libalpm/util.c
parent7ff5a917fd0a91cd03ba61419a57053e4ae17e92 (diff)
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 'lib/libalpm/util.c')
-rw-r--r--lib/libalpm/util.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 55bd46a8..91995451 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -200,12 +200,11 @@ int _alpm_makepath_mode(const char *path, mode_t mode)
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, mode)) {
ret = 1;
break;
@@ -533,12 +532,11 @@ int _alpm_logaction(unsigned short usesyslog, FILE *f, const char *fmt, va_list
int _alpm_ldconfig(const char *root)
{
char line[PATH_MAX];
- struct stat buf;
snprintf(line, PATH_MAX, "%setc/ld.so.conf", root);
- if(stat(line, &buf) == 0) {
+ if(access(line, F_OK) == 0) {
snprintf(line, PATH_MAX, "%ssbin/ldconfig", root);
- if(stat(line, &buf) == 0) {
+ if(access(line, X_OK) == 0) {
char cmd[PATH_MAX];
snprintf(cmd, PATH_MAX, "%s -r %s", line, root);
system(cmd);
@@ -561,7 +559,6 @@ int _alpm_str_cmp(const void *s1, const void *s2)
*/
char *_alpm_filecache_find(const char* filename)
{
- struct stat buf;
char path[PATH_MAX];
char *retpath;
alpm_list_t *i;
@@ -570,8 +567,7 @@ char *_alpm_filecache_find(const char* filename)
for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) {
snprintf(path, PATH_MAX, "%s%s", (char*)alpm_list_getdata(i),
filename);
- if(stat(path, &buf) == 0) {
- /* TODO maybe check to make sure it is readable? */
+ if(access(path, R_OK) == 0) {
retpath = strdup(path);
_alpm_log(PM_LOG_DEBUG, "found cached pkg: %s\n", retpath);
return(retpath);