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.
- if(stat(installfn, &buf)) {
+ if(access(installfn, R_OK)) {
/* not found */
_alpm_log(PM_LOG_DEBUG, "scriptlet '%s' not found
", installfn);
return(0);
}
/* NOTE: popen will use the PARENT's /bin/sh, not the chroot's */
- if(stat("/bin/sh", &buf)) {
+ if(access("/bin/sh", X_OK)) {
/* not found */
_alpm_log(PM_LOG_ERROR, _("No /bin/sh in parent environment, aborting scriptlet
"));
return(0);
@@ -474,7 +474,7 @@ int _alpm_runscriptlet(const char *root, const char *installfn,
/* creates a directory in $root/tmp/ for copying/extracting the scriptlet */
snprintf(tmpdir, PATH_MAX, "%stmp/", root);
- if(stat(tmpdir, &buf)) {
+ if(access(tmpdir, F_OK) != 0) {
_alpm_makepath_mode(tmpdir, 01777);
}
snprintf(tmpdir, PATH_MAX, "%stmp/alpm_XXXXXX", root);
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 55bd46a..9199545 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;
#include <stdio.h>
#include <stdlib.h>
@@ -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;
diff --git a/src/util/testdb.c b/src/util/testdb.c
index f354eca..87bfcf9 100644
--- a/src/util/testdb.c
+++ b/src/util/testdb.c
@@ -23,7 +23,6 @@
#include <errno.h>
#include <limits.h>
#include <string.h>
-#include <sys/stat.h>
#include <dirent.h>
#include <libgen.h>
@@ -61,7 +60,6 @@ static int db_test(char *dbpath)
{
struct dirent *ent;
char path[PATH_MAX];
- struct stat buf;
int ret = 0;