stas            Thu Feb  1 02:24:02 2001 EDT

  Modified files:              
    /php4/ext/standard  file.c 
  Log:
  Add utility function
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.136 php4/ext/standard/file.c:1.137
--- php4/ext/standard/file.c:1.136      Sun Jan 21 09:26:43 2001
+++ php4/ext/standard/file.c    Thu Feb  1 02:24:02 2001
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: file.c,v 1.136 2001/01/21 17:26:43 rasmus Exp $ */
+/* $Id: file.c,v 1.137 2001/02/01 10:24:02 stas Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -2071,6 +2071,36 @@
 }      
 
 #endif
+
+/* Function reads all data from file or socket and puts it into the buffer */
+size_t php_fread_all(char **buf, int socket, FILE *fp, int issock) {
+       size_t ret;
+       char *ptr;
+       size_t len = 0, max_len;
+       int step = PHP_FSOCK_CHUNK_SIZE;
+       int min_room = PHP_FSOCK_CHUNK_SIZE/4;
+       
+       ptr = *buf = emalloc(step);
+       max_len = step;
+
+       while(ret = FP_FREAD(ptr, max_len - len, socket, fp, issock)) {
+               len += ret;
+               if(len + min_room >= max_len) {
+                       *buf = erealloc(*buf, max_len + step);
+                       max_len += step;
+                       ptr = *buf + len;
+               }
+       }
+
+       if(len) {
+               *buf = erealloc(*buf, len);
+       } else {
+               efree(*buf);
+               *buf = NULL;
+       }
+
+       return len;
+}
 
 /*
  * Local variables:



-- 
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]

Reply via email to