[PHP-CVS] cvs: php4 /main streams.c

2003-02-15 Thread Moriyoshi Koizumi
moriyoshi   Sat Feb 15 14:56:13 2003 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Fixed bug #22234
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.154 php4/main/streams.c:1.155
--- php4/main/streams.c:1.154   Thu Feb 13 16:08:04 2003
+++ php4/main/streams.c Sat Feb 15 14:56:12 2003
@@ -20,7 +20,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.154 2003/02/13 21:08:04 wez Exp $ */
+/* $Id: streams.c,v 1.155 2003/02/15 19:56:12 moriyoshi Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -1206,6 +1206,17 @@
/* fall through - we might be able to copy in smaller chunks */
}
 #endif
+
+   {
+   php_stream_statbuf sbuf;
+   if (php_stream_stat(src, sbuf TSRMLS_CC) == 0) {
+   /* in the event that the source file is 0 bytes, return 1 to 
+indicate success
+* because opening the file to write had already created a 
+copy */
+   if (sbuf.sb.st_size == 0) {
+   return 1;
+   }
+   }
+   }
 
while(1) {
readchunk = sizeof(buf);



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




Re: [PHP-CVS] cvs: php4 /main streams.c

2003-02-15 Thread Wez Furlong
This is a bogus patch; the return value of the php_stream_copy_to_XXX
functions are the number of bytes that were copied, and this patch
breaks that.

The correct fix for #22234 is to fix php_copy_file() to handle a 0
return from this function.

Please revert!

--Wez.

On Sat, 15 Feb 2003, Moriyoshi Koizumi wrote:

 moriyoshi Sat Feb 15 14:56:13 2003 EDT

   Modified files:
 /php4/mainstreams.c
   Log:
   Fixed bug #22234


 Index: php4/main/streams.c
 diff -u php4/main/streams.c:1.154 php4/main/streams.c:1.155
 --- php4/main/streams.c:1.154 Thu Feb 13 16:08:04 2003
 +++ php4/main/streams.c   Sat Feb 15 14:56:12 2003
 @@ -20,7 +20,7 @@
 +--+
   */

 -/* $Id: streams.c,v 1.154 2003/02/13 21:08:04 wez Exp $ */
 +/* $Id: streams.c,v 1.155 2003/02/15 19:56:12 moriyoshi Exp $ */

  #define _GNU_SOURCE
  #include php.h
 @@ -1206,6 +1206,17 @@
   /* fall through - we might be able to copy in smaller chunks */
   }
  #endif
 +
 + {
 + php_stream_statbuf sbuf;
 + if (php_stream_stat(src, sbuf TSRMLS_CC) == 0) {
 + /* in the event that the source file is 0 bytes, return 1 to 
indicate success
 +  * because opening the file to write had already created a 
copy */
 + if (sbuf.sb.st_size == 0) {
 + return 1;
 + }
 + }
 + }

   while(1) {
   readchunk = sizeof(buf);



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





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




Re: [PHP-CVS] cvs: php4 /main streams.c

2003-02-15 Thread Wez Furlong
Actually, the return values throughout that function are all bogus...
Don't worry about reverting (for 4.3).
I'll add this to my TODO for PHP 5.

--Wez.

On Sat, 15 Feb 2003, Wez Furlong wrote:

 This is a bogus patch; the return value of the php_stream_copy_to_XXX
 functions are the number of bytes that were copied, and this patch
 breaks that.

 The correct fix for #22234 is to fix php_copy_file() to handle a 0
 return from this function.

 Please revert!

 --Wez.

 On Sat, 15 Feb 2003, Moriyoshi Koizumi wrote:

  moriyoshi   Sat Feb 15 14:56:13 2003 EDT
 
Modified files:
  /php4/main  streams.c
Log:
Fixed bug #22234
 
 
  Index: php4/main/streams.c
  diff -u php4/main/streams.c:1.154 php4/main/streams.c:1.155
  --- php4/main/streams.c:1.154   Thu Feb 13 16:08:04 2003
  +++ php4/main/streams.c Sat Feb 15 14:56:12 2003
  @@ -20,7 +20,7 @@
  +--+
*/
 
  -/* $Id: streams.c,v 1.154 2003/02/13 21:08:04 wez Exp $ */
  +/* $Id: streams.c,v 1.155 2003/02/15 19:56:12 moriyoshi Exp $ */
 
   #define _GNU_SOURCE
   #include php.h
  @@ -1206,6 +1206,17 @@
  /* fall through - we might be able to copy in smaller chunks */
  }
   #endif
  +
  +   {
  +   php_stream_statbuf sbuf;
  +   if (php_stream_stat(src, sbuf TSRMLS_CC) == 0) {
  +   /* in the event that the source file is 0 bytes, return 1 to 
indicate success
  +* because opening the file to write had already created a 
copy */
  +   if (sbuf.sb.st_size == 0) {
  +   return 1;
  +   }
  +   }
  +   }
 
  while(1) {
  readchunk = sizeof(buf);
 
 
 
  --
  PHP CVS Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 


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





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




Re: [PHP-CVS] cvs: php4 /main streams.c

2003-02-15 Thread Moriyoshi Koizumi
So should I revert the patch on HEAD then?

Moriyoshi

Wez Furlong [EMAIL PROTECTED] wrote:

 Actually, the return values throughout that function are all bogus...
 Don't worry about reverting (for 4.3).
 I'll add this to my TODO for PHP 5.
 
 --Wez.
 
 On Sat, 15 Feb 2003, Wez Furlong wrote:
 
  This is a bogus patch; the return value of the php_stream_copy_to_XXX
  functions are the number of bytes that were copied, and this patch
  breaks that.
 
  The correct fix for #22234 is to fix php_copy_file() to handle a 0
  return from this function.
 
  Please revert!
 
  --Wez.
 
  On Sat, 15 Feb 2003, Moriyoshi Koizumi wrote:
 
   moriyoshi Sat Feb 15 14:56:13 2003 EDT
  
 Modified files:
   /php4/mainstreams.c
 Log:
 Fixed bug #22234
  
  
   Index: php4/main/streams.c
   diff -u php4/main/streams.c:1.154 php4/main/streams.c:1.155
   --- php4/main/streams.c:1.154 Thu Feb 13 16:08:04 2003
   +++ php4/main/streams.c   Sat Feb 15 14:56:12 2003
   @@ -20,7 +20,7 @@
   +--+
 */
  
   -/* $Id: streams.c,v 1.154 2003/02/13 21:08:04 wez Exp $ */
   +/* $Id: streams.c,v 1.155 2003/02/15 19:56:12 moriyoshi Exp $ */
  
#define _GNU_SOURCE
#include php.h
   @@ -1206,6 +1206,17 @@
 /* fall through - we might be able to copy in smaller chunks */
 }
