Re: cvs: php4 /ext/standard file.c
| From: | Andi Gutmans | Date: | Fri, 22 Dec 2000 16:45:43 +0000 |
| Subject: | Re: cvs: php4 /ext/standard file.c | ||
| References: | 1 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-3228@lists.php.net to get a copy of this message | ||
As you're doing the write() in one go now and the file could be very big you're best off checking the return value on how much has been written and call write() as many times as needed. Less change that the 8K buffer will fail although it should also be done if mmap() isn't being used.
Probably best if we have full_write() and full_read() API functions which do it for you and change most places to use these.
Andi
At 04:34 PM 12/22/00 +0000, Sascha Schumann wrote:
--- Andi Gutmans <andi@zend.com> http://www.zend.com/sas Fri Dec 22 08:34:12 2000 EDTModified files:/php4/ext/standard file.cLog: (php_file_copy) Use mmap to map the source file into our address space and then simply write it out to the target file. That avoids switching between user and kernel land too many times. If that does not work, we fall back to the read/write method. Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.128 php4/ext/standard/file.c:1.129--- php4/ext/standard/file.c:1.128 Thu Dec 14 06:18:35 2000 +++ php4/ext/standard/file.c Fri Dec 22 08:34:11 2000@@ -20,7 +20,7 @@+----------------------------------------------------------------------+*/ -/* $Id: file.c,v 1.128 2000/12/14 14:18:35 hholzgra Exp $ */ +/* $Id: file.c,v 1.129 2000/12/22 16:34:11 sas Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -1658,6 +1658,7 @@ {char buffer[8192]; int fd_s,fd_t,read_bytes; + int ret = FAILURE;#ifdef PHP_WIN32if ((fd_s=V_OPEN((src,O_RDONLY|_O_BINARY)))==-1) {@@ -1677,18 +1678,36 @@return FAILURE; }+#ifdef HAVE_MMAP+ { + void *srcfile; + struct stat sbuf;++ if (fstat(fd_s, &sbuf)) { + goto cleanup; + } + srcfile = mmap(NULL, sbuf.st_size, PROT_READ, MAP_SHARED, fd_s, 0); + if (srcfile) { + write(fd_t, srcfile, sbuf.st_size); + ret = SUCCESS; + munmap(srcfile, sbuf.st_size); + goto cleanup; + } + }+#endif +while ((read_bytes=read(fd_s,buffer,8192))!=-1 && read_bytes!=0) { if (write(fd_t,buffer,read_bytes)==-1) { php_error(E_WARNING,"Unable to write to '%s': %s", dest, strerror(errno)); - close(fd_s); - close(fd_t); - return FAILURE; + goto cleanup; } } + ret = SUCCESS;+cleanup:close(fd_s); close(fd_t); - return SUCCESS; + return ret;} -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-cvs-unsubscribe@lists.php.net For additional commands, e-mail: php-cvs-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net