sasha Sun Mar 11 02:08:28 2001 EDT
Modified files:
/php4 NEWS
/php4/ext/standard config.m4 file.c
Log:
Fixed a compatibility problem is some file functions (fgets, fputs, fread,
fwrite). The ANSI standard says that if a file is opened in read/write
mode, fseek() should be called before switching from reading to writing
and vice versa.
Index: php4/NEWS
diff -u php4/NEWS:1.608 php4/NEWS:1.609
--- php4/NEWS:1.608 Fri Mar 9 18:09:25 2001
+++ php4/NEWS Sun Mar 11 02:08:27 2001
@@ -2,6 +2,10 @@
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 200?, Version 4.0.5
+- Fixed a compatibility problem in some file functions (fgets, fputs, fread,
+ fwrite). The ANSI standard says that if a file is opened in read/write
+ mode, fseek() should be called before switching from reading to writing
+ and vice versa. ([EMAIL PROTECTED])
- Fixed argument checking for call_user_func* functions and allowed
specifying array($obj, 'method') syntax for call_user_func_array. (Andrei)
- Fixed parent::method() to also work with runtime bindings (Zeev, Zend Engine)
Index: php4/ext/standard/config.m4
diff -u php4/ext/standard/config.m4:1.26 php4/ext/standard/config.m4:1.27
--- php4/ext/standard/config.m4:1.26 Tue Jan 9 07:11:23 2001
+++ php4/ext/standard/config.m4 Sun Mar 11 02:08:27 2001
@@ -1,8 +1,59 @@
-dnl $Id: config.m4,v 1.26 2001/01/09 15:11:23 hirokawa Exp $ -*- sh -*-
+dnl $Id: config.m4,v 1.27 2001/03/11 10:08:27 sasha Exp $ -*- sh -*-
divert(3)dnl
dnl
+dnl Check if flush should be called explicitly after buffered io
+dnl
+AC_DEFUN(AC_FLUSH_IO,[
+ AC_CACHE_CHECK([whether flush should be called explicitly after a bufferered io],
+ac_cv_flush_io,[
+ AC_TRY_RUN( [
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char **argv)
+{
+ char *filename = tmpnam(NULL);
+ char buffer[64];
+ int result = 0;
+
+ FILE *fp = fopen(filename, "wb");
+ if (NULL == fp)
+ return 0;
+ fputs("line 1\n", fp);
+ fputs("line 2\n", fp);
+ fclose(fp);
+
+ fp = fopen(filename, "rb+");
+ if (NULL == fp)
+ return 0;
+ fgets(buffer, sizeof(buffer), fp);
+ fputs("line 3\n", fp);
+ rewind(fp);
+ fgets(buffer, sizeof(buffer), fp);
+ if (0 != strcmp(buffer, "line 1\n"))
+ result = 1;
+ fgets(buffer, sizeof(buffer), fp);
+ if (0 != strcmp(buffer, "line 3\n"))
+ result = 1;
+ fclose(fp);
+ unlink(filename);
+
+ exit(result);
+}
+],[
+ ac_cv_flush_io="no"
+],[
+ ac_cv_flush_io="yes"
+],[
+ ac_cv_flush_io="no"
+])])
+ if test "$ac_cv_flush_io" = "yes"; then
+ AC_DEFINE(HAVE_FLUSHIO, 1, [Define if flush should be called explicitly after a
+buffered io.])
+ fi
+])
+
+dnl
dnl Check for crypt() capabilities
dnl
AC_DEFUN(AC_CRYPT_CAP,[
@@ -143,6 +194,7 @@
AC_CHECK_FUNCS(getcwd getwd)
AC_CRYPT_CAP
+AC_FLUSH_IO
divert(5)dnl
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.147 php4/ext/standard/file.c:1.148
--- php4/ext/standard/file.c:1.147 Mon Mar 5 20:42:04 2001
+++ php4/ext/standard/file.c Sun Mar 11 02:08:27 2001
@@ -20,7 +20,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: file.c,v 1.147 2001/03/06 04:42:04 elixer Exp $ */
+/* $Id: file.c,v 1.148 2001/03/11 10:08:27 sasha Exp $ */
/* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
@@ -918,6 +918,11 @@
buf = emalloc(sizeof(char) * (len + 1));
/* needed because recv doesnt put a null at the end*/
memset(buf,0,len+1);
+#ifdef HAVE_FLUSHIO
+ if (!issock) {
+ fseek((FILE*)what, 0, SEEK_CUR);
+ }
+#endif
if (FP_FGETS(buf, len, socketd, (FILE*)what, issock) == NULL) {
efree(buf);
RETVAL_FALSE;
@@ -961,6 +966,11 @@
socketd=*(int*)what;
}
+#ifdef HAVE_FLUSHIO
+ if (!issock) {
+ fseek((FILE*)what, 0, SEEK_CUR);
+ }
+#endif
buf = emalloc(sizeof(int));
if ((result = FP_FGETC(socketd, (FILE*)what, issock)) == EOF) {
efree(buf);
@@ -1159,6 +1169,9 @@
if (issock){
ret = SOCK_WRITEL((*arg2)->value.str.val,num_bytes,socketd);
} else {
+#ifdef HAVE_FLUSHIO
+ fseek((FILE*)what, 0, SEEK_CUR);
+#endif
ret = fwrite((*arg2)->value.str.val,1,num_bytes,(FILE*)what);
}
RETURN_LONG(ret);
@@ -1794,6 +1807,9 @@
/* needed because recv doesnt put a null at the end*/
if (!issock) {
+#ifdef HAVE_FLUSHIO
+ fseek((FILE*)what, 0, SEEK_CUR);
+#endif
return_value->value.str.len = fread(return_value->value.str.val, 1,
len, (FILE*)what);
return_value->value.str.val[return_value->value.str.len] = 0;
} else {
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]