#endif
   +
   + {
   + php_stream_statbuf sbuf;
   + if (php_stream_stat(src, sbuf TSRMLS_CC) == 0) {
   + /* in the event that the source file is 0 bytes, return 1 to 
indicate success
   +  * because opening the file to write had already created a 
copy */
   + if (sbuf.sb.st_size == 0) {
   + return 1;
   + }
   + }
   + }
  
 while(1) {
 readchunk = sizeof(buf);
  
  
  
   --
   PHP CVS Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
  
  
  
 
 
  --
  PHP CVS Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 
 -- 
 PHP CVS Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


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




Re: [PHP-CVS] cvs: php4 /main streams.c

2003-02-15 Thread Wez Furlong
Keep the patch in there for now.

--Wez.

On Sun, 16 Feb 2003, Moriyoshi Koizumi wrote:

 So should I revert the patch on HEAD then?

 Moriyoshi

 Wez Furlong [EMAIL PROTECTED] wrote:

  Actually, the return values throughout that function are all bogus...
  Don't worry about reverting (for 4.3).
  I'll add this to my TODO for PHP 5.
 
  --Wez.
 
  On Sat, 15 Feb 2003, Wez Furlong wrote:
 
   This is a bogus patch; the return value of the php_stream_copy_to_XXX
   functions are the number of bytes that were copied, and this patch
   breaks that.
  
   The correct fix for #22234 is to fix php_copy_file() to handle a 0
   return from this function.
  
   Please revert!
  
   --Wez.
  
   On Sat, 15 Feb 2003, Moriyoshi Koizumi wrote:
  
moriyoshi   Sat Feb 15 14:56:13 2003 EDT
   
  Modified files:
/php4/main  streams.c
  Log:
  Fixed bug #22234
   
   
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.154 php4/main/streams.c:1.155
--- php4/main/streams.c:1.154   Thu Feb 13 16:08:04 2003
+++ php4/main/streams.c Sat Feb 15 14:56:12 2003
@@ -20,7 +20,7 @@
+--+
  */
   
-/* $Id: streams.c,v 1.154 2003/02/13 21:08:04 wez Exp $ */
+/* $Id: streams.c,v 1.155 2003/02/15 19:56:12 moriyoshi Exp $ */
   
 #define _GNU_SOURCE
 #include php.h
@@ -1206,6 +1206,17 @@
/* fall through - we might be able to copy in smaller chunks */
}
 #endif
+
+   {
+   php_stream_statbuf sbuf;
+   if (php_stream_stat(src, sbuf TSRMLS_CC) == 0) {
+   /* in the event that the source file is 0 bytes, 
return 1 to indicate success
+* because opening the file to write had already 
created a copy */
+   if (sbuf.sb.st_size == 0) {
+   return 1;
+   }
+   }
+   }
   
while(1) {
readchunk = sizeof(buf);
   
   
   
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
   
   
   
  
  
   --
   PHP CVS Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
  
  
  
 
 
  --
  PHP CVS Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 





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




[PHP-CVS] cvs: php4 /main streams.c

2003-02-13 Thread Wez Furlong
wez Thu Feb 13 06:12:57 2003 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Whitespace-fix these goto labels.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.146 php4/main/streams.c:1.147
--- php4/main/streams.c:1.146   Wed Feb 12 20:17:45 2003
+++ php4/main/streams.c Thu Feb 13 06:12:56 2003
@@ -20,7 +20,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.146 2003/02/13 01:17:45 wez Exp $ */
+/* $Id: streams.c,v 1.147 2003/02/13 11:12:56 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -1663,7 +1663,7 @@
 * safe mode GID/UID checks
 */
 
-   not_relative_path:
+not_relative_path:
 
/* Absolute path open */
if (IS_ABSOLUTE_PATH(filename, filename_length)) {
@@ -1775,7 +1775,7 @@
}
stream = php_stream_fopen_rel(trypath, mode, opened_path, options);
if (stream) {
-   stream_done:
+stream_done:
efree(pathbuf);
return stream;
}



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




[PHP-CVS] cvs: php4 /main streams.c

2003-02-13 Thread Wez Furlong
wez Thu Feb 13 09:52:54 2003 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Clarify error message.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.149 php4/main/streams.c:1.150
--- php4/main/streams.c:1.149   Thu Feb 13 09:40:16 2003
+++ php4/main/streams.c Thu Feb 13 09:52:54 2003
@@ -20,7 +20,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.149 2003/02/13 14:40:16 iliaa Exp $ */
+/* $Id: streams.c,v 1.150 2003/02/13 14:52:54 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -2553,7 +2553,7 @@
}

if (stream == NULL  (options  REPORT_ERRORS)) {
-   display_wrapper_errors(wrapper, path, failed to create stream 
TSRMLS_CC);
+   display_wrapper_errors(wrapper, path, failed to open stream 
+TSRMLS_CC);
}
tidy_wrapper_error_log(wrapper TSRMLS_CC);
 #if ZEND_DEBUG



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




[PHP-CVS] cvs: php4 /main streams.c

2003-02-13 Thread Ilia Alshanetsky
iliaa   Thu Feb 13 10:09:39 2003 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Simplified the mode validation code  added support for read+write mode to
  'x' mode.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.150 php4/main/streams.c:1.151
--- php4/main/streams.c:1.150   Thu Feb 13 09:52:54 2003
+++ php4/main/streams.c Thu Feb 13 10:09:39 2003
@@ -20,7 +20,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.150 2003/02/13 14:52:54 wez Exp $ */
+/* $Id: streams.c,v 1.151 2003/02/13 15:09:39 iliaa Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -1853,27 +1853,13 @@
 
switch (mode[0]) {
case 'r':
-   if (strchr(mode, '+')) {
-   flags = O_RDWR;
-   } else {
-   flags = O_RDONLY;
-   }
+   flags = 0;
break;
case 'w':
-   if (strchr(mode, '+')) {
-   flags = O_RDWR;
-   } else {
-   flags = O_WRONLY;
-   }
-   flags |= O_TRUNC|O_CREAT;
+   flags = O_TRUNC|O_CREAT;
break;
case 'a':
-   if (strchr(mode, '+')) {
-   flags = O_RDWR;
-   } else {
-   flags = O_WRONLY;
-   }
-   flags |= O_CREAT|O_APPEND;
+   flags = O_CREAT|O_APPEND;
break;
case 'x':
flags = O_CREAT|O_EXCL;
@@ -1881,6 +1867,14 @@
default:
/* unknown mode */
return FAILURE;
+   }
+
+   if (strchr(mode, '+')) {
+   flags |= O_RDWR;
+   } else if (flags) {
+   flags |= O_WRONLY;
+   } else {
+   flags |= O_RDONLY'
}
 
 #ifdef O_BINARY



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




[PHP-CVS] cvs: php4 /main streams.c

