for stdio streams opened with a mode of "a+".
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 ])
])
PHP_FOPENCOOKIE
+PHP_BROKEN_GLIBC_FOPEN_APPEND
dnl Checks for typedefs, structures, and compiler characteristics.
dnl -------------------------------------------------------------------------
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;
}
}
- 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 */