view release on metacpan or search on metacpan
libuv/ChangeLog view on Meta::CPAN
* win,fs: avoid double freeing uv_fs_event_t.dirw (Vladimir Matveev)
* unix: remove unused code in `uv__io_start` (Fedor Indutny)
* signal: add uv_signal_start_oneshot method (Santiago Gimeno)
* unix: factor out reusable POSIX hrtime impl (Brad King)
* unix,win: add uv_os_{get,set,unset}env() (cjihrig)
* win: add uv__convert_utf8_to_utf16() (cjihrig)
* docs: improve UV_ENOBUFS scenario documentation (cjihrig)
* unix: return UV_EINVAL for NULL env name (jBarz)
* unix: filter getifaddrs results consistently (Brad King)
* unix: factor out getifaddrs result filter (Brad King)
* unix: factor out reusable BSD ifaddrs impl (Brad King)
libuv/ChangeLog view on Meta::CPAN
* build: always compile with -fvisibility=hidden (Ben Noordhuis)
* test: fix -Wformat warnings in platform test (Ben Noordhuis)
* win: clarify fsevents handling code (Saúl Ibarra Corretgé)
* test: fix POLLHDRUP related failures for AIX (Imran Iqbal)
* build, mingw: set LIBS in configure.ac (Tony Theodore)
* win: improve uv__convert_utf16_to_utf8 (Saúl Ibarra Corretgé)
* win: simplified UTF16 -> UTF8 conversions (Saúl Ibarra Corretgé)
* win: remove unneeded condition (Saúl Ibarra Corretgé)
* darwin: work around condition variable kernel bug (Ben Noordhuis)
* darwin: make thread stack multiple of page size (Ben Noordhuis)
* build,win: rename platform to msbuild_platform (João Reis)
libuv/docs/code/multi-echo-server/hammer.js view on Meta::CPAN
var net = require('net');
var PHRASE = "hello world";
var write = function(socket) {
socket.write(PHRASE, 'utf8');
}
for (var i = 0; i < 1000; i++) {
(function() {
var socket = net.connect(7000, 'localhost', function() {
socket.on('data', function(reply) {
if (reply.toString().indexOf(PHRASE) != 0)
console.error("Problem! '" + reply + "'" + " '" + PHRASE + "'");
else
write(socket);
libuv/include/uv/win.h view on Meta::CPAN
HANDLE read_raw_wait; \
/* Fields used for translating win keystrokes into vt100 characters */ \
char last_key[8]; \
unsigned char last_key_offset; \
unsigned char last_key_len; \
WCHAR last_utf16_high_surrogate; \
INPUT_RECORD last_input_record; \
} rd; \
struct { \
/* Used for writable TTY handles */ \
/* utf8-to-utf16 conversion state */ \
unsigned int utf8_codepoint; \
unsigned char utf8_bytes_left; \
/* eol conversion state */ \
unsigned char previous_eol; \
/* ansi parser state */ \
unsigned char ansi_parser_state; \
unsigned char ansi_csi_argc; \
unsigned short ansi_csi_argv[4]; \
COORD saved_position; \
WORD saved_attributes; \
} wr; \
} tty;
libuv/src/idna.c view on Meta::CPAN
*/
/* Derived from https://github.com/bnoordhuis/punycode
* but updated to support IDNA 2008.
*/
#include "uv.h"
#include "idna.h"
#include <string.h>
static unsigned uv__utf8_decode1_slow(const char** p,
const char* pe,
unsigned a) {
unsigned b;
unsigned c;
unsigned d;
unsigned min;
if (a > 0xF7)
return -1;
libuv/src/idna.c view on Meta::CPAN
if (a > 0x10FFFF)
return -1; /* Four-byte sequence > U+10FFFF. */
if (a >= 0xD800 && a <= 0xDFFF)
return -1; /* Surrogate pair. */
return a;
}
unsigned uv__utf8_decode1(const char** p, const char* pe) {
unsigned a;
a = (unsigned char) *(*p)++;
if (a < 128)
return a; /* ASCII, common case. */
return uv__utf8_decode1_slow(p, pe, a);
}
#define foreach_codepoint(c, p, pe) \
for (; (void) (*p <= pe && (c = uv__utf8_decode1(p, pe))), *p <= pe;)
static int uv__idna_toascii_label(const char* s, const char* se,
char** d, char* de) {
static const char alphabet[] = "abcdefghijklmnopqrstuvwxyz0123456789";
const char* ss;
unsigned c;
unsigned h;
unsigned k;
unsigned n;
unsigned m;
libuv/src/idna.c view on Meta::CPAN
const char* si;
const char* st;
unsigned c;
char* ds;
int rc;
ds = d;
for (si = s; si < se; /* empty */) {
st = si;
c = uv__utf8_decode1(&si, se);
if (c != '.')
if (c != 0x3002) /* ã */
if (c != 0xFF0E) /* ï¼ */
if (c != 0xFF61) /* 。 */
continue;
rc = uv__idna_toascii_label(s, st, &d, de);
if (rc < 0)
libuv/src/idna.h view on Meta::CPAN
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef UV_SRC_IDNA_H_
#define UV_SRC_IDNA_H_
/* Decode a single codepoint. Returns the codepoint or UINT32_MAX on error.
* |p| is updated on success _and_ error, i.e., bad multi-byte sequences are
* skipped in their entirety, not just the first bad byte.
*/
unsigned uv__utf8_decode1(const char** p, const char* pe);
/* Convert a UTF-8 domain name to IDNA 2008 / Punycode. A return value >= 0
* is the number of bytes written to |d|, including the trailing nul byte.
* A return value < 0 is a libuv error code. |s| and |d| can not overlap.
*/
long uv__idna_toascii(const char* s, const char* se, char* d, char* de);
#endif /* UV_SRC_IDNA_H_ */
libuv/src/win/fs-event.c view on Meta::CPAN
*/
filenamew = file_info->FileName;
sizew = file_info->FileNameLength / sizeof(WCHAR);
}
} else {
/* We already have the long name of the file, so just use it. */
filenamew = handle->filew;
sizew = -1;
}
/* Convert the filename to utf8. */
uv__convert_utf16_to_utf8(filenamew, sizew, &filename);
switch (file_info->Action) {
case FILE_ACTION_ADDED:
case FILE_ACTION_REMOVED:
case FILE_ACTION_RENAMED_OLD_NAME:
case FILE_ACTION_RENAMED_NEW_NAME:
handle->cb(handle, filename, UV_RENAME, 0);
break;
case FILE_ACTION_MODIFIED:
libuv/src/win/fs.c view on Meta::CPAN
req->flags = 0;
req->fs_type = fs_type;
req->result = 0;
req->ptr = NULL;
req->path = NULL;
req->cb = cb;
memset(&req->fs, 0, sizeof(req->fs));
}
static int fs__wide_to_utf8(WCHAR* w_source_ptr,
DWORD w_source_len,
char** target_ptr,
uint64_t* target_len_ptr) {
int r;
int target_len;
char* target;
target_len = WideCharToMultiByte(CP_UTF8,
0,
w_source_ptr,
w_source_len,
libuv/src/win/fs.c view on Meta::CPAN
/* Remove leading \??\ */
w_target += 4;
w_target_len -= 4;
} else {
/* Reparse tag does not indicate a symlink. */
SetLastError(ERROR_SYMLINK_NOT_SUPPORTED);
return -1;
}
return fs__wide_to_utf8(w_target, w_target_len, target_ptr, target_len_ptr);
}
void fs__open(uv_fs_t* req) {
DWORD access;
DWORD share;
DWORD disposition;
DWORD attributes = 0;
HANDLE file;
int fd, current_umask;
libuv/src/win/fs.c view on Meta::CPAN
while (NT_SUCCESS(status)) {
char* position = buffer;
size_t next_entry_offset = 0;
do {
FILE_DIRECTORY_INFORMATION* info;
uv__dirent_t* dirent;
size_t wchar_len;
size_t utf8_len;
/* Obtain a pointer to the current directory entry. */
position += next_entry_offset;
info = (FILE_DIRECTORY_INFORMATION*) position;
/* Fetch the offset to the next directory entry. */
next_entry_offset = info->NextEntryOffset;
/* Compute the length of the filename in WCHARs. */
wchar_len = info->FileNameLength / sizeof info->FileName[0];
libuv/src/win/fs.c view on Meta::CPAN
if (wchar_len == 0)
continue;
if (wchar_len == 1 && info->FileName[0] == L'.')
continue;
if (wchar_len == 2 && info->FileName[0] == L'.' &&
info->FileName[1] == L'.')
continue;
/* Compute the space required to store the filename as UTF-8. */
utf8_len = WideCharToMultiByte(
CP_UTF8, 0, &info->FileName[0], wchar_len, NULL, 0, NULL, NULL);
if (utf8_len == 0)
goto win32_error;
/* Resize the dirent array if needed. */
if (dirents_used >= dirents_size) {
size_t new_dirents_size =
dirents_size == 0 ? dirents_initial_size : dirents_size << 1;
uv__dirent_t** new_dirents =
uv__realloc(dirents, new_dirents_size * sizeof *dirents);
if (new_dirents == NULL)
goto out_of_memory_error;
dirents_size = new_dirents_size;
dirents = new_dirents;
}
/* Allocate space for the uv dirent structure. The dirent structure
* includes room for the first character of the filename, but `utf8_len`
* doesn't count the NULL terminator at this point.
*/
dirent = uv__malloc(sizeof *dirent + utf8_len);
if (dirent == NULL)
goto out_of_memory_error;
dirents[dirents_used++] = dirent;
/* Convert file name to UTF-8. */
if (WideCharToMultiByte(CP_UTF8,
0,
&info->FileName[0],
wchar_len,
&dirent->d_name[0],
utf8_len,
NULL,
NULL) == 0)
goto win32_error;
/* Add a null terminator to the filename. */
dirent->d_name[utf8_len] = '\0';
/* Fill out the type field. */
if (info->FileAttributes & FILE_ATTRIBUTE_DEVICE)
dirent->d_type = UV__DT_CHAR;
else if (info->FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
dirent->d_type = UV__DT_LINK;
else if (info->FileAttributes & FILE_ATTRIBUTE_DIRECTORY)
dirent->d_type = UV__DT_DIR;
else
dirent->d_type = UV__DT_FILE;
libuv/src/win/fs.c view on Meta::CPAN
/* Skip "." and ".." entries. */
if (find_data->cFileName[0] == L'.' &&
(find_data->cFileName[1] == L'\0' ||
(find_data->cFileName[1] == L'.' &&
find_data->cFileName[2] == L'\0'))) {
dir->need_find_call = TRUE;
continue;
}
r = uv__convert_utf16_to_utf8((const WCHAR*) &find_data->cFileName,
-1,
(char**) &dirents[dirent_idx].name);
if (r != 0)
goto error;
/* Copy file type. */
if ((find_data->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
dent.d_type = UV__DT_DIR;
else if ((find_data->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0)
dent.d_type = UV__DT_LINK;
libuv/src/win/fs.c view on Meta::CPAN
LONG_PATH_PREFIX,
LONG_PATH_PREFIX_LEN) == 0) {
w_realpath_ptr += 4;
w_realpath_len -= 4;
} else {
uv__free(w_realpath_buf);
SetLastError(ERROR_INVALID_HANDLE);
return -1;
}
r = fs__wide_to_utf8(w_realpath_ptr, w_realpath_len, realpath_ptr, NULL);
uv__free(w_realpath_buf);
return r;
}
static void fs__realpath(uv_fs_t* req) {
HANDLE handle;
handle = CreateFileW(req->file.pathw,
0,
0,
libuv/src/win/internal.h view on Meta::CPAN
/*
* Utilities.
*/
void uv__util_init(void);
uint64_t uv__hrtime(double scale);
__declspec(noreturn) void uv_fatal_error(const int errorno, const char* syscall);
int uv__getpwuid_r(uv_passwd_t* pwd);
int uv__convert_utf16_to_utf8(const WCHAR* utf16, int utf16len, char** utf8);
int uv__convert_utf8_to_utf16(const char* utf8, int utf8len, WCHAR** utf16);
typedef int (WINAPI *uv__peersockfunc)(SOCKET, struct sockaddr*, int*);
int uv__getsockpeername(const uv_handle_t* handle,
uv__peersockfunc func,
struct sockaddr* name,
int* namelen,
int delayed_error);
libuv/src/win/process.c view on Meta::CPAN
uv_fatal_error(GetLastError(), "CreateJobObjectW");
if (!SetInformationJobObject(uv_global_job_handle_,
JobObjectExtendedLimitInformation,
&info,
sizeof info))
uv_fatal_error(GetLastError(), "SetInformationJobObject");
}
static int uv_utf8_to_utf16_alloc(const char* s, WCHAR** ws_ptr) {
int ws_len, r;
WCHAR* ws;
ws_len = MultiByteToWideChar(CP_UTF8,
0,
s,
-1,
NULL,
0);
if (ws_len <= 0) {
libuv/src/win/process.c view on Meta::CPAN
assert(options->file != NULL);
assert(!(options->flags & ~(UV_PROCESS_DETACHED |
UV_PROCESS_SETGID |
UV_PROCESS_SETUID |
UV_PROCESS_WINDOWS_HIDE |
UV_PROCESS_WINDOWS_HIDE_CONSOLE |
UV_PROCESS_WINDOWS_HIDE_GUI |
UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS)));
err = uv_utf8_to_utf16_alloc(options->file, &application);
if (err)
goto done;
err = make_program_args(
options->args,
options->flags & UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS,
&arguments);
if (err)
goto done;
if (options->env) {
err = make_program_env(options->env, &env);
if (err)
goto done;
}
if (options->cwd) {
/* Explicit cwd */
err = uv_utf8_to_utf16_alloc(options->cwd, &cwd);
if (err)
goto done;
} else {
/* Inherit cwd */
DWORD cwd_len, r;
cwd_len = GetCurrentDirectoryW(0, NULL);
if (!cwd_len) {
err = GetLastError();
libuv/src/win/tty.c view on Meta::CPAN
/* Init keycode-to-vt100 mapper state. */
tty->tty.rd.last_key_len = 0;
tty->tty.rd.last_key_offset = 0;
tty->tty.rd.last_utf16_high_surrogate = 0;
memset(&tty->tty.rd.last_input_record, 0, sizeof tty->tty.rd.last_input_record);
} else {
/* TTY output specific fields. */
tty->flags |= UV_HANDLE_WRITABLE;
/* Init utf8-to-utf16 conversion state. */
tty->tty.wr.utf8_bytes_left = 0;
tty->tty.wr.utf8_codepoint = 0;
/* Initialize eol conversion state */
tty->tty.wr.previous_eol = 0;
/* Init ANSI parser state. */
tty->tty.wr.ansi_parser_state = ANSI_NORMAL;
}
return 0;
}
libuv/src/win/tty.c view on Meta::CPAN
} \
utf16_buf_used = 0; \
} while (0)
#define ENSURE_BUFFER_SPACE(wchars_needed) \
if (wchars_needed > ARRAY_SIZE(utf16_buf) - utf16_buf_used) { \
FLUSH_TEXT(); \
}
/* Cache for fast access */
unsigned char utf8_bytes_left = handle->tty.wr.utf8_bytes_left;
unsigned int utf8_codepoint = handle->tty.wr.utf8_codepoint;
unsigned char previous_eol = handle->tty.wr.previous_eol;
unsigned char ansi_parser_state = handle->tty.wr.ansi_parser_state;
/* Store the error here. If we encounter an error, stop trying to do i/o but
* keep parsing the buffer so we leave the parser in a consistent state. */
*error = ERROR_SUCCESS;
utf16_buffer = utf16_buf;
uv_sem_wait(&uv_tty_output_lock);
libuv/src/win/tty.c view on Meta::CPAN
}
FLUSH_TEXT();
continue;
}
for (j = 0; j < buf.len; j++) {
unsigned char c = buf.base[j];
/* Run the character through the utf8 decoder We happily accept non
* shortest form encodings and invalid code points - there's no real harm
* that can be done. */
if (utf8_bytes_left == 0) {
/* Read utf-8 start byte */
DWORD first_zero_bit;
unsigned char not_c = ~c;
#ifdef _MSC_VER /* msvc */
if (_BitScanReverse(&first_zero_bit, not_c)) {
#else /* assume gcc */
if (c != 0) {
first_zero_bit = (sizeof(int) * 8) - 1 - __builtin_clz(not_c);
#endif
if (first_zero_bit == 7) {
/* Ascii - pass right through */
utf8_codepoint = (unsigned int) c;
} else if (first_zero_bit <= 5) {
/* Multibyte sequence */
utf8_codepoint = (0xff >> (8 - first_zero_bit)) & c;
utf8_bytes_left = (char) (6 - first_zero_bit);
} else {
/* Invalid continuation */
utf8_codepoint = UNICODE_REPLACEMENT_CHARACTER;
}
} else {
/* 0xff -- invalid */
utf8_codepoint = UNICODE_REPLACEMENT_CHARACTER;
}
} else if ((c & 0xc0) == 0x80) {
/* Valid continuation of utf-8 multibyte sequence */
utf8_bytes_left--;
utf8_codepoint <<= 6;
utf8_codepoint |= ((unsigned int) c & 0x3f);
} else {
/* Start byte where continuation was expected. */
utf8_bytes_left = 0;
utf8_codepoint = UNICODE_REPLACEMENT_CHARACTER;
/* Patch buf offset so this character will be parsed again as a start
* byte. */
j--;
}
/* Maybe we need to parse more bytes to find a character. */
if (utf8_bytes_left != 0) {
continue;
}
/* Parse vt100/ansi escape codes */
if (ansi_parser_state == ANSI_NORMAL) {
switch (utf8_codepoint) {
case '\033':
ansi_parser_state = ANSI_ESCAPE_SEEN;
continue;
case 0233:
ansi_parser_state = ANSI_CSI;
handle->tty.wr.ansi_csi_argc = 0;
continue;
}
} else if (ansi_parser_state == ANSI_ESCAPE_SEEN) {
switch (utf8_codepoint) {
case '[':
ansi_parser_state = ANSI_CSI;
handle->tty.wr.ansi_csi_argc = 0;
continue;
case '^':
case '_':
case 'P':
case ']':
/* Not supported, but we'll have to parse until we see a stop code,
libuv/src/win/tty.c view on Meta::CPAN
continue;
case '8':
/* Restore the cursor position and text attributes */
FLUSH_TEXT();
uv_tty_restore_state(handle, 1, error);
ansi_parser_state = ANSI_NORMAL;
continue;
default:
if (utf8_codepoint >= '@' && utf8_codepoint <= '_') {
/* Single-char control. */
ansi_parser_state = ANSI_NORMAL;
continue;
} else {
/* Invalid - proceed as normal, */
ansi_parser_state = ANSI_NORMAL;
}
}
} else if (ansi_parser_state & ANSI_CSI) {
if (!(ansi_parser_state & ANSI_IGNORE)) {
if (utf8_codepoint >= '0' && utf8_codepoint <= '9') {
/* Parsing a numerical argument */
if (!(ansi_parser_state & ANSI_IN_ARG)) {
/* We were not currently parsing a number */
/* Check for too many arguments */
if (handle->tty.wr.ansi_csi_argc >= ARRAY_SIZE(handle->tty.wr.ansi_csi_argv)) {
ansi_parser_state |= ANSI_IGNORE;
continue;
}
ansi_parser_state |= ANSI_IN_ARG;
handle->tty.wr.ansi_csi_argc++;
handle->tty.wr.ansi_csi_argv[handle->tty.wr.ansi_csi_argc - 1] =
(unsigned short) utf8_codepoint - '0';
continue;
} else {
/* We were already parsing a number. Parse next digit. */
uint32_t value = 10 *
handle->tty.wr.ansi_csi_argv[handle->tty.wr.ansi_csi_argc - 1];
/* Check for overflow. */
if (value > UINT16_MAX) {
ansi_parser_state |= ANSI_IGNORE;
continue;
}
handle->tty.wr.ansi_csi_argv[handle->tty.wr.ansi_csi_argc - 1] =
(unsigned short) value + (utf8_codepoint - '0');
continue;
}
} else if (utf8_codepoint == ';') {
/* Denotes the end of an argument. */
if (ansi_parser_state & ANSI_IN_ARG) {
ansi_parser_state &= ~ANSI_IN_ARG;
continue;
} else {
/* If ANSI_IN_ARG is not set, add another argument and default it
* to 0. */
/* Check for too many arguments */
if (handle->tty.wr.ansi_csi_argc >= ARRAY_SIZE(handle->tty.wr.ansi_csi_argv)) {
ansi_parser_state |= ANSI_IGNORE;
continue;
}
handle->tty.wr.ansi_csi_argc++;
handle->tty.wr.ansi_csi_argv[handle->tty.wr.ansi_csi_argc - 1] = 0;
continue;
}
} else if (utf8_codepoint == '?' && !(ansi_parser_state & ANSI_IN_ARG) &&
handle->tty.wr.ansi_csi_argc == 0) {
/* Ignores '?' if it is the first character after CSI[. This is an
* extension character from the VT100 codeset that is supported and
* used by most ANSI terminals today. */
continue;
} else if (utf8_codepoint >= '@' && utf8_codepoint <= '~' &&
(handle->tty.wr.ansi_csi_argc > 0 || utf8_codepoint != '[')) {
int x, y, d;
/* Command byte */
switch (utf8_codepoint) {
case 'A':
/* cursor up */
FLUSH_TEXT();
y = -(handle->tty.wr.ansi_csi_argc ? handle->tty.wr.ansi_csi_argv[0] : 1);
uv_tty_move_caret(handle, 0, 1, y, 1, error);
break;
case 'B':
/* cursor down */
FLUSH_TEXT();
libuv/src/win/tty.c view on Meta::CPAN
continue;
} else {
/* We don't support commands that use private mode characters or
* intermediaries. Ignore the rest of the sequence. */
ansi_parser_state |= ANSI_IGNORE;
continue;
}
} else {
/* We're ignoring this command. Stop only on command character. */
if (utf8_codepoint >= '@' && utf8_codepoint <= '~') {
ansi_parser_state = ANSI_NORMAL;
}
continue;
}
} else if (ansi_parser_state & ANSI_ST_CONTROL) {
/* Unsupported control code.
* Ignore everything until we see `BEL` or `ESC \`. */
if (ansi_parser_state & ANSI_IN_STRING) {
if (!(ansi_parser_state & ANSI_BACKSLASH_SEEN)) {
if (utf8_codepoint == '"') {
ansi_parser_state &= ~ANSI_IN_STRING;
} else if (utf8_codepoint == '\\') {
ansi_parser_state |= ANSI_BACKSLASH_SEEN;
}
} else {
ansi_parser_state &= ~ANSI_BACKSLASH_SEEN;
}
} else {
if (utf8_codepoint == '\007' || (utf8_codepoint == '\\' &&
(ansi_parser_state & ANSI_ESCAPE_SEEN))) {
/* End of sequence */
ansi_parser_state = ANSI_NORMAL;
} else if (utf8_codepoint == '\033') {
/* Escape character */
ansi_parser_state |= ANSI_ESCAPE_SEEN;
} else if (utf8_codepoint == '"') {
/* String starting */
ansi_parser_state |= ANSI_IN_STRING;
ansi_parser_state &= ~ANSI_ESCAPE_SEEN;
ansi_parser_state &= ~ANSI_BACKSLASH_SEEN;
} else {
ansi_parser_state &= ~ANSI_ESCAPE_SEEN;
}
}
continue;
} else {
/* Inconsistent state */
abort();
}
/* We wouldn't mind emitting utf-16 surrogate pairs. Too bad, the windows
* console doesn't really support UTF-16, so just emit the replacement
* character. */
if (utf8_codepoint > 0xffff) {
utf8_codepoint = UNICODE_REPLACEMENT_CHARACTER;
}
if (utf8_codepoint == 0x0a || utf8_codepoint == 0x0d) {
/* EOL conversion - emit \r\n when we see \n. */
if (utf8_codepoint == 0x0a && previous_eol != 0x0d) {
/* \n was not preceded by \r; print \r\n. */
ENSURE_BUFFER_SPACE(2);
utf16_buf[utf16_buf_used++] = L'\r';
utf16_buf[utf16_buf_used++] = L'\n';
} else if (utf8_codepoint == 0x0d && previous_eol == 0x0a) {
/* \n was followed by \r; do not print the \r, since the source was
* either \r\n\r (so the second \r is redundant) or was \n\r (so the
* \n was processed by the last case and an \r automatically
* inserted). */
} else {
/* \r without \n; print \r as-is. */
ENSURE_BUFFER_SPACE(1);
utf16_buf[utf16_buf_used++] = (WCHAR) utf8_codepoint;
}
previous_eol = (char) utf8_codepoint;
} else if (utf8_codepoint <= 0xffff) {
/* Encode character into utf-16 buffer. */
ENSURE_BUFFER_SPACE(1);
utf16_buf[utf16_buf_used++] = (WCHAR) utf8_codepoint;
previous_eol = 0;
}
}
}
/* Flush remaining characters */
FLUSH_TEXT();
/* Copy cached values back to struct. */
handle->tty.wr.utf8_bytes_left = utf8_bytes_left;
handle->tty.wr.utf8_codepoint = utf8_codepoint;
handle->tty.wr.previous_eol = previous_eol;
handle->tty.wr.ansi_parser_state = ansi_parser_state;
uv_sem_post(&uv_tty_output_lock);
if (*error == STATUS_SUCCESS) {
return 0;
} else {
return -1;
}
libuv/src/win/util.c view on Meta::CPAN
*/
if (QueryPerformanceFrequency(&perf_frequency)) {
hrtime_interval_ = 1.0 / perf_frequency.QuadPart;
} else {
hrtime_interval_= 0;
}
}
int uv_exepath(char* buffer, size_t* size_ptr) {
int utf8_len, utf16_buffer_len, utf16_len;
WCHAR* utf16_buffer;
int err;
if (buffer == NULL || size_ptr == NULL || *size_ptr == 0) {
return UV_EINVAL;
}
if (*size_ptr > 32768) {
/* Windows paths can never be longer than this. */
utf16_buffer_len = 32768;
libuv/src/win/util.c view on Meta::CPAN
utf16_len = GetModuleFileNameW(NULL, utf16_buffer, utf16_buffer_len);
if (utf16_len <= 0) {
err = GetLastError();
goto error;
}
/* utf16_len contains the length, *not* including the terminating null. */
utf16_buffer[utf16_len] = L'\0';
/* Convert to UTF-8 */
utf8_len = WideCharToMultiByte(CP_UTF8,
0,
utf16_buffer,
-1,
buffer,
(int) *size_ptr,
NULL,
NULL);
if (utf8_len == 0) {
err = GetLastError();
goto error;
}
uv__free(utf16_buffer);
/* utf8_len *does* include the terminating null at this point, but the
* returned size shouldn't. */
*size_ptr = utf8_len - 1;
return 0;
error:
uv__free(utf16_buffer);
return uv_translate_sys_error(err);
}
int uv_cwd(char* buffer, size_t* size) {
DWORD utf16_len;
libuv/src/win/util.c view on Meta::CPAN
}
static int uv__get_process_title(void) {
WCHAR title_w[MAX_TITLE_LENGTH];
if (!GetConsoleTitleW(title_w, sizeof(title_w) / sizeof(WCHAR))) {
return -1;
}
if (uv__convert_utf16_to_utf8(title_w, -1, &process_title) != 0)
return -1;
return 0;
}
int uv_get_process_title(char* buffer, size_t size) {
size_t len;
if (buffer == NULL || size == 0)
libuv/src/win/util.c view on Meta::CPAN
cpu_info = &cpu_infos[i];
cpu_info->speed = cpu_speed;
cpu_info->cpu_times.user = sppi[i].UserTime.QuadPart / 10000;
cpu_info->cpu_times.sys = (sppi[i].KernelTime.QuadPart -
sppi[i].IdleTime.QuadPart) / 10000;
cpu_info->cpu_times.idle = sppi[i].IdleTime.QuadPart / 10000;
cpu_info->cpu_times.irq = sppi[i].InterruptTime.QuadPart / 10000;
cpu_info->cpu_times.nice = 0;
uv__convert_utf16_to_utf8(cpu_brand,
cpu_brand_size / sizeof(WCHAR),
&(cpu_info->model));
}
uv__free(sppi);
*cpu_count_ptr = cpu_count;
*cpu_infos_ptr = cpu_infos;
return 0;
libuv/src/win/util.c view on Meta::CPAN
}
/*
* Converts a UTF-16 string into a UTF-8 one. The resulting string is
* null-terminated.
*
* If utf16 is null terminated, utf16len can be set to -1, otherwise it must
* be specified.
*/
int uv__convert_utf16_to_utf8(const WCHAR* utf16, int utf16len, char** utf8) {
DWORD bufsize;
if (utf16 == NULL)
return UV_EINVAL;
/* Check how much space we need */
bufsize = WideCharToMultiByte(CP_UTF8,
0,
utf16,
utf16len,
libuv/src/win/util.c view on Meta::CPAN
0,
NULL,
NULL);
if (bufsize == 0)
return uv_translate_sys_error(GetLastError());
/* Allocate the destination buffer adding an extra byte for the terminating
* NULL. If utf16len is not -1 WideCharToMultiByte will not add it, so
* we do it ourselves always, just in case. */
*utf8 = uv__malloc(bufsize + 1);
if (*utf8 == NULL)
return UV_ENOMEM;
/* Convert to UTF-8 */
bufsize = WideCharToMultiByte(CP_UTF8,
0,
utf16,
utf16len,
*utf8,
bufsize,
NULL,
NULL);
if (bufsize == 0) {
uv__free(*utf8);
*utf8 = NULL;
return uv_translate_sys_error(GetLastError());
}
(*utf8)[bufsize] = '\0';
return 0;
}
/*
* Converts a UTF-8 string into a UTF-16 one. The resulting string is
* null-terminated.
*
* If utf8 is null terminated, utf8len can be set to -1, otherwise it must
* be specified.
*/
int uv__convert_utf8_to_utf16(const char* utf8, int utf8len, WCHAR** utf16) {
int bufsize;
if (utf8 == NULL)
return UV_EINVAL;
/* Check how much space we need */
bufsize = MultiByteToWideChar(CP_UTF8, 0, utf8, utf8len, NULL, 0);
if (bufsize == 0)
return uv_translate_sys_error(GetLastError());
/* Allocate the destination buffer adding an extra byte for the terminating
* NULL. If utf8len is not -1 MultiByteToWideChar will not add it, so
* we do it ourselves always, just in case. */
*utf16 = uv__malloc(sizeof(WCHAR) * (bufsize + 1));
if (*utf16 == NULL)
return UV_ENOMEM;
/* Convert to UTF-16 */
bufsize = MultiByteToWideChar(CP_UTF8, 0, utf8, utf8len, *utf16, bufsize);
if (bufsize == 0) {
uv__free(*utf16);
*utf16 = NULL;
return uv_translate_sys_error(GetLastError());
}
(*utf16)[bufsize] = '\0';
return 0;
}
libuv/src/win/util.c view on Meta::CPAN
r = GetLastError();
/* This should not be possible */
if (r == ERROR_INSUFFICIENT_BUFFER)
return UV_ENOMEM;
return uv_translate_sys_error(r);
}
pwd->homedir = NULL;
r = uv__convert_utf16_to_utf8(path, -1, &pwd->homedir);
if (r != 0)
return r;
pwd->username = NULL;
r = uv__convert_utf16_to_utf8(username, -1, &pwd->username);
if (r != 0) {
uv__free(pwd->homedir);
return r;
}
pwd->shell = NULL;
pwd->uid = -1;
pwd->gid = -1;
libuv/src/win/util.c view on Meta::CPAN
int uv_os_getenv(const char* name, char* buffer, size_t* size) {
wchar_t var[MAX_ENV_VAR_LENGTH];
wchar_t* name_w;
DWORD bufsize;
size_t len;
int r;
if (name == NULL || buffer == NULL || size == NULL || *size == 0)
return UV_EINVAL;
r = uv__convert_utf8_to_utf16(name, -1, &name_w);
if (r != 0)
return r;
len = GetEnvironmentVariableW(name_w, var, MAX_ENV_VAR_LENGTH);
uv__free(name_w);
assert(len < MAX_ENV_VAR_LENGTH); /* len does not include the null */
if (len == 0) {
r = GetLastError();
libuv/src/win/util.c view on Meta::CPAN
int uv_os_setenv(const char* name, const char* value) {
wchar_t* name_w;
wchar_t* value_w;
int r;
if (name == NULL || value == NULL)
return UV_EINVAL;
r = uv__convert_utf8_to_utf16(name, -1, &name_w);
if (r != 0)
return r;
r = uv__convert_utf8_to_utf16(value, -1, &value_w);
if (r != 0) {
uv__free(name_w);
return r;
}
r = SetEnvironmentVariableW(name_w, value_w);
uv__free(name_w);
uv__free(value_w);
libuv/src/win/util.c view on Meta::CPAN
}
int uv_os_unsetenv(const char* name) {
wchar_t* name_w;
int r;
if (name == NULL)
return UV_EINVAL;
r = uv__convert_utf8_to_utf16(name, -1, &name_w);
if (r != 0)
return r;
r = SetEnvironmentVariableW(name_w, NULL);
uv__free(name_w);
if (r == 0)
return uv_translate_sys_error(GetLastError());
libuv/test/test-idna.c view on Meta::CPAN
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "task.h"
#include "../src/idna.c"
#include <string.h>
TEST_IMPL(utf8_decode1) {
const char* p;
char b[32];
int i;
/* ASCII. */
p = b;
snprintf(b, sizeof(b), "%c\x7F", 0x00);
ASSERT(0 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 1);
ASSERT(127 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 2);
/* Two-byte sequences. */
p = b;
snprintf(b, sizeof(b), "\xC2\x80\xDF\xBF");
ASSERT(128 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 2);
ASSERT(0x7FF == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 4);
/* Three-byte sequences. */
p = b;
snprintf(b, sizeof(b), "\xE0\xA0\x80\xEF\xBF\xBF");
ASSERT(0x800 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 3);
ASSERT(0xFFFF == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 6);
/* Four-byte sequences. */
p = b;
snprintf(b, sizeof(b), "\xF0\x90\x80\x80\xF4\x8F\xBF\xBF");
ASSERT(0x10000 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 4);
ASSERT(0x10FFFF == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 8);
/* Four-byte sequences > U+10FFFF; disallowed. */
p = b;
snprintf(b, sizeof(b), "\xF4\x90\xC0\xC0\xF7\xBF\xBF\xBF");
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 4);
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 8);
/* Overlong; disallowed. */
p = b;
snprintf(b, sizeof(b), "\xC0\x80\xC1\x80");
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 2);
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 4);
/* Surrogate pairs; disallowed. */
p = b;
snprintf(b, sizeof(b), "\xED\xA0\x80\xED\xA3\xBF");
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 3);
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 6);
/* Simply illegal. */
p = b;
snprintf(b, sizeof(b), "\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
for (i = 1; i <= 8; i++) {
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + i);
}
return 0;
}
/* Doesn't work on z/OS because that platform uses EBCDIC, not ASCII. */
#ifndef __MVS__
#define F(input, err) \
libuv/test/test-list.h view on Meta::CPAN
TEST_DECLARE (fork_fs_events_child)
TEST_DECLARE (fork_fs_events_child_dir)
TEST_DECLARE (fork_fs_events_file_parent_child)
#endif
#ifndef __MVS__
TEST_DECLARE (fork_threadpool_queue_work_simple)
#endif
#endif
TEST_DECLARE (idna_toascii)
TEST_DECLARE (utf8_decode1)
TEST_DECLARE (uname)
TASK_LIST_START
TEST_ENTRY_CUSTOM (platform_output, 0, 1, 5000)
#if 0
TEST_ENTRY (callback_order)
#endif
TEST_ENTRY (close_order)
TEST_ENTRY (run_once)
libuv/test/test-list.h view on Meta::CPAN
#ifndef __APPLE__
TEST_ENTRY (fork_fs_events_child)
TEST_ENTRY (fork_fs_events_child_dir)
TEST_ENTRY (fork_fs_events_file_parent_child)
#endif
#ifndef __MVS__
TEST_ENTRY (fork_threadpool_queue_work_simple)
#endif
#endif
TEST_ENTRY (utf8_decode1)
TEST_ENTRY (uname)
/* Doesn't work on z/OS because that platform uses EBCDIC, not ASCII. */
#ifndef __MVS__
TEST_ENTRY (idna_toascii)
#endif
#if 0
/* These are for testing the test runner. */
TEST_ENTRY (fail_always)