cvs: php4 /ext/standard file.c
| From: | Sascha Schumann | Date: | Fri, 22 Dec 2000 16:34:12 +0000 |
| Subject: | cvs: php4 /ext/standard file.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-3226@lists.php.net to get a copy of this message | ||
sas Fri Dec 22 08:34:12 2000 EDT
Modified files:
/php4/ext/standard file.c
Log:
(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_WIN32
if ((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;
}