wez Fri Oct 18 12:55:48 2002 EDT Modified files: /php4/ext/standard file.c Log: Improve file(). Patch by Tal Peer <[EMAIL PROTECTED]> Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.270 php4/ext/standard/file.c:1.271 --- php4/ext/standard/file.c:1.270 Tue Oct 15 12:45:26 2002 +++ php4/ext/standard/file.c Fri Oct 18 12:55:47 2002 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.270 2002/10/15 16:45:26 wez Exp $ */ +/* $Id: file.c,v 1.271 2002/10/18 16:55:47 wez Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -463,7 +463,7 @@ int filename_len; char *slashed, *target_buf; register int i = 0; - int target_len, len; + int len; char eol_marker = '\n'; zend_bool use_include_path = 0; zend_bool reached_eof = 0; @@ -486,47 +486,19 @@ array_init(return_value); /* Now loop through the file and do the magic quotes thing if needed */ - target_len = 0; - target_buf = NULL; while (1) { - if (!target_buf) { - target_buf = (char *) emalloc(PHP_FILE_BUF_SIZE+1); - target_buf[PHP_FILE_BUF_SIZE] = 0; /* avoid overflows */ - } else { - target_buf = (char *) erealloc(target_buf, target_len+PHP_FILE_BUF_SIZE+1); - target_buf[target_len+PHP_FILE_BUF_SIZE] = 0; /* avoid overflows */ - } - if (php_stream_gets(stream, target_buf+target_len, PHP_FILE_BUF_SIZE)==NULL) { - if (target_len==0) { - efree(target_buf); - break; - } else { - reached_eof = 1; - } + target_buf = php_stream_gets(stream, NULL, 0); + if (target_buf == NULL) { + break; } - /* mini-hack because I don't feel like re-writing this whole function */ - if (stream->flags & PHP_STREAM_FLAG_EOL_MAC) - eol_marker = '\r'; - - if (!reached_eof) { - target_len += strlen(target_buf+target_len); - if (target_buf[target_len-1] != eol_marker) { - continue; - } - } if (PG(magic_quotes_runtime)) { - slashed = php_addslashes(target_buf, target_len, &len, 1 TSRMLS_CC); /* 1 = free source string */ - add_index_stringl(return_value, i++, slashed, len, 0); + /* 1 = free source string */ + slashed = php_addslashes(target_buf, strlen(target_buf), &len, +1 TSRMLS_CC); + add_next_index_stringl(return_value, slashed, len, 0); } else { - target_buf = erealloc(target_buf, target_len+1); /* do we really want to do that? */ - add_index_stringl(return_value, i++, target_buf, target_len, 0); - } - if (reached_eof) { - break; + add_next_index_string(return_value, target_buf, 0); } - target_buf = NULL; - target_len = 0; } php_stream_close(stream); }
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php