]> granicus.if.org Git - php/commitdiff
Workaround for glibc 2.2.9x and later "a+" bug that does not seek to EOF for
authorWez Furlong <wez@php.net>
Wed, 1 Jan 2003 09:58:17 +0000 (09:58 +0000)
committerWez Furlong <wez@php.net>
Wed, 1 Jan 2003 09:58:17 +0000 (09:58 +0000)
files fopen()ed with that mode.

acinclude.m4
configure.in
main/streams.c

index b86185f6e0c925286df32acdda76575098dc34ac..b4380881e40af11ae5d43ade34865c80d60254b4 100644 (file)
@@ -1455,6 +1455,45 @@ int main(void) {
   fi
 ])
 
+AC_DEFUN([PHP_BROKEN_GLIBC_FOPEN_APPEND],[
+  AC_MSG_CHECKING([for broken libc stdio])
+  AC_TRY_RUN([
+#include <stdio.h>
+int main(int argc, char *argv[])
+{
+  FILE *fp;
+  long position;
+  char *filename = "/tmp/phpglibccheck";
+  
+  fp = fopen(filename, "w");
+  if (fp == NULL) {
+         perror("fopen");
+         exit(2);
+  }
+  fputs("foobar", fp);
+  fclose(fp);
+
+  fp = fopen(filename, "a+");
+  position = ftell(fp);
+  fclose(fp);
+  unlink(filename);
+  if (position == 0)
+       return 1;
+  return 0;
+}
+],
+[have_broken_glibc_fopen_append=no],
+[have_broken_glibc_fopen_append=yes ])
+
+  if test "$have_broken_glibc_fopen_append" = "yes"; then
+       AC_MSG_RESULT(yes)
+       AC_DEFINE(HAVE_BROKEN_GLIBC_FOPEN_APPEND,1, [Define if your glibc borks on fopen with mode a+])
+  else
+       AC_MSG_RESULT(no)
+  fi
+])
+
+
 AC_DEFUN([PHP_FOPENCOOKIE],[
        AC_CHECK_FUNC(fopencookie, [ have_glibc_fopencookie=yes ])
 
index a6408336ea3235b841fad21941a976bd64a1fdeb..a5f80c641c63cf72cfcf22b0d0d4f9ef94fcfbc4 100644 (file)
@@ -382,6 +382,7 @@ sys/ipc.h \
 ])
 
 PHP_FOPENCOOKIE
+PHP_BROKEN_GLIBC_FOPEN_APPEND
 
 dnl Checks for typedefs, structures, and compiler characteristics.
 dnl -------------------------------------------------------------------------
index 02be2f2d7518160009cf60552a8b4d2cc3b209a0..74b95bf94bd2cfd7ceac3012a5be2cb8ad7ac9a9 100755 (executable)
@@ -1317,6 +1317,12 @@ PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STRE
        
        stream = php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode);
 
+#ifdef HAVE_BROKEN_GLIBC_FOPEN_APPEND
+       if (strchr(mode, 'a')) {
+               fseek(file, 0, SEEK_END);
+       }
+#endif
+       
        if (stream) {
                if (self->is_pipe) {
                        stream->flags |= PHP_STREAM_FLAG_NO_SEEK;
@@ -2417,7 +2423,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int optio
                }
        }
 
-       if (stream && stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0 && strchr(mode, 'a')) {
+       if (stream && stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0 && strchr(mode, 'a') && stream->position == 0) {
                off_t newpos = 0;
 
                /* if opened for append, we need to revise our idea of the initial file position */