wez             Wed Jan  1 04:55:38 2003 EDT

  Modified files:              (Branch: PHP_4_3)
    /php4       acinclude.m4 configure.in 
    /php4/main  streams.c 
  Log:
  Workaround a bug in glibc 2.2.9x and later that causes it not to seek to EOF
  for stdio streams opened with a mode of "a+".
  
  
Index: php4/acinclude.m4
diff -u php4/acinclude.m4:1.218.2.2 php4/acinclude.m4:1.218.2.3
--- php4/acinclude.m4:1.218.2.2 Sun Nov 17 14:28:57 2002
+++ php4/acinclude.m4   Wed Jan  1 04:55:38 2003
@@ -1,4 +1,4 @@
-dnl $Id: acinclude.m4,v 1.218.2.2 2002/11/17 19:28:57 wez Exp $
+dnl $Id: acinclude.m4,v 1.218.2.3 2003/01/01 09:55:38 wez Exp $
 dnl
 dnl This file contains local autoconf functions.
 
@@ -1461,6 +1461,45 @@
     AC_DEFINE(CHARSET_EBCDIC,1, [Define if system uses EBCDIC])
   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: php4/configure.in
diff -u php4/configure.in:1.396.2.20 php4/configure.in:1.396.2.21
--- php4/configure.in:1.396.2.20        Fri Dec 27 17:11:40 2002
+++ php4/configure.in   Wed Jan  1 04:55:38 2003
@@ -1,4 +1,4 @@
-dnl ## $Id: configure.in,v 1.396.2.20 2002/12/27 22:11:40 edink Exp $ -*- sh -*-
+dnl ## $Id: configure.in,v 1.396.2.21 2003/01/01 09:55:38 wez Exp $ -*- sh -*-
 dnl ## Process this file with autoconf to produce a configure script.
 
 divert(1)
@@ -382,6 +382,7 @@
 ])
 
 PHP_FOPENCOOKIE
+PHP_BROKEN_GLIBC_FOPEN_APPEND
 
 dnl Checks for typedefs, structures, and compiler characteristics.
 dnl -------------------------------------------------------------------------
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.125.2.24 php4/main/streams.c:1.125.2.25
--- php4/main/streams.c:1.125.2.24      Tue Dec 31 11:26:28 2002
+++ php4/main/streams.c Wed Jan  1 04:55:38 2003
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: streams.c,v 1.125.2.24 2002/12/31 16:26:28 sebastian Exp $ */
+/* $Id: streams.c,v 1.125.2.25 2003/01/01 09:55:38 wez Exp $ */
 
 #define _GNU_SOURCE
 #include "php.h"
@@ -1317,6 +1317,12 @@
        
        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 @@
                }
        }
 
-       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 */



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to