2003-02-13 Thread Ilia Alshanetsky
iliaa   Thu Feb 13 11:22:04 2003 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Fixed a typo.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.151 php4/main/streams.c:1.152
--- php4/main/streams.c:1.151   Thu Feb 13 10:09:39 2003
+++ php4/main/streams.c Thu Feb 13 11:22:03 2003
@@ -20,7 +20,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.151 2003/02/13 15:09:39 iliaa Exp $ */
+/* $Id: streams.c,v 1.152 2003/02/13 16:22:03 iliaa Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -1874,7 +1874,7 @@
} else if (flags) {
flags |= O_WRONLY;
} else {
-   flags |= O_RDONLY'
+   flags |= O_RDONLY;
}
 
 #ifdef O_BINARY



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




[PHP-CVS] cvs: php4 /main streams.c

2003-02-13 Thread Wez Furlong
wez Thu Feb 13 12:20:21 2003 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  A probable cure for many getcwd/relative include related problems for win32.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.152 php4/main/streams.c:1.153
--- php4/main/streams.c:1.152   Thu Feb 13 11:22:03 2003
+++ php4/main/streams.c Thu Feb 13 12:20:20 2003
@@ -20,7 +20,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.152 2003/02/13 16:22:03 iliaa Exp $ */
+/* $Id: streams.c,v 1.153 2003/02/13 17:20:20 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -1691,12 +1691,12 @@
filename_length = strlen(filename);
 
/* Relative path open */
-   if (*filename == '.'  (*(filename+1) == '/' || *(filename+1) == '.')) {
+   if (*filename == '.'  (IS_SLASH(filename[1]) || filename[1] == '.')) {
/* further checks, we could have ... filenames */
ptr = filename + 1;
if (*ptr == '.') {
while (*(++ptr) == '.');
-   if (*ptr != '/') { /* not a relative path after all */
+   if (!IS_SLASH(*ptr)) { /* not a relative path after all */
goto not_relative_path;
}
}



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




[PHP-CVS] cvs: php4 /main streams.c

2003-02-13 Thread Wez Furlong
wez Thu Feb 13 16:08:05 2003 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  MFB: Fix for bug #22199
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.153 php4/main/streams.c:1.154
--- php4/main/streams.c:1.153   Thu Feb 13 12:20:20 2003
+++ php4/main/streams.c Thu Feb 13 16:08:04 2003
@@ -20,7 +20,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.153 2003/02/13 17:20:20 wez Exp $ */
+/* $Id: streams.c,v 1.154 2003/02/13 21:08:04 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -869,14 +869,17 @@
justwrote = stream-ops-write(stream, buf, towrite TSRMLS_CC);
}
if (justwrote  0) {
-   stream-position += justwrote;
buf += justwrote;
count -= justwrote;
didwrite += justwrote;

-   /* FIXME: invalidate the whole readbuffer */
-   stream-writepos = 0;
-   stream-readpos = 0;
+   /* Only screw with the buffer if we can seek, otherwise we 
+lose data
+* buffered from fifos and sockets */
+   if (stream-ops-seek  (stream-flags  
+PHP_STREAM_FLAG_NO_SEEK) == 0) {
+   stream-position += justwrote;
+   stream-writepos = 0;
+   stream-readpos = 0;
+   }
} else {
break;
}



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




[PHP-CVS] cvs: php4 /main streams.c

2003-01-30 Thread Sascha Schumann
sas Thu Jan 30 16:06:35 2003 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Fix sticky EOF problem
  
  Sometimes streams signal a temporary EOF, because all current data
  has been consumed. But that does not preclude the possibility that
  more data will become available later.
  
  Thus we must not treat eof in the read path as final.
  
  Now, tail -f like scripts work again.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.142 php4/main/streams.c:1.143
--- php4/main/streams.c:1.142   Mon Jan  6 18:27:03 2003
+++ php4/main/streams.c Thu Jan 30 16:06:34 2003
@@ -20,7 +20,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.142 2003/01/06 23:27:03 wez Exp $ */
+/* $Id: streams.c,v 1.143 2003/01/30 21:06:34 sas Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -521,8 +521,7 @@
if (stream-writepos - stream-readpos  (off_t)size) {
size_t justread = 0;

-   if (stream-eof)
-   return;
+   /* ignore eof here; the underlying state might have changed */

/* no; so lets fetch more data */

@@ -581,7 +580,8 @@
didread += toread;
}
 
-   if (size == 0 || stream-eof) {
+   /* ignore eof here; the underlying state might have changed */
+   if (size == 0) {
break;
}
 



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




[PHP-CVS] cvs: php4 /main streams.c

2003-01-06 Thread Wez Furlong
wez Mon Jan  6 18:27:03 2003 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Fix for Bug #20827: where stat is a macro on Tru64.
  Patch from [EMAIL PROTECTED]
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.141 php4/main/streams.c:1.142
--- php4/main/streams.c:1.141   Sun Jan  5 23:06:40 2003
+++ php4/main/streams.c Mon Jan  6 18:27:03 2003
@@ -20,7 +20,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.141 2003/01/06 04:06:40 pollita Exp $ */
+/* $Id: streams.c,v 1.142 2003/01/06 23:27:03 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -679,7 +679,7 @@
return -1;
}
 
-   return stream-ops-stat(stream, ssb TSRMLS_CC);
+   return (stream-ops-stat)(stream, ssb TSRMLS_CC);
 }
 
 PHPAPI char *php_stream_locate_eol(php_stream *stream, char *buf, size_t buf_len 
TSRMLS_DC)



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




[PHP-CVS] cvs: php4 /main streams.c

2002-12-22 Thread Wez Furlong
wez Sun Dec 22 21:56:46 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  MFB: fpos_t - off_t 
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.137 php4/main/streams.c:1.138
--- php4/main/streams.c:1.137   Sun Dec 22 13:05:36 2002
+++ php4/main/streams.c Sun Dec 22 21:56:46 2002
@@ -20,7 +20,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.137 2002/12/22 18:05:36 wez Exp $ */
+/* $Id: streams.c,v 1.138 2002/12/23 02:56:46 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -2418,7 +2418,7 @@
}
 
if (stream  stream-ops-seek  (stream-flags  PHP_STREAM_FLAG_NO_SEEK) 
== 0  strchr(mode, 'a')) {
-   fpos_t newpos = 0;
+   off_t newpos = 0;
 
/* if opened for append, we need to revise our idea of the initial 
file position */
if (0 == stream-ops-seek(stream, 0, SEEK_CUR, newpos TSRMLS_CC)) {



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




[PHP-CVS] cvs: php4 /main streams.c

2002-12-10 Thread Ilia Alshanetsky
iliaa   Tue Dec 10 11:39:59 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  MFB
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.133 php4/main/streams.c:1.134
--- php4/main/streams.c:1.133   Mon Dec  9 11:14:28 2002
+++ php4/main/streams.c Tue Dec 10 11:39:59 2002
@@ -20,7 +20,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.133 2002/12/09 16:14:28 wez Exp $ */
+/* $Id: streams.c,v 1.134 2002/12/10 16:39:59 iliaa Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -1770,16 +1770,12 @@
if (fp) {
/* sanity checks for include/require */
if (options  STREAM_OPEN_FOR_INCLUDE  (fstat(fileno(fp), st) == -1 
|| !S_ISREG(st.st_mode))) {
-   int is_unc = 0;
-
 #ifdef PHP_WIN32
/* skip the sanity check; fstat doesn't appear to work on
 * UNC paths */
-   is_unc = (filename[0] == '\\'  filename[1] == '\\');
+   if (!IS_UNC_PATH(filename, strlen(filename)))
 #endif
-   if (!is_unc) {
goto err;
-   }
} 

ret = php_stream_fopen_from_file_rel(fp, mode);



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




[PHP-CVS] cvs: php4 /main streams.c

2002-12-09 Thread Wez Furlong
wez Mon Dec  9 05:38:35 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  MFB: #20831 fix
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.131 php4/main/streams.c:1.132
--- php4/main/streams.c:1.131   Fri Nov 22 20:24:08 2002
+++ php4/main/streams.c Mon Dec  9 05:38:35 2002
@@ -20,7 +20,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.131 2002/11/23 01:24:08 helly Exp $ */
+/* $Id: streams.c,v 1.132 2002/12/09 10:38:35 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -1751,7 +1751,16 @@
if (fp) {
/* sanity checks for include/require */
if (options  STREAM_OPEN_FOR_INCLUDE  (fstat(fileno(fp), st) == -1 
|| !S_ISREG(st.st_mode))) {
-   goto err;
+   int is_unc = 0;
+
+#ifdef PHP_WIN32
+   /* skip the sanity check; fstat doesn't appear to work on
+* UNC paths */
+   is_unc = (filename[0] == '\\'  filename[1] == '\\');
+#endif
+   if (!is_unc) {
+   goto err;
+   }
} 

ret = php_stream_fopen_from_file_rel(fp, mode);
@@ -2317,7 +2326,7 @@
return stream;
case PHP_STREAM_RELEASED:
 #if ZEND_DEBUG
-   newstream-__orig_path = estrdup(copy_of_path);
+   newstream-__orig_path = estrdup(path);
 #endif
return newstream;
default:
@@ -2339,8 +2348,9 @@
}
tidy_wrapper_error_log(wrapper TSRMLS_CC);
 #if ZEND_DEBUG
-   if (stream == NULL  copy_of_path != NULL)
+   if (stream == NULL  copy_of_path != NULL) {
efree(copy_of_path);
+   }
 #endif
return stream;
 }



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




[PHP-CVS] cvs: php4 /main streams.c

2002-11-18 Thread Wez Furlong
wez Mon Nov 18 07:37:20 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  wb - r+b
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.128 php4/main/streams.c:1.129
--- php4/main/streams.c:1.128   Mon Nov 18 06:39:42 2002
+++ php4/main/streams.c Mon Nov 18 07:37:19 2002
@@ -20,7 +20,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.128 2002/11/18 11:39:42 wez Exp $ */
+/* $Id: streams.c,v 1.129 2002/11/18 12:37:19 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -1236,7 +1236,7 @@
FILE *fp = php_open_temporary_file(dir, pfx, opened_path TSRMLS_CC);
 
if (fp) {
-   php_stream *stream = php_stream_fopen_from_file_rel(fp, wb);
+   php_stream *stream = php_stream_fopen_from_file_rel(fp, r+b);
if (stream) {
return stream;
}



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




[PHP-CVS] cvs: php4 /main streams.c

2002-11-16 Thread Ilia Alshanetsky
iliaa   Sat Nov 16 19:06:51 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Fixed a problem that would cause include/require(/dir/file) to fail on
  Windows.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.126 php4/main/streams.c:1.127
--- php4/main/streams.c:1.126   Thu Nov 14 05:56:35 2002
+++ php4/main/streams.c Sat Nov 16 19:06:50 2002
@@ -20,7 +20,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.126 2002/11/14 10:56:35 derick Exp $ */
+/* $Id: streams.c,v 1.127 2002/11/17 00:06:50 iliaa Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -1579,6 +1579,32 @@
 
return php_stream_fopen_rel(filename, mode, opened_path, options);
}
+   
+#ifdef PHP_WIN32
+   if (IS_SLASH(filename[0])) {
+   int cwd_len;
+   char *cwd;
+   cwd = virtual_getcwd_ex(cwd_len TSRMLS_CC);
+   /* getcwd() will return always return [DRIVE_LETTER]:/) on windows. */
+   *(cwd+3) = '\0';
+   
+   snprintf(trypath, MAXPATHLEN, %s%s, cwd, filename);
+   
+   free(cwd);
+   
+   if (php_check_open_basedir(trypath TSRMLS_CC)) {
+   return NULL;
+   }
+   if ((php_check_safe_mode_include_dir(trypath TSRMLS_CC)) == 0) {
+   return php_stream_fopen_rel(trypath, mode, opened_path, 
+options);
+   }   
+   if (PG(safe_mode)  (!php_checkuid(trypath, mode, 
+CHECKUID_CHECK_MODE_PARAM))) {
+   return NULL;
+   }
+   
+   return php_stream_fopen_rel(trypath, mode, opened_path, options);
+   }
+#endif
 
