-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Implement stream_vt100_support user function #2103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
a0e0d8d
18c5c42
be50062
e11f3d2
6953d2f
bd93781
35bf19a
d9b1c99
2f05643
694e207
4f4ffd0
3fcdc64
99bd01e
7b155f4
08e75a2
c10467e
dd85825
a6e88f6
8000
1643715
f86567e
658ff84
d9e0531
157f8e8
76411a4
4d956f2
7d348a0
4588b50
bf60a78
5d2ecf9
7581767
d15063c
65ad779
67e1eb7
f9ff470
6df8c3c
1081aa8
e4aaa27
2d062f3
d70a7f2
c2988ea
d1772e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1636,10 +1636,60 @@ PHP_FUNCTION(stream_supports_lock) | |
RETURN_TRUE; | ||
} | ||
|
||
/* {{{ proto proto stream_vt100_support(resource stream[, bool enable]) | ||
Get or set VT100 support for the specified stream. | ||
/* {{{ proto proto stream_isatty(resource stream) | ||
Check if a stream is a TTY. | ||
*/ | ||
PHP_FUNCTION(stream_vt100_support) | ||
PHP_FUNCTION(stream_isatty) | ||
{ | ||
zval *zsrc; | ||
php_stream *stream; | ||
zend_long fileno; | ||
|
||
int argc = ZEND_NUM_ARGS(); | ||
|
||
if (zend_parse_parameters(argc, "r", &zsrc) == FAILURE) { | ||
RETURN_FALSE; | ||
} | ||
|
||
php_stream_from_zval(stream, zsrc); | ||
|
||
if (php_stream_can_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT) == SUCCESS) { | ||
php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT, (void*)&fileno, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The void* cast will cause the stack corruption on 64-bit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Fixed in 694e207 |
||
} | ||
else if (php_stream_can_cast(stream, PHP_STREAM_AS_FD) == SUCCESS) { | ||
php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)&fileno, 0); | ||
} | ||
else { | ||
RETURN_FALSE; | ||
} | ||
|
||
#ifdef PHP_WIN32 | ||
/* Check if the Windows standard handle is redirected to file */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Much better: e4aaa27 |
||
if (php_win32_console_fileno_is_console(fileno)) { | ||
RETURN_TRUE; | ||
} | ||
else { | ||
RETURN_FALSE; | ||
} | ||
#elif HAVE_POSIX | ||
/* Check if the file descriptor identifier is a terminal */ | ||
if (isatty(fileno)) { | ||
RETURN_TRUE; | ||
} | ||
else { | ||
RETURN_FALSE; | ||
} | ||
#else | ||
RETURN_FALSE; | ||
#endif | ||
} | ||
|
||
#ifdef PHP_WIN32 | ||
/* {{{ proto proto sapi_windows_vt100_support(resource stream[, bool enable]) | ||
Get or set VT100 support for the specified stream associated to an | ||
output buffer of a Windows console. | ||
*/ | ||
PHP_FUNCTION(sapi_windows_vt100_support) | ||
{ | ||
zval *zsrc; | ||
php_stream *stream; | ||
|
@@ -1669,51 +1719,31 @@ PHP_FUNCTION(stream_vt100_support) | |
RETURN_FALSE; | ||
} | ||
|
||
/* Check if the Windows standard handle is redirected to file */ | ||
if (!php_win32_console_fileno_is_console(fileno)) { | ||
RETURN_FALSE; | ||
} | ||
|
||
if (argc == 1) { | ||
/* Check if the specified stream supports VT100 control codes */ | ||
#ifdef PHP_WIN32 | ||
/* Check if the Windows standard handle is redirected to file */ | ||
if (!php_win32_console_fileno_is_console(fileno)) { | ||
RETURN_FALSE; | ||
} | ||
/* Check if the Windows standard handle has VT100 control codes enabled */ | ||
if (php_win32_console_fileno_has_vt100(fileno)) { | ||
RETURN_TRUE; | ||
} | ||
else { | ||
RETURN_FALSE; | ||
} | ||
#elif HAVE_POSIX | ||
/* Check if the file descriptor identifier is a terminal */ | ||
if (isatty(fileno)) { | ||
RETURN_TRUE; | ||
} | ||
else { | ||
RETURN_FALSE; | ||
} | ||
#else | ||
RETURN_FALSE; | ||
#endif | ||
} | ||
else { | ||
/* Enable/disable VT100 control codes support for the specified stream */ | ||
#ifdef PHP_WIN32 | ||
/* Check if the Windows standard handle is redirected to file */ | ||
if (!php_win32_console_fileno_is_console(fileno)) { | ||
RETURN_FALSE; | ||
} | ||
/* Enable/disable VT100 control codes support for the specified Windows standard handle */ | ||
if (php_win32_console_fileno_set_vt100(fileno, enable ? TRUE : FALSE)) { | ||
RETURN_TRUE; | ||
} | ||
else { | ||
RETURN_FALSE; | ||
} | ||
#else | ||
RETURN_FALSE; | ||
#endif | ||
} | ||
} | ||
#endif | ||
|
||
#ifdef HAVE_SHUTDOWN | ||
/* {{{ proto int stream_socket_shutdown(resource stream, int how) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You only use this in the call to
zend_parse_parameters
nowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 1081aa8