-
Couldn't load subscription status.
- Fork 8k
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 all commits
a0e0d8d
18c5c42
be50062
e11f3d2
6953d2f
bd93781
35bf19a
d9b1c99
2f05643
694e207
4f4ffd0
3fcdc64
99bd01e
7b155f4
08e75a2
c10467e
dd85825
a6e88f6
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
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ typedef unsigned long long php_timeout_ull; | |
| #else | ||
| #include "win32/select.h" | ||
| #include "win32/sockets.h" | ||
| #include "win32/console.h" | ||
| typedef unsigned __int64 php_timeout_ull; | ||
| #endif | ||
|
|
||
|
|
@@ -1569,6 +1570,119 @@ PHP_FUNCTION(stream_supports_lock) | |
| RETURN_TRUE; | ||
| } | ||
|
|
||
| /* {{{ proto proto stream_isatty(resource stream) | ||
| Check if a stream is a TTY. | ||
| */ | ||
| PHP_FUNCTION(stream_isatty) | ||
| { | ||
| zval *zsrc; | ||
| php_stream *stream; | ||
| zend_long fileno; | ||
|
|
||
| if (zend_parse_parameters(ZEND_NUM_ARGS(), "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); | ||
| } | ||
| 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 | ||
| zend_stat_t stat; | ||
| if (zend_fstat(fileno, &stat) == 0) { | ||
| if ((stat.st_mode & /*S_IFMT*/0170000) == /*S_IFCHR*/0020000) { | ||
| RETURN_TRUE; | ||
| } | ||
| } | ||
| RETURN_NULL(); | ||
| #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; | ||
| zend_bool enable; | ||
| zend_long fileno; | ||
|
|
||
| int argc = ZEND_NUM_ARGS(); | ||
|
|
||
| if (zend_parse_parameters(argc, "r|b", &zsrc, &enable) == 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); | ||
| } | ||
| else if (php_stream_can_cast(stream, PHP_STREAM_AS_FD) == SUCCESS) { | ||
| php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)&fileno, 0); | ||
| } | ||
| else { | ||
| zend_internal_type_error( | ||
| ZEND_ARG_USES_STRICT_TYPES(), | ||
| "%s() was not able to analyze the specified stream", | ||
| get_active_function_name() | ||
| ); | ||
| RETURN_FALSE; | ||
| } | ||
|
|
||
| /* Check if the file descriptor is a console */ | ||
| if (!php_win32_console_fileno_is_console(fileno)) { | ||
| RETURN_FALSE; | ||
| } | ||
|
|
||
| if (argc == 1) { | ||
| /* Check if the Windows standard handle has VT100 control codes enabled */ | ||
| if (php_win32_console_fileno_has_vt100(fileno)) { | ||
| RETURN_TRUE; | ||
| } | ||
| else { | ||
| RETURN_FALSE; | ||
| } | ||
| } | ||
| else { | ||
| /* 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; | ||
| } | ||
| } | ||
| } | ||
| #endif | ||
|
|
||
| #ifdef HAVE_SHUTDOWN | ||
| /* {{{ proto int stream_socket_shutdown(resource stream, int how) | ||
| causes all or part of a full-duplex connection on the socket associated | ||
|
|
||
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.
The void* cast will cause the stack corruption on 64-bit.
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.
Fixed in 694e207