if (!path || (path  !*path)) {
 



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




[PHP-CVS] cvs: php4 /main streams.c

2002-11-09 Thread Ilia Alshanetsky
iliaa   Sun Nov 10 00:14:27 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Fixed a bug that in many situations would cause open_basedir restriction to
  be bypassed. Most notable exception, is the inclusion of files via include(),
  with a partial path.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.124 php4/main/streams.c:1.125
--- php4/main/streams.c:1.124   Tue Nov  5 19:15:24 2002
+++ php4/main/streams.c Sun Nov 10 00:14:26 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.124 2002/11/06 00:15:24 helly Exp $ */
+/* $Id: streams.c,v 1.125 2002/11/10 05:14:26 iliaa Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -1626,26 +1626,28 
end++;
}
snprintf(trypath, MAXPATHLEN, %s/%s, ptr, filename);
+   
+   if (php_check_open_basedir(trypath TSRMLS_CC)) {
+   stream = NULL;
+   goto stream_done;
+   }
+   
if (PG(safe_mode)) {
if (VCWD_STAT(trypath, sb) == 0) {
/* file exists ... check permission */
-
-   if (php_check_open_basedir(trypath TSRMLS_CC)) {
-   stream = NULL;
-   } else if ((php_check_safe_mode_include_dir(trypath 
TSRMLS_CC) == 0) ||
+   if ((php_check_safe_mode_include_dir(trypath 
+TSRMLS_CC) == 0) ||
php_checkuid(trypath, mode, 
CHECKUID_CHECK_MODE_PARAM)) {
/* UID ok, or trypath is in 
safe_mode_include_dir */
stream = php_stream_fopen_rel(trypath, mode, 
opened_path, options);
} else {
stream = NULL;
}
-
-   efree(pathbuf);
-   return stream;
+   goto stream_done;
}
}
stream = php_stream_fopen_rel(trypath, mode, opened_path, options);
if (stream) {
+   stream_done:
efree(pathbuf);
return stream;
}



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




[PHP-CVS] cvs: php4 /main streams.c

