summaryrefslogtreecommitdiff
path: root/sapi
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2009-01-09 17:21:12 +0000
committerIlia Alshanetsky <iliaa@php.net>2009-01-09 17:21:12 +0000
commit71ea95354b4133f12dcf8207bc7b36e1562bdd65 (patch)
treed086c5d9579dfef4baeaceb7519080dbdf086ab1 /sapi
parent2538bd21e7086941dea30e59ac3927654ea2d9db (diff)
downloadphp-git-71ea95354b4133f12dcf8207bc7b36e1562bdd65.tar.gz
MFH: Corrected fix for bug #46844 to only trigger on the 1st line of CLI
opened files.
Diffstat (limited to 'sapi')
-rw-r--r--sapi/cli/php_cli.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c
index 3b72f9469f..373c39f2c9 100644
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
@@ -570,6 +570,8 @@ static const char *param_mode_conflict = "Either execute direct code, process st
*/
static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, int *lineno TSRMLS_DC)
{
+ char c;
+
*lineno = 1;
file_handle->type = ZEND_HANDLE_FP;
@@ -580,6 +582,25 @@ static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file,
return FAILURE;
}
file_handle->filename = script_file;
+
+ /* #!php support */
+ c = fgetc(file_handle->handle.fp);
+ if (c == '#' && (c = fgetc(file_handle->handle.fp)) == '!') {
+ while (c != '\n' && c != '\r' && c != EOF) {
+ c = fgetc(file_handle->handle.fp); /* skip to end of line */
+ }
+ /* handle situations where line is terminated by \r\n */
+ if (c == '\r') {
+ if (fgetc(file_handle->handle.fp) != '\n') {
+ long pos = ftell(file_handle->handle.fp);
+ fseek(file_handle->handle.fp, pos - 1, SEEK_SET);
+ }
+ }
+ *lineno = 2;
+ } else {
+ rewind(file_handle->handle.fp);
+ }
+
return SUCCESS;
}
/* }}} */