From de338a26033d0f38987bec1d0eda8499854fb634 Mon Sep 17 00:00:00 2001 From: Vreixo Formoso Date: Sun, 27 Jan 2008 15:53:48 +0100 Subject: [PATCH] Check for non standard eaccess(), use open() otherwise. --- .cproject | 14 ++++++++++---- .project | 20 ++++++++++---------- configure.ac | 11 +++++++++++ libisofs/util.c | 26 +++++++++++++++++++++++--- 4 files changed, 54 insertions(+), 17 deletions(-) diff --git a/.cproject b/.cproject index ecb6ce5..e50a2a9 100644 --- a/.cproject +++ b/.cproject @@ -45,6 +45,10 @@ + @@ -79,6 +83,7 @@ + @@ -244,7 +249,7 @@ - + @@ -327,7 +332,7 @@ - + @@ -476,6 +481,7 @@ + @@ -641,7 +647,7 @@ - + @@ -724,7 +730,7 @@ - + diff --git a/.project b/.project index 44eca66..8352496 100644 --- a/.project +++ b/.project @@ -16,14 +16,14 @@ org.eclipse.cdt.make.core.enableCleanBuild true - - ?name? - - org.eclipse.cdt.make.core.append_environment true + + ?name? + + org.eclipse.cdt.make.core.stopOnError false @@ -40,25 +40,25 @@ org.eclipse.cdt.make.core.buildLocation - - org.eclipse.cdt.make.core.useDefaultBuildCmd - false - org.eclipse.cdt.make.core.environment - org.eclipse.cdt.make.core.enableFullBuild + org.eclipse.cdt.make.core.useDefaultBuildCmd true org.eclipse.cdt.make.core.enableAutoBuild true + + org.eclipse.cdt.make.core.enableFullBuild + true + org.eclipse.cdt.make.core.buildArguments - check -k + -k org.eclipse.cdt.make.core.fullBuildTarget diff --git a/configure.ac b/configure.ac index b7ebea0..118b0cf 100644 --- a/configure.ac +++ b/configure.ac @@ -92,17 +92,28 @@ AC_PROG_INSTALL AC_CHECK_HEADERS() +dnl Use GNU extensions if available +AC_DEFINE(_GNU_SOURCE, 1) + +dnl Check for tm_gmtoff field in struct tm AC_CHECK_MEMBER([struct tm.tm_gmtoff], [AC_DEFINE(HAVE_TM_GMTOFF, 1, [Define this if tm structure includes a tm_gmtoff entry.])], , [#include ]) +dnl Check if non standard timegm() function is available AC_CHECK_DECL([timegm], [AC_DEFINE(HAVE_TIMEGM, 1, [Define this if timegm function is available])], , [#include ]) +dnl Check if non standard eaccess() function is available +AC_CHECK_DECL([eaccess], + [AC_DEFINE(HAVE_EACCESS, 1, [Define this if eaccess function is available])], + , + [#include ]) + THREAD_LIBS=-lpthread AC_SUBST(THREAD_LIBS) diff --git a/libisofs/util.c b/libisofs/util.c index 4209b83..36d3830 100644 --- a/libisofs/util.c +++ b/libisofs/util.c @@ -22,10 +22,15 @@ #include #include -/* for eaccess, defined in unistd.h */ -#define __USE_GNU #include +/* if we don't have eaccess, we check file access by openning it */ +#ifndef HAVE_EACCESS +#include +#include +#include +#endif + int int_pow(int base, int power) { int result = 1; @@ -1117,7 +1122,22 @@ time_t iso_datetime_read_17(const uint8_t *buf) */ int iso_eaccess(const char *path) { - if (eaccess(path, R_OK) != 0) { + int access; + + /* use non standard eaccess when available, open() otherwise */ +#ifdef HAVE_EACCESS + access = !eaccess(path, R_OK); +#else + int fd = open(path, O_RDONLY); + if (fd != -1) { + close(fd); + access = 1; + } else { + access = 0; + } +#endif + + if (!access) { int err; /* error, choose an appropriate return code */