cvs: php4(PHP_4_3) /sapi/cli php_cli.c

From: Date: Tue, 13 May 2003 23:36:38 +0000
Subject: cvs: php4(PHP_4_3) /sapi/cli php_cli.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-20876@lists.php.net to get a copy of this message
sas Tue May 13 19:36:38 2003 EDT Modified files: (Branch: PHP_4_3) /php4/sapi/cli php_cli.c Log: Use POSIX IO here, mainly to fix interactive mode. This also fixes a possible cpu-time hog bug where a file would consist of "#" and nothing else. Index: php4/sapi/cli/php_cli.c diff -u php4/sapi/cli/php_cli.c:1.51.2.11 php4/sapi/cli/php_cli.c:1.51.2.12 --- php4/sapi/cli/php_cli.c:1.51.2.11 Wed Apr 30 09:07:18 2003 +++ php4/sapi/cli/php_cli.c Tue May 13 19:36:38 2003 @@ -46,6 +46,10 @@ #if HAVE_SETLOCALE #include <locale.h> #endif +#if HAVE_FCNTL_H +#include <fcntl.h> +#endif + #include "zend.h" #include "zend_extensions.h" #include "php_ini.h" @@ -75,6 +79,10 @@ #include "php_getopt.h" +#ifndef O_BINARY +#define O_BINARY 0 +#endif + #define PHP_MODE_STANDARD 1 #define PHP_MODE_HIGHLIGHT 2 #define PHP_MODE_INDENT 3 @@ -716,7 +724,7 @@ ap_php_optind++; } if (script_file) { - if (!(file_handle.handle.fp = VCWD_FOPEN(script_file, "rb"))) { + if (!(file_handle.handle.fd = VCWD_OPEN(script_file, O_RDONLY | O_BINARY))) { SG(headers_sent) = 1; SG(request_info).no_headers = 1; php_printf("Could not open input file: %s.\n", script_file); @@ -725,27 +733,30 @@ file_handle.filename = script_file; script_filename = script_file; /* #!php support */ - c = fgetc(file_handle.handle.fp); + c = 0; + read(file_handle.handle.fd, &c, 1); if (c == '#') { while (c != 10 && c != 13) { - c = fgetc(file_handle.handle.fp); /* skip to end of line */ + /* skip to end of line */ + if (read(file_handle.handle.fd, &c, 1) != 1) + break; } /* handle situations where line is terminated by \r\n */ if (c == 13) { - if (fgetc(file_handle.handle.fp) != 10) { + if (read(file_handle.handle.fd, &c, 1) == 1 && c != 10) { long pos = ftell(file_handle.handle.fp); fseek(file_handle.handle.fp, pos - 1, SEEK_SET); } } CG(zend_lineno) = -2; } else { - rewind(file_handle.handle.fp); + lseek(file_handle.handle.fd, 0, SEEK_SET); } } else { file_handle.filename = "-"; - file_handle.handle.fp = stdin; + file_handle.handle.fd = STDIN_FILENO; } - file_handle.type = ZEND_HANDLE_FP; + file_handle.type = ZEND_HANDLE_FD; file_handle.opened_path = NULL; file_handle.free_filename = 0; php_self = file_handle.filename; @@ -761,7 +772,7 @@ if (php_request_startup(TSRMLS_C)==FAILURE) { *arg_excp = arg_free; - fclose(file_handle.handle.fp); + zend_file_handle_dtor(&file_handle); SG(headers_sent) = 1; SG(request_info).no_headers = 1; php_request_shutdown((void *) 0); @@ -798,7 +809,7 @@ case PHP_MODE_STRIP: if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) { zend_strip(TSRMLS_C); - fclose(file_handle.handle.fp); + zend_file_handle_dtor(&file_handle); } goto out; break; @@ -809,7 +820,7 @@ if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) { php_get_highlight_struct(&syntax_highlighter_ini); zend_highlight(&syntax_highlighter_ini TSRMLS_CC); - fclose(file_handle.handle.fp); + zend_file_handle_dtor(&file_handle); } goto out; } @@ -819,7 +830,7 @@ case PHP_MODE_INDENT: open_file_for_scanning(&file_handle TSRMLS_CC); zend_indent(); - fclose(file_handle.handle.fp); + zend_file_handle_dtor(&file_handle); goto out; break; #endif

« previous php.cvs (#20876) next »