2002-10-31 Thread Wez Furlong
wez Thu Oct 31 23:58:23 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Probable fix for #20180.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.122 php4/main/streams.c:1.123
--- php4/main/streams.c:1.122   Mon Oct 28 07:37:31 2002
+++ php4/main/streams.c Thu Oct 31 23:58:23 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.122 2002/10/28 12:37:31 iliaa Exp $ */
+/* $Id: streams.c,v 1.123 2002/11/01 04:58:23 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -1286,7 +1286,7 
if (data-fd = 0) {
ret = read(data-fd, buf, count);

-   if (ret == 0 || (ret  count  errno != EWOULDBLOCK))
+   if (ret == 0 || (ret == -1  errno != EWOULDBLOCK))
stream-eof = 1;

} else {



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




[PHP-CVS] cvs: php4 /main streams.c

2002-10-28 Thread Ilia Alshanetsky
iliaa   Mon Oct 28 07:37:31 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Fix win32 build.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.121 php4/main/streams.c:1.122
--- php4/main/streams.c:1.121   Sun Oct 27 22:45:21 2002
+++ php4/main/streams.c Mon Oct 28 07:37:31 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.121 2002/10/28 03:45:21 iliaa Exp $ */
+/* $Id: streams.c,v 1.122 2002/10/28 12:37:31 iliaa Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -1638,6 +1638,10 
 
 }
 /* }}} */
+
+#ifndef S_ISREG
+#define S_ISREG(mode)  (((mode)S_IFMT) == S_IFREG)
+#endif
 
 /* {{{ php_stream_fopen */
 PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, char 
**opened_path, int options STREAMS_DC TSRMLS_DC)



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





[PHP-CVS] cvs: php4 /main streams.c

2002-10-27 Thread Ilia Alshanetsky
iliaa   Sun Oct 27 19:28:11 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Fixed bug #20110.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.119 php4/main/streams.c:1.120
--- php4/main/streams.c:1.119   Sun Oct 27 18:34:48 2002
+++ php4/main/streams.c Sun Oct 27 19:28:11 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.119 2002/10/27 23:34:48 shane Exp $ */
+/* $Id: streams.c,v 1.120 2002/10/28 00:28:11 iliaa Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -1644,13 +1644,20 
 {
FILE *fp;
char *realpath = NULL;
+   struct stat st;
+   php_stream *ret;
 
realpath = expand_filepath(filename, NULL TSRMLS_CC);
 
fp = fopen(realpath, mode);
 
if (fp) {
-   php_stream *ret = php_stream_fopen_from_file_rel(fp, mode);
+   /* this is done to prevent opening of anything other then regular 
+files */
+   if (fstat(fileno(fp), st) == -1 || !S_ISREG(st.st_mode)) {
+   goto err;
+   }
+   
+   ret = php_stream_fopen_from_file_rel(fp, mode);
 
if (ret){
if (opened_path){
 -1662,7 +1669,7 
 
return ret;
}
-
+   err:
fclose(fp);
}
efree(realpath);



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




[PHP-CVS] cvs: php4 /main streams.c

2002-10-19 Thread Wez Furlong
wez Sat Oct 19 06:34:10 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Probable fix for #19944
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.110 php4/main/streams.c:1.111
--- php4/main/streams.c:1.110   Fri Oct 18 16:39:49 2002
+++ php4/main/streams.c Sat Oct 19 06:34:10 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.110 2002/10/18 20:39:49 iliaa Exp $ */
+/* $Id: streams.c,v 1.111 2002/10/19 10:34:10 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -495,7 +495,7 
TSRMLS_CC);
}
 
-   if (justread  0) {
+   if (justread != (size_t)-1) {
stream-writepos += justread;
}
}



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




Re: [PHP-CVS] cvs: php4 /main streams.c

2002-10-19 Thread Wez Furlong
Nope.  The problem was that size_t is unsigned, but -1 is signed.

--Wez.

On 10/19/02, Sander Roobol [EMAIL PROTECTED] wrote:
 On Sat, Oct 19, 2002 at 10:34:10AM -, Wez Furlong wrote:
  -   if (justread  0) {
  +   if (justread != (size_t)-1) {
 
 Shouldn't that be someting like this?
if (justread != sizeof(size_t)-1) {
 
 Sander
 
 -- 
 PHP CVS Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




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




[PHP-CVS] cvs: php4 /main streams.c

2002-10-15 Thread Wez Furlong

wez Tue Oct 15 12:04:47 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Some buffer paranoia.
  Also, make feof() detection safer (ala recent changes to zlib extension).
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.105 php4/main/streams.c:1.106
--- php4/main/streams.c:1.105   Mon Oct 14 01:38:50 2002
+++ php4/main/streams.c Tue Oct 15 12:04:46 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.105 2002/10/14 05:38:50 wez Exp $ */
+/* $Id: streams.c,v 1.106 2002/10/15 16:04:46 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -808,6 +808,10 
buf += justwrote;
count -= justwrote;
didwrite += justwrote;
+   
+   /* FIXME: invalidate the whole readbuffer */
+   stream-writepos = 0;
+   stream-readpos = 0;
} else {
break;
}
 -827,24 +831,26 
return 0;
 
/* handle the case where we are in the buffer */
-   switch(whence) {
-   case SEEK_CUR:
-   if (offset  0  offset  stream-writepos - stream-readpos) 
{
-   stream-readpos += offset;
-   stream-position += offset;
-   stream-eof = 0;
-   return 0;
-   }
-   break;
-   case SEEK_SET:
-   if (offset  stream-position 
-   offset  stream-position + stream-writepos - 
stream-readpos) {
-   stream-readpos += offset - stream-position;
-   stream-position = offset;
-   stream-eof = 0;
-   return 0;
-   }
-   break;
+   if ((stream-flags  PHP_STREAM_FLAG_NO_BUFFER) == 0) {
+   switch(whence) {
+   case SEEK_CUR:
+   if (offset  0  offset  stream-writepos - 
+stream-readpos) {
+   stream-readpos += offset;
+   stream-position += offset;
+   stream-eof = 0;
+   return 0;
+   }
+   break;
+   case SEEK_SET:
+   if (offset  stream-position 
+   offset  stream-position + 
+stream-writepos - stream-readpos) {
+   stream-readpos += offset - stream-position;
+   stream-position = offset;
+   stream-eof = 0;
+   return 0;
+   }
+   break;
+   }
}

/* invalidate the buffer contents */
 -1286,7 +1292,7 
 
ret = fread(buf, 1, count, data-file);
 
-   if (ret == 0  feof(data-file))
+   if (feof(data-file))
stream-eof = 1;
}
return ret;



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




[PHP-CVS] cvs: php4 /main streams.c

2002-10-15 Thread Wez Furlong

