summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSascha Schumann <sas@php.net>2002-09-06 10:27:26 +0000
committerSascha Schumann <sas@php.net>2002-09-06 10:27:26 +0000
commit702d7afc3cbc8599ca8113c223079d57dfec939a (patch)
tree024cc6160d68b5fc415a2f0b2eecb88fa91f952e
parent8f14aafe97639984022364afc544565a052ba399 (diff)
downloadphp-git-702d7afc3cbc8599ca8113c223079d57dfec939a.tar.gz
Reenable pwrite/pread support
The old checks supposed that pread/pwrite worked, if a declaration was found in <unistd.h>. We now actually check whether they work successfully before using them.
-rw-r--r--acinclude.m4106
-rw-r--r--ext/session/config.m43
-rw-r--r--ext/session/mod_files.c9
3 files changed, 63 insertions, 55 deletions
diff --git a/acinclude.m4 b/acinclude.m4
index 7da512c2fd..3ebad7a5bb 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -374,80 +374,76 @@ X
rm -fr conftest*
])
-AC_DEFUN(PHP_MISSING_PREAD_DECL,[
- AC_CACHE_CHECK(whether pread works without custom declaration,ac_cv_pread,[
- AC_TRY_COMPILE([#include <unistd.h>],[size_t (*func)() = pread],[
- ac_cv_pread=yes
- ],[
- echo test > conftest_in
- AC_TRY_RUN([
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
- main() { char buf[3]; return !(pread(open("conftest_in", O_RDONLY), buf, 2, 0) == 2); }
- ],[
- ac_cv_pread=yes
- ],[
- echo test > conftest_in
- AC_TRY_RUN([
+AC_DEFUN(PHP_DOES_PWRITE_WORK,[
+ AC_TRY_RUN([
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
- ssize_t pread(int, void *, size_t, off64_t);
- main() { char buf[3]; return !(pread(open("conftest_in", O_RDONLY), buf, 2, 0) == 2); }
- ],[
- ac_cv_pread=64
- ],[
- ac_cv_pread=no
- ])
- ],[
- ac_cv_pread=no
- ])
- ])
+$1
+ main() { return !(pwrite(open("conftest_in", O_WRONLY|O_CREAT, 0600), "hi", 2, 0) == 2); }
+ ],[
+ ac_cv_pwrite=yes
+ ],[
+ ac_cv_pwrite=no
+ ],[
+ ac_cv_pwrite=no
])
- case $ac_cv_pread in
- no) ac_cv_func_pread=no;;
- 64) AC_DEFINE(PHP_PREAD_64, 1, [whether pread64 is default]);;
- esac
])
-AC_DEFUN(PHP_MISSING_PWRITE_DECL,[
- AC_CACHE_CHECK(whether pwrite works without custom declaration,ac_cv_pwrite,[
- AC_TRY_COMPILE([#include <unistd.h>],[size_t (*func)() = pwrite],[
- ac_cv_pwrite=yes
- ],[
- AC_TRY_RUN([
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
- main() { return !(pwrite(open("conftest_out", O_WRONLY|O_CREAT, 0600), "Ok", 2, 0) == 2); }
- ],[
- ac_cv_pwrite=yes
- ],[
- AC_TRY_RUN([
+AC_DEFUN(PHP_DOES_PREAD_WORK,[
+ echo test > conftest_in
+ AC_TRY_RUN([
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
- ssize_t pwrite(int, void *, size_t, off64_t);
- main() { return !(pwrite(open("conftest_out", O_WRONLY|O_CREAT, 0600), "Ok", 2, 0) == 2); }
- ],[
- ac_cv_pwrite=64
- ],[
- ac_cv_pwrite=no
- ])
- ],[
- ac_cv_pwrite=no
- ])
+$1
+ main() { char buf[3]; return !(pread(open("conftest_in", O_RDONLY), buf, 2, 0) == 2); }
+ ],[
+ ac_cv_pread=yes
+ ],[
+ ac_cv_pread=no
+ ],[
+ ac_cv_pread=no
])
+ rm -f conftest_in
+])
+
+AC_DEFUN(PHP_PWRITE_TEST,[
+ AC_CACHE_CHECK(whether pwrite works,ac_cv_pwrite,[
+ PHP_DOES_PWRITE_WORK
+ if test "$ac_cv_pwrite" = "no"; then
+ PHP_DOES_PWRITE_WORK([ssize_t pwrite(int, void *, size_t, off64_t);])
+ if test "$ac_cv_pwrite" = "yes"; then
+ ac_cv_pwrite=64
+ fi
+ fi
])
+
case $ac_cv_pwrite in
no) ac_cv_func_pwrite=no;;
64) AC_DEFINE(PHP_PWRITE_64, 1, [whether pwrite64 is default]);;
esac
])
+AC_DEFUN(PHP_PREAD_TEST,[
+ AC_CACHE_CHECK(whether pread works,ac_cv_pread,[
+ PHP_DOES_PREAD_WORK
+ if test "$ac_cv_pread" = "no"; then
+ PHP_DOES_PREAD_WORK([ssize_t pread(int, void *, size_t, off64_t);])
+ if test "$ac_cv_pread" = "yes"; then
+ ac_cv_pread=64
+ fi
+ fi
+ ])
+
+ case $ac_cv_pread in
+ no) ac_cv_func_pread=no;;
+ 64) AC_DEFINE(PHP_PREAD_64, 1, [whether pread64 is default]);;
+ esac
+])
+
AC_DEFUN(PHP_MISSING_TIME_R_DECL,[
AC_MSG_CHECKING([for missing declarations of reentrant functions])
AC_TRY_COMPILE([#include <time.h>],[struct tm *(*func)() = localtime_r],[
diff --git a/ext/session/config.m4 b/ext/session/config.m4
index ddb92441ed..8bb43b676b 100644
--- a/ext/session/config.m4
+++ b/ext/session/config.m4
@@ -9,6 +9,9 @@ PHP_ARG_WITH(mm,for mm support,
[ --with-mm[=DIR] Include mm support for session storage], no, no)
if test "$PHP_SESSION" != "no"; then
+ AC_CHECK_FUNCS(pread pwrite)
+ PHP_PWRITE_TEST
+ PHP_PREAD_TEST
PHP_NEW_EXTENSION(session, session.c mod_files.c mod_mm.c mod_user.c, $ext_shared)
PHP_SUBST(SESSION_SHARED_LIBADD)
AC_DEFINE(HAVE_PHP_SESSION,1,[ ])
diff --git a/ext/session/mod_files.c b/ext/session/mod_files.c
index 2fce69d792..52dddadc6d 100644
--- a/ext/session/mod_files.c
+++ b/ext/session/mod_files.c
@@ -267,8 +267,13 @@ PS_READ_FUNC(files)
data->st_size = *vallen = sbuf.st_size;
*val = emalloc(sbuf.st_size);
+#ifdef HAVE_PREAD
+ n = pread(data->fd, *val, sbuf.st_size, 0);
+#else
lseek(data->fd, 0, SEEK_SET);
n = read(data->fd, *val, sbuf.st_size);
+#endif
+
if (n != sbuf.st_size) {
efree(*val);
return FAILURE;
@@ -294,8 +299,12 @@ PS_WRITE_FUNC(files)
if (vallen < (int)data->st_size)
ftruncate(data->fd, 0);
+#ifdef HAVE_PWRITE
+ n = pwrite(data->fd, val, vallen, 0);
+#else
lseek(data->fd, 0, SEEK_SET);
n = write(data->fd, val, vallen);
+#endif
if (n != vallen) {
php_error(E_WARNING, "write failed: %s (%d)", strerror(errno), errno);