wez Tue Oct 15 12:38:11 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Fix mem leak for zero-byte files.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.106 php4/main/streams.c:1.107
--- php4/main/streams.c:1.106   Tue Oct 15 12:04:46 2002
+++ php4/main/streams.c Tue Oct 15 12:38:11 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.106 2002/10/15 16:04:46 wez Exp $ */
+/* $Id: streams.c,v 1.107 2002/10/15 16:38:11 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -1028,7 +1028,7 
 #endif

srcfile = mmap(NULL, maxlen, PROT_READ, MAP_SHARED, srcfd, 0);
-   if (srcfile != (void*)MAP_FAILED) {
+   if (srcfile != (void*)MAP_FAILED  ret  0) {
 
*buf = pemalloc_rel_orig(maxlen + 1, persistent);
 



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




[PHP-CVS] cvs: php4 /main streams.c

2002-10-13 Thread Wez Furlong

wez Fri Oct 11 22:31:43 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Write in blocks of the current chunk_size for a stream.
  Should resolve problems with network writes.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.99 php4/main/streams.c:1.100
--- php4/main/streams.c:1.99Sun Oct  6 23:12:06 2002
+++ php4/main/streams.c Fri Oct 11 22:31:42 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.99 2002/10/07 03:12:06 sas Exp $ */
+/* $Id: streams.c,v 1.100 2002/10/12 02:31:42 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -759,18 +759,31 
 
 PHPAPI size_t _php_stream_write(php_stream *stream, const char *buf, size_t count 
TSRMLS_DC)
 {
-   size_t didwrite;
+   size_t didwrite = 0, towrite, justwrote;

assert(stream);
if (buf == NULL || count == 0 || stream-ops-write == NULL)
return 0;
 
-   if (stream-filterhead) {
-   didwrite = stream-filterhead-fops-write(stream, stream-filterhead, 
buf, count TSRMLS_CC);
-   } else {
-   didwrite = stream-ops-write(stream, buf, count TSRMLS_CC);
+   while (count  0) {
+   towrite = count;
+   if (towrite  stream-chunk_size)
+   towrite = stream-chunk_size;
+   
+   if (stream-filterhead) {
+   justwrote = stream-filterhead-fops-write(stream, 
+stream-filterhead, buf, towrite TSRMLS_CC);
+   } else {
+   justwrote = stream-ops-write(stream, buf, towrite TSRMLS_CC);
+   }
+   if (justwrote  0) {
+   stream-position += justwrote;
+   buf += justwrote;
+   count -= justwrote;
+   didwrite += justwrote;
+   } else {
+   break;
+   }
}
-   stream-position += didwrite;
return didwrite;
 }
 



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




[PHP-CVS] cvs: php4 /main streams.c

2002-10-13 Thread Wez Furlong

wez Sun Oct 13 18:52:33 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Fix a nasty nasty bug:
  When not enough data to satisfy a read was found in the buffer, fgets modifies
  the buf pointer to point to the position to store the next chunk.  It then
  returned the modified buf pointer, instead of a pointer to the start of the
  buffer.
  
  Also added some infrastructure for making fgets grow the buffer on-demand to
  the correct line-size.  Since streams uses reasonable chunk sizes, the
  performance of the realloc's should be pretty good; in the best case, the line
  is already found completely in the buffer, so the returned buffer will be
  allocated to precisely the correct size.
  
  In the worst case, where the buffer only contains part of the line, we get a
  realloc per buffer fill. The reallocs are either the size of the remainder
  of the line, or the chunk_size (if the buffer sill does not contain a complete
  line).  Each realloc adds an extra byte for a NUL terminator.
  
  I think this will perform quite well using the default chunk size of 8K.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.101 php4/main/streams.c:1.102
--- php4/main/streams.c:1.101   Fri Oct 11 22:56:34 2002
+++ php4/main/streams.c Sun Oct 13 18:52:33 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.101 2002/10/12 02:56:34 wez Exp $ */
+/* $Id: streams.c,v 1.102 2002/10/13 22:52:33 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -668,12 +668,20 
return eol;
 }
 
+/* If buf == NULL, the buffer will be allocated automatically and will be of an
+ * appropriate length to hold the line, regardless of the line length, memory
+ * permitting */
 PHPAPI char *_php_stream_gets(php_stream *stream, char *buf, size_t maxlen TSRMLS_DC)
 {
size_t avail = 0;
int did_copy = 0;
-
-   if (maxlen == 0)
+   size_t current_buf_size = 0;
+   int grow_mode = 0;
+   char *bufstart = buf;
+
+   if (buf == NULL)
+   grow_mode = 1;
+   else if (maxlen == 0)
return NULL;
 
/*
 -708,9 +716,21 
cpysz = avail;
}
 
-   if (cpysz = maxlen - 1) {
-   cpysz = maxlen - 1;
-   done = 1;
+   if (grow_mode) {
+   /* allow room for a NUL. If this realloc is really a 
+realloc
+* (ie: second time around), we get an extra byte. In 
+most
+* cases, with the default chunk size of 8K, we will 
+only
+* incur that overhead once.  When people have lines 
+longer
+* than 8K, we waste 1 byte per additional 8K or so.
+* That seems acceptable to me, to avoid making this 
+code
+* hard to follow */
+   bufstart = erealloc(bufstart, current_buf_size + cpysz 
++ 1);
+   current_buf_size += cpysz + 1;
+   } else {
+   if (cpysz = maxlen - 1) {
+   cpysz = maxlen - 1;
+   done = 1;
+   }
}
 
memcpy(buf, readptr, cpysz);
 -728,9 +748,15 
break;
} else {
/* XXX: Should be fine to always read chunk_size */
-   size_t toread = maxlen - 1;
-   if (toread  stream-chunk_size)
+   size_t toread;
+   
+   if (grow_mode) {
toread = stream-chunk_size;
+   } else {
+   toread = maxlen - 1;
+   if (toread  stream-chunk_size)
+   toread = stream-chunk_size;
+   }
 
php_stream_fill_read_buffer(stream, toread TSRMLS_CC);
 
 -745,7 +771,7 

buf[0] = '\0';
 
-   return buf;
+   return bufstart;
 }
 
 PHPAPI int _php_stream_flush(php_stream *stream, int closing TSRMLS_DC)



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




[PHP-CVS] cvs: php4 /main streams.c

2002-10-13 Thread Wez Furlong

wez Sun Oct 13 19:43:46 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Remove some old code.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.102 php4/main/streams.c:1.103
--- php4/main/streams.c:1.102   Sun Oct 13 18:52:33 2002
+++ php4/main/streams.c Sun Oct 13 19:43:46 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.102 2002/10/13 22:52:33 wez Exp $ */
+/* $Id: streams.c,v 1.103 2002/10/13 23:43:46 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -544,7 +544,7 
if (toread  size)
toread = size;
 
-   if (toread) {
+   if (toread  0) {
memcpy(buf, stream-readbuf + stream-readpos, toread);
stream-readpos += toread;
}
 -572,14 +572,6 
return 0;
 
return stream-eof;
-   
-   /* we define our stream reading function so that it
-  must return EOF when an EOF condition occurs, when
-  working in unbuffered mode and called with these args */
-   if (stream-filterhead)
-   return stream-filterhead-fops-eof(stream, stream-filterhead 
TSRMLS_CC);
-   
-   return stream-ops-read(stream, NULL, 0 TSRMLS_CC) == EOF ? 1 : 0;
 }
 
 PHPAPI int _php_stream_putc(php_stream *stream, int c TSRMLS_DC)



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




[PHP-CVS] cvs: php4 /main streams.c

2002-10-13 Thread Wez Furlong

wez Mon Oct 14 01:38:50 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  *cough*
  Fix inverted logic for the assert.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.104 php4/main/streams.c:1.105
--- php4/main/streams.c:1.104   Sun Oct 13 22:28:35 2002
+++ php4/main/streams.c Mon Oct 14 01:38:50 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.104 2002/10/14 02:28:35 wez Exp $ */
+/* $Id: streams.c,v 1.105 2002/10/14 05:38:50 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -760,8 +760,9 
}

if (total_copied == 0) {
-   if (grow_mode)
-   assert(bufstart != NULL);
+   if (grow_mode) {
+   assert(bufstart == NULL);
+   }
return NULL;
}




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




[PHP-CVS] cvs: php4 /main streams.c

2002-10-06 Thread Wez Furlong

wez Sun Oct  6 19:27:53 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Try to ensure that we return the number of bytes requested during fread().
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.97 php4/main/streams.c:1.98
--- php4/main/streams.c:1.97Sat Oct  5 06:59:34 2002
+++ php4/main/streams.c Sun Oct  6 19:27:53 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.97 2002/10/05 10:59:34 wez Exp $ */
+/* $Id: streams.c,v 1.98 2002/10/06 23:27:53 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -501,61 +501,63 
 
 PHPAPI size_t _php_stream_read(php_stream *stream, char *buf, size_t size TSRMLS_DC)
 {
-   size_t toread, didread = 0;
+   size_t toread = 0, didread = 0;

-   if (size == 0)
-   return 0;
-   
-   /* take from the read buffer first.
-* It is possible that a buffered stream was switched to non-buffered, so we
-* drain the remainder of the buffer before using the raw read mode for
-* the excess */
-   if (stream-writepos  stream-readpos) {
-   
-   toread = stream-writepos - stream-readpos;
-   if (toread  size)
-   toread = size;
-
-   memcpy(buf, stream-readbuf + stream-readpos, toread);
-   stream-readpos += toread;
-   size -= toread;
-   buf += toread;
-   didread += toread;
-   }
+   while (size  0) {
 
-   if (size == 0) {
-   stream-position += didread;
+   /* take from the read buffer first.
+* It is possible that a buffered stream was switched to non-buffered, 
+so we
+* drain the remainder of the buffer before using the raw read mode 
+for
+* the excess */
+   if (stream-writepos  stream-readpos) {
 
-   if (didread == 0)
-   stream-eof = 1;
-   
-   return didread;
-   }
-   
-   if (stream-flags  PHP_STREAM_FLAG_NO_BUFFER || stream-chunk_size == 1) {
-   if (stream-filterhead) {
-   didread += stream-filterhead-fops-read(stream, 
stream-filterhead,
-   buf, size
-   TSRMLS_CC);
-   } else {
-   didread += stream-ops-read(stream, buf, size TSRMLS_CC);
+   toread = stream-writepos - stream-readpos;
+   if (toread  size)
+   toread = size;
+
+   memcpy(buf, stream-readbuf + stream-readpos, toread);
+   stream-readpos += toread;
+   size -= toread;
+   buf += toread;
+   didread += toread;
}
-   } else {
-   php_stream_fill_read_buffer(stream, size TSRMLS_CC);
 
-   if ((off_t)size  stream-writepos - stream-readpos)
-   size = stream-writepos - stream-readpos;
-   
-   if (size) {
-   memcpy(buf, stream-readbuf + stream-readpos, size);
-   stream-readpos += size;
-   didread += size;
+   if (size == 0) {
+   break;
+   }
+
+   if (stream-flags  PHP_STREAM_FLAG_NO_BUFFER || stream-chunk_size == 
+1) {
+   if (stream-filterhead) {
+   toread = stream-filterhead-fops-read(stream, 
+stream-filterhead,
+   buf, size
+   TSRMLS_CC);
+   } else {
+   toread = stream-ops-read(stream, buf, size 
+TSRMLS_CC);
+   }
+   } else {
+   php_stream_fill_read_buffer(stream, size TSRMLS_CC);
+
+   toread = stream-writepos - stream-readpos;
+   if (toread  size)
+   toread = size;
+
+   if (toread) {
+   memcpy(buf, stream-readbuf + stream-readpos, toread);
+   stream-readpos += toread;
+   }
+   }
+   if (toread  0) {
+   didread += toread;
+   buf += toread;
+   size -= toread;
+   } else {
+   /* EOF, or temporary end of data (for non-blocking mode). */
+   break;
}
}
-   stream-position += size;
 
-   if (didread == 0)
-   stream-eof = 1;
+   if (didread  0)
+   stream-position += didread;
 
return didread;
 }



-- 
PHP CVS 

[PHP-CVS] cvs: php4 /main streams.c

2002-10-06 Thread Sascha Schumann

sas Sun Oct  6 23:12:06 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  stdio buffers data in user land. By calling fflush(3), this
  data is sent to the kernel using write(2). fsync'ing a 
  file descriptor is not required -- writing to a fd has the same
  affect as calling fflush after each fwrite.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.98 php4/main/streams.c:1.99
--- php4/main/streams.c:1.98Sun Oct  6 19:27:53 2002
+++ php4/main/streams.c Sun Oct  6 23:12:06 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.98 2002/10/06 23:27:53 wez Exp $ */
+/* $Id: streams.c,v 1.99 2002/10/07 03:12:06 sas Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -1280,11 +1280,15 
 
assert(data != NULL);
 
-   if (data-fd = 0) {
-   return fsync(data-fd);
-   } else {
+   /*
+* stdio buffers data in user land. By calling fflush(3), this
+* data is send to the kernel using write(2). fsync'ing is
+* something completely different.
+*/
+   if (data-fd  0) {
return fflush(data-file);
}
+   return 0;
 }
 
 static int php_stdiop_seek(php_stream *stream, off_t offset, int whence, off_t 
*newoffset TSRMLS_DC)



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




[PHP-CVS] cvs: php4 /main streams.c

2002-10-04 Thread Ilia Alshanetsky

iliaa   Fri Oct  4 14:44:47 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Fixed bug #19746
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.90 php4/main/streams.c:1.91
--- php4/main/streams.c:1.90Fri Oct  4 14:21:40 2002
+++ php4/main/streams.c Fri Oct  4 14:44:47 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.90 2002/10/04 18:21:40 sas Exp $ */
+/* $Id: streams.c,v 1.91 2002/10/04 18:44:47 iliaa Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -711,6 +711,8 
size_t toread = maxlen - 1;
if (toread  stream-chunk_size)
toread = stream-chunk_size;
+   else if (toread  stream-chunk_size)
+   stream-chunk_size = toread;
 
/* XXX: Should not the loop end, if the stream op fails? */
php_stream_fill_read_buffer(stream, toread TSRMLS_CC);



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




[PHP-CVS] cvs: php4 /main streams.c

2002-10-04 Thread Sascha Schumann

sas Fri Oct  4 15:36:10 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Interrupt loop, if the stream op fails.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.93 php4/main/streams.c:1.94
--- php4/main/streams.c:1.93Fri Oct  4 15:08:43 2002
+++ php4/main/streams.c Fri Oct  4 15:36:09 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.93 2002/10/04 19:08:43 sas Exp $ */
+/* $Id: streams.c,v 1.94 2002/10/04 19:36:09 sas Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -713,8 +713,11 
if (toread  stream-chunk_size)
toread = stream-chunk_size;
 
-   /* XXX: Should not the loop end, if the stream op fails? */
php_stream_fill_read_buffer(stream, toread TSRMLS_CC);
+
+   if (stream-writepos - stream-readpos == 0) {
+   break;
+   }
}
}




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




[PHP-CVS] cvs: php4 /main streams.c

2002-10-04 Thread Sascha Schumann

sas Fri Oct  4 15:48:59 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Fix EOF cases
  
  Noticed by: Ilia
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.94 php4/main/streams.c:1.95
--- php4/main/streams.c:1.94Fri Oct  4 15:36:09 2002
+++ php4/main/streams.c Fri Oct  4 15:48:59 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.94 2002/10/04 19:36:09 sas Exp $ */
+/* $Id: streams.c,v 1.95 2002/10/04 19:48:59 sas Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -656,6 +656,7 
 PHPAPI char *_php_stream_gets(php_stream *stream, char *buf, size_t maxlen TSRMLS_DC)
 {
size_t avail = 0;
+   int did_copy = 0;

if (maxlen == 0)
return NULL;
 -704,6 +705,7 
buf += cpysz;
maxlen -= cpysz;
 
+   did_copy = 1;
if (done) {
break;
}
 -720,6 +722,9 
}
}
}
+   
+   if (!did_copy)
+   return NULL;

buf[0] = '\0';
 



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




[PHP-CVS] cvs: php4 /main streams.c

2002-10-02 Thread Marcus Börger

helly   Wed Oct  2 09:25:38 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Another missing variable init
  #Wez shouldn't stream-filterhead-fops-flush() affect return value also?
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.87 php4/main/streams.c:1.88
--- php4/main/streams.c:1.87Wed Oct  2 09:18:01 2002
+++ php4/main/streams.c Wed Oct  2 09:25:38 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.87 2002/10/02 13:18:01 helly Exp $ */
+/* $Id: streams.c,v 1.88 2002/10/02 13:25:38 helly Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -687,7 +687,7 
 
 PHPAPI int _php_stream_flush(php_stream *stream, int closing TSRMLS_DC)
 {
-   int ret;
+   int ret = 0;

if (stream-filterhead)
stream-filterhead-fops-flush(stream, stream-filterhead, closing 
TSRMLS_CC);



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




[PHP-CVS] cvs: php4 /main streams.c

2002-09-26 Thread Wez Furlong

wez Thu Sep 26 12:22:28 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Fix for #19580. (Incorrectly warning about lost data when that is not the
  case on systems without fopencookie).
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.83 php4/main/streams.c:1.84
--- php4/main/streams.c:1.83Thu Sep 26 08:12:27 2002
+++ php4/main/streams.c Thu Sep 26 12:22:28 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.83 2002/09/26 12:12:27 wez Exp $ */
+/* $Id: streams.c,v 1.84 2002/09/26 16:22:28 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -1580,7 +1580,7 
 
 exit_success:
 
-   if (stream-writepos  stream-fclose_stdiocast != 
PHP_STREAM_FCLOSE_FOPENCOOKIE) {
+   if ((stream-writepos - stream-readpos)  0  stream-fclose_stdiocast != 
+PHP_STREAM_FCLOSE_FOPENCOOKIE) {
/* the data we have buffered will be lost to the third party library 
that
 * will be accessing the stream.  Emit a warning so that the end-user 
will
 * know that they should try something else */



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




[PHP-CVS] cvs: php4 /main streams.c

2002-09-23 Thread Wez Furlong

wez Mon Sep 23 11:21:17 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Hopefully fix the other warnings that my last warning-fixing commit caused.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.77 php4/main/streams.c:1.78
--- php4/main/streams.c:1.77Mon Sep 23 10:50:21 2002
+++ php4/main/streams.c Mon Sep 23 11:21:16 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.77 2002/09/23 14:50:21 wez Exp $ */
+/* $Id: streams.c,v 1.78 2002/09/23 15:21:16 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -33,6 +33,8 
 #include sys/mman.h
 #endif
 
+#include stddef.h
+
 #include fcntl.h
 
 #ifndef MAP_FAILED
 -320,7 +322,7 
/* allocate/fill the buffer */

/* is there enough data in the buffer ? */
-   while (stream-writepos - stream-readpos  size) {
+   while (stream-writepos - stream-readpos  (off_t)size) {
size_t justread;

/* no; so lets fetch more data */
 -390,7 +392,7 
} else {
php_stream_fill_read_buffer(stream, size TSRMLS_CC);
 
-   if (size  stream-writepos - stream-readpos)
+   if ((off_t)size  stream-writepos - stream-readpos)
size = stream-writepos - stream-readpos;
 
memcpy(buf, stream-readbuf + stream-readpos, size);



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




[PHP-CVS] cvs: php4 /main streams.c

2002-09-23 Thread Wez Furlong

wez Mon Sep 23 19:39:46 2002 EDT

  Modified files:  
/php4/main  streams.c 
  Log:
  Correct a buglet in the newly introduced buffer code.
  # Andi: this might have been the cause of that problem you mentioned.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.80 php4/main/streams.c:1.81
--- php4/main/streams.c:1.80Mon Sep 23 15:10:33 2002
+++ php4/main/streams.c Mon Sep 23 19:39:46 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.80 2002/09/23 19:10:33 wez Exp $ */
+/* $Id: streams.c,v 1.81 2002/09/23 23:39:46 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -355,7 +355,8 
stream-readbuflen - stream-writepos
TSRMLS_CC);
}
-   if (justread == 0)
+   
+   if (justread = 0)
break;
stream-writepos += justread;
}
 -363,15 +364,15 
 
 PHPAPI size_t _php_stream_read(php_stream *stream, char *buf, size_t size TSRMLS_DC)
 {
-   size_t avail, toread, didread = 0;
+   size_t toread, didread = 0;

/* take from the read buffer first.
 * It is possible that a buffered stream was switched to non-buffered, so we
 * drain the remainder of the buffer before using the raw read mode for
 * the excess */
-   avail = stream-writepos - stream-readpos;
-   if (avail) {
-   toread = avail;
+   if (stream-writepos  stream-readpos) {
+   
+   toread = stream-writepos - stream-readpos;
if (toread  size)
toread = size;
 
 -379,7 +380,7 
stream-readpos += toread;
size -= toread;
buf += toread;
-   didread += size;
+   didread += toread;
}
 
if (size == 0)
 -398,10 +399,12 
 
if ((off_t)size  stream-writepos - stream-readpos)
size = stream-writepos - stream-readpos;
-
-   memcpy(buf, stream-readbuf + stream-readpos, size);
-   stream-readpos += size;
-   didread += size;
+   
+   if (size) {
+   memcpy(buf, stream-readbuf + stream-readpos, size);
+   stream-readpos += size;
+   didread += size;
+   }
}
stream-position += size;
return didread;



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