22 #undef __STRICT_ANSI__ 56 #define isdirsep(x) ((x) == '/' || (x) == '\\') 58 #if defined _MSC_VER && _MSC_VER <= 1200 59 # define CharNextExA(cp, p, flags) CharNextExA((WORD)(cp), (p), (flags)) 62 static int w32_wopen(
const WCHAR *file,
int oflag,
int perm);
63 static int w32_stati64(
const char *path,
struct stati64 *st, UINT cp);
64 static int w32_lstati64(
const char *path,
struct stati64 *st, UINT cp);
68 #define DLN_FIND_EXTRA_ARG_DECL ,UINT cp 69 #define DLN_FIND_EXTRA_ARG ,cp 70 #define rb_w32_stati64(path, st) w32_stati64(path, st, cp) 71 #define getenv(name) w32_getenv(name, cp) 73 #define CharNext(p) CharNextExA(cp, (p), 0) 74 #define dln_find_exe_r rb_w32_udln_find_exe_r 75 #define dln_find_file_r rb_w32_udln_find_file_r 81 #undef dln_find_file_r 82 #define dln_find_exe_r(fname, path, buf, size) rb_w32_udln_find_exe_r(fname, path, buf, size, cp) 83 #define dln_find_file_r(fname, path, buf, size) rb_w32_udln_find_file_r(fname, path, buf, size, cp) 88 # define PATH_MAX MAX_PATH 89 # elif defined HAVE_SYS_PARAM_H 90 # include <sys/param.h> 91 # define PATH_MAX MAXPATHLEN 103 #if RUBY_MSVCRT_VERSION >= 140 104 # define _filbuf _fgetc_nolock 105 # define _flsbuf _fputc_nolock 107 #define enough_to_get(n) (--(n) >= 0) 108 #define enough_to_put(n) (--(n) >= 0) 111 #define Debug(something) something 113 #define Debug(something) 116 #define TO_SOCKET(x) _get_osfhandle(x) 124 static int wstati64(
const WCHAR *path,
struct stati64 *st);
125 static int wlstati64(
const WCHAR *path,
struct stati64 *st);
130 #define RUBY_CRITICAL if (0) {} else 137 { ERROR_INVALID_FUNCTION, EINVAL },
138 { ERROR_FILE_NOT_FOUND, ENOENT },
139 { ERROR_PATH_NOT_FOUND, ENOENT },
140 { ERROR_TOO_MANY_OPEN_FILES, EMFILE },
141 { ERROR_ACCESS_DENIED, EACCES },
142 { ERROR_INVALID_HANDLE, EBADF },
143 { ERROR_ARENA_TRASHED, ENOMEM },
144 { ERROR_NOT_ENOUGH_MEMORY, ENOMEM },
145 { ERROR_INVALID_BLOCK, ENOMEM },
146 { ERROR_BAD_ENVIRONMENT, E2BIG },
147 { ERROR_BAD_FORMAT, ENOEXEC },
148 { ERROR_INVALID_ACCESS, EINVAL },
149 { ERROR_INVALID_DATA, EINVAL },
150 { ERROR_INVALID_DRIVE, ENOENT },
151 { ERROR_CURRENT_DIRECTORY, EACCES },
152 { ERROR_NOT_SAME_DEVICE, EXDEV },
153 { ERROR_NO_MORE_FILES, ENOENT },
154 { ERROR_WRITE_PROTECT, EROFS },
155 { ERROR_BAD_UNIT, ENODEV },
156 { ERROR_NOT_READY, ENXIO },
157 { ERROR_BAD_COMMAND, EACCES },
158 { ERROR_CRC, EACCES },
159 { ERROR_BAD_LENGTH, EACCES },
161 { ERROR_NOT_DOS_DISK, EACCES },
162 { ERROR_SECTOR_NOT_FOUND, EACCES },
163 { ERROR_OUT_OF_PAPER, EACCES },
164 { ERROR_WRITE_FAULT, EIO },
165 { ERROR_READ_FAULT, EIO },
166 { ERROR_GEN_FAILURE, EACCES },
167 { ERROR_LOCK_VIOLATION, EACCES },
168 { ERROR_SHARING_VIOLATION, EACCES },
169 { ERROR_WRONG_DISK, EACCES },
170 { ERROR_SHARING_BUFFER_EXCEEDED, EACCES },
171 { ERROR_BAD_NETPATH, ENOENT },
172 { ERROR_NETWORK_ACCESS_DENIED, EACCES },
173 { ERROR_BAD_NET_NAME, ENOENT },
174 { ERROR_FILE_EXISTS, EEXIST },
175 { ERROR_CANNOT_MAKE, EACCES },
176 { ERROR_FAIL_I24, EACCES },
177 { ERROR_INVALID_PARAMETER, EINVAL },
178 { ERROR_NO_PROC_SLOTS, EAGAIN },
179 { ERROR_DRIVE_LOCKED, EACCES },
180 { ERROR_BROKEN_PIPE, EPIPE },
181 { ERROR_DISK_FULL, ENOSPC },
182 { ERROR_INVALID_TARGET_HANDLE, EBADF },
183 { ERROR_INVALID_HANDLE, EINVAL },
184 { ERROR_WAIT_NO_CHILDREN, ECHILD },
185 { ERROR_CHILD_NOT_COMPLETE, ECHILD },
186 { ERROR_DIRECT_ACCESS_HANDLE, EBADF },
187 { ERROR_NEGATIVE_SEEK, EINVAL },
188 { ERROR_SEEK_ON_DEVICE, EACCES },
189 { ERROR_DIR_NOT_EMPTY, ENOTEMPTY },
190 { ERROR_DIRECTORY, ENOTDIR },
191 { ERROR_NOT_LOCKED, EACCES },
192 { ERROR_BAD_PATHNAME, ENOENT },
193 { ERROR_MAX_THRDS_REACHED, EAGAIN },
194 { ERROR_LOCK_FAILED, EACCES },
195 { ERROR_ALREADY_EXISTS, EEXIST },
196 { ERROR_INVALID_STARTING_CODESEG, ENOEXEC },
197 { ERROR_INVALID_STACKSEG, ENOEXEC },
198 { ERROR_INVALID_MODULETYPE, ENOEXEC },
199 { ERROR_INVALID_EXE_SIGNATURE, ENOEXEC },
200 { ERROR_EXE_MARKED_INVALID, ENOEXEC },
201 { ERROR_BAD_EXE_FORMAT, ENOEXEC },
202 { ERROR_ITERATED_DATA_EXCEEDS_64k,ENOEXEC },
203 { ERROR_INVALID_MINALLOCSIZE, ENOEXEC },
204 { ERROR_DYNLINK_FROM_INVALID_RING,ENOEXEC },
205 { ERROR_IOPL_NOT_ENABLED, ENOEXEC },
206 { ERROR_INVALID_SEGDPL, ENOEXEC },
207 { ERROR_AUTODATASEG_EXCEEDS_64k, ENOEXEC },
208 { ERROR_RING2SEG_MUST_BE_MOVABLE, ENOEXEC },
209 { ERROR_RELOC_CHAIN_XEEDS_SEGLIM, ENOEXEC },
210 { ERROR_INFLOOP_IN_RELOC_CHAIN, ENOEXEC },
211 { ERROR_FILENAME_EXCED_RANGE, ENOENT },
212 { ERROR_NESTING_NOT_ALLOWED, EAGAIN },
213 #ifndef ERROR_PIPE_LOCAL 214 #define ERROR_PIPE_LOCAL 229L 217 { ERROR_BAD_PIPE, EPIPE },
218 { ERROR_PIPE_BUSY, EAGAIN },
219 { ERROR_NO_DATA, EPIPE },
220 { ERROR_PIPE_NOT_CONNECTED, EPIPE },
221 { ERROR_OPERATION_ABORTED, EINTR },
222 { ERROR_NOT_ENOUGH_QUOTA, ENOMEM },
223 { ERROR_MOD_NOT_FOUND, ENOENT },
224 { ERROR_PRIVILEGE_NOT_HELD, EACCES, },
225 { ERROR_CANT_RESOLVE_FILENAME,
ELOOP, },
228 { WSAEACCES, EACCES },
229 { WSAEFAULT, EFAULT },
230 { WSAEINVAL, EINVAL },
231 { WSAEMFILE, EMFILE },
260 { WSAENAMETOOLONG, ENAMETOOLONG },
264 { WSAENOTEMPTY, ENOTEMPTY },
281 for (i = 0; i < (int)(
sizeof(
errmap) /
sizeof(*
errmap)); i++) {
282 if (
errmap[i].winerr == winerr) {
287 if (winerr >= WSABASEERR) {
293 #define map_errno rb_w32_map_errno 303 memset(&
osver, 0,
sizeof(OSVERSIONINFO));
304 osver.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
305 GetVersionEx(&
osver);
313 return osver.dwPlatformId;
321 return osver.dwMajorVersion;
327 #define LK_ERR(f,i) \ 332 DWORD err = GetLastError(); \ 333 if (err == ERROR_LOCK_VIOLATION || err == ERROR_IO_PENDING) \ 334 errno = EWOULDBLOCK; \ 335 else if (err == ERROR_NOT_LOCKED) \ 338 errno = map_errno(err); \ 341 #define LK_LEN ULONG_MAX 349 const HANDLE fh = (HANDLE)
self;
350 const int oper =
argc;
352 memset(&o, 0,
sizeof(o));
366 LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY,
394 static inline WCHAR *
409 if ((
unsigned char)*p == from)
411 p = CharNextExA(cp, p, 0);
416 #ifndef CSIDL_LOCAL_APPDATA 417 #define CSIDL_LOCAL_APPDATA 28 419 #ifndef CSIDL_COMMON_APPDATA 420 #define CSIDL_COMMON_APPDATA 35 422 #ifndef CSIDL_WINDOWS 423 #define CSIDL_WINDOWS 36 426 #define CSIDL_SYSTEM 37 428 #ifndef CSIDL_PROFILE 429 #define CSIDL_PROFILE 40 439 typedef BOOL (WINAPI *get_path_func)(LPITEMIDLIST, WCHAR*,
DWORD, int);
440 static get_path_func
func = (get_path_func)-1;
442 if (func == (get_path_func)-1) {
443 func = (get_path_func)
446 if (!func && len < MAX_PATH)
return FALSE;
448 if (SHGetSpecialFolderLocation(
NULL, n, &pidl) == 0) {
450 f =
func(pidl, buf, len, 0);
453 f = SHGetPathFromIDListW(pidl, buf);
456 alloc->lpVtbl->Free(alloc, pidl);
457 alloc->lpVtbl->Release(alloc);
467 if (p - path == 2 && path[1] ==
L':') {
481 h = LoadLibrary(module);
483 h = GetModuleHandle(module);
487 ptr = GetProcAddress(h, func);
508 #if defined _MSC_VER && _MSC_VER <= 1200 510 #define GetSystemWindowsDirectoryW GetWindowsDirectoryW 517 static const WCHAR temp[] =
L"temp";
521 if (GetSystemWindowsDirectoryW(path, len))
return 0;
524 if (*(p - 1) !=
L'/') *p++ =
L'/';
525 if ((UINT)(p - path +
numberof(temp)) >= len)
return 0;
526 memcpy(p, temp,
sizeof(temp));
527 return (UINT)(p - path +
numberof(temp) - 1);
542 WCHAR *buffer =
NULL;
543 size_t buffer_len = MAX_PATH,
len = 0;
545 HOME_NONE, ENV_HOME, ENV_DRIVEPATH, ENV_USERPROFILE
546 } home_type = HOME_NONE;
548 if ((len = GetEnvironmentVariableW(
L"HOME",
NULL, 0)) != 0) {
550 home_type = ENV_HOME;
552 else if ((len = GetEnvironmentVariableW(
L"HOMEDRIVE",
NULL, 0)) != 0) {
554 if ((len = GetEnvironmentVariableW(
L"HOMEPATH",
NULL, 0)) != 0) {
556 home_type = ENV_DRIVEPATH;
559 else if ((len = GetEnvironmentVariableW(
L"USERPROFILE",
NULL, 0)) != 0) {
561 home_type = ENV_USERPROFILE;
565 buffer =
ALLOC_N(WCHAR, buffer_len);
569 GetEnvironmentVariableW(
L"HOME", buffer, buffer_len);
572 len = GetEnvironmentVariableW(
L"HOMEDRIVE", buffer, buffer_len);
573 GetEnvironmentVariableW(
L"HOMEPATH", buffer + len, buffer_len - len);
575 case ENV_USERPROFILE:
576 GetEnvironmentVariableW(
L"USERPROFILE", buffer, buffer_len);
584 REALLOC_N(buffer, WCHAR, lstrlenW(buffer) + 1);
598 static const WCHAR TMPDIR[] =
L"TMPDIR";
603 #define set_env_val(vname) do { \ 604 typedef char wk_name_offset[(numberof(wk.name) - (numberof(vname) - 1)) * 2 + 1]; \ 605 WCHAR *const buf = wk.name + sizeof(wk_name_offset) / 2; \ 606 MEMCPY(buf, vname, WCHAR, numberof(vname) - 1); \ 618 if (GetEnvironmentVariableW(
L"HOMEPATH",
env + len,
numberof(
env) - len) || len) {
621 else if (GetEnvironmentVariableW(
L"USERPROFILE",
env,
numberof(
env))) {
663 #if RUBY_MSVCRT_VERSION >= 80 666 invalid_parameter(
const wchar_t *expr,
const wchar_t *
func,
const wchar_t *file,
unsigned int line,
uintptr_t dummy)
671 int ruby_w32_rtc_error;
675 rtc_error_handler(
int e,
const char *src,
int line,
const char *exe,
const char *fmt, ...)
680 if (!ruby_w32_rtc_error)
return 0;
695 #define conlist_disabled ((st_table *)-1) 762 version = MAKEWORD(2, 0);
763 if (WSAStartup(version, &retdata))
764 rb_fatal(
"Unable to locate winsock library!");
765 if (LOBYTE(retdata.wVersion) != 2)
766 rb_fatal(
"could not find version 2 of winsock dll");
773 #define MAKE_SOCKDATA(af, fl) ((int)((((int)af)<<4)|((fl)&0xFFFF))) 774 #define GET_FAMILY(v) ((int)(((v)>>4)&0xFFFF)) 775 #define GET_FLAGS(v) ((int)((v)&0xFFFF)) 817 *sockp = (SOCKET)key;
833 #if RUBY_MSVCRT_VERSION >= 80 834 static void set_pioinfo_extra(
void);
836 _CrtSetReportMode(_CRT_ASSERT, 0);
837 _set_invalid_parameter_handler(invalid_parameter);
838 _RTC_SetErrorFunc(rtc_error_handler);
841 SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOGPFAULTERRORBOX);
872 #define MAXCHILDNUM 256 881 #define FOREACH_CHILD(v) do { \ 882 struct ChildRecord* v; \ 883 for (v = ChildRecord; v < ChildRecord + sizeof(ChildRecord) / sizeof(ChildRecord[0]); ++v) 884 #define END_FOREACH_CHILD } while (0) 892 if (child->pid == pid) {
905 if (child->hProcess == h) {
929 child->hProcess =
NULL;
943 #define InternalCmdsMax 8 1007 int i =
strlen(interp) - 11;
1009 if ((i == 0 || (i > 0 &&
isdirsep(interp[i-1]))) &&
1022 char cmdname[9], *b = cmdname, c;
1025 if (!(c = *cmd++))
return 0;
1026 }
while (isspace(c));
1029 while (isalpha(c)) {
1031 if (b == cmdname +
sizeof(cmdname))
return 0;
1034 if (c ==
'.') c = *cmd;
1036 case '<':
case '>':
case '|':
1038 case '\0':
case ' ':
case '\t':
case '\n':
1057 if (!nm || !(nm[0] & (nt ? 2 : 1)))
1066 return _get_osfhandle(fh);
1075 int len, n, bs, quote;
1077 for (t = argv, q = cmd, len = 0; (p = *t) != 0; t++) {
1080 if (!*p || strpbrk(p,
" \t\"'")) {
1085 for (bs = 0; *p; ++p) {
1099 memset(q,
'\\', bs);
1104 case '<':
case '>':
case '|':
case '^':
1105 if (escape && !quote) {
1106 len += (n = p - s) + 1;
1117 p = CharNextExA(cp, p, 0) - 1;
1121 len += (n = p - s) + 1;
1125 if (backslash > 0) {
1131 if (quote) *q++ =
'"';
1144 #define STRNDUPV(ptr, v, src, len) \ 1145 (((char *)memcpy(((ptr) = ALLOCV((v), (len) + 1)), (src), (len)))[len] = 0) 1171 if (mode == P_OVERLAY) {
1172 WaitForSingleObject(child->
hProcess, INFINITE);
1173 GetExitCodeProcess(child->
hProcess, &exitcode);
1182 CreateChild(
const WCHAR *cmd,
const WCHAR *prog, SECURITY_ATTRIBUTES *psa,
1183 HANDLE hInput, HANDLE hOutput, HANDLE hError,
DWORD dwCreationFlags)
1186 STARTUPINFOW aStartupInfo;
1187 PROCESS_INFORMATION aProcessInformation;
1188 SECURITY_ATTRIBUTES sa;
1191 if (!cmd && !prog) {
1203 sa.nLength =
sizeof (SECURITY_ATTRIBUTES);
1204 sa.lpSecurityDescriptor =
NULL;
1205 sa.bInheritHandle =
TRUE;
1209 memset(&aStartupInfo, 0,
sizeof(aStartupInfo));
1210 memset(&aProcessInformation, 0,
sizeof(aProcessInformation));
1211 aStartupInfo.cb =
sizeof(aStartupInfo);
1212 aStartupInfo.dwFlags = STARTF_USESTDHANDLES;
1214 aStartupInfo.hStdInput = hInput;
1217 aStartupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
1220 aStartupInfo.hStdOutput = hOutput;
1223 aStartupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
1226 aStartupInfo.hStdError = hError;
1229 aStartupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
1232 dwCreationFlags |= NORMAL_PRIORITY_CLASS;
1234 if (lstrlenW(cmd) > 32767) {
1241 fRet = CreateProcessW(prog, (WCHAR *)cmd, psa, psa,
1242 psa->bInheritHandle, dwCreationFlags,
NULL,
NULL,
1243 &aStartupInfo, &aProcessInformation);
1252 CloseHandle(aProcessInformation.hThread);
1254 child->
hProcess = aProcessInformation.hProcess;
1255 child->
pid = (rb_pid_t)aProcessInformation.dwProcessId;
1265 if (len <= 4)
return 0;
1267 if (*cmd++ !=
'.')
return 0;
1273 #define filecp rb_w32_filecp 1274 #define mbstr_to_wstr rb_w32_mbstr_to_wstr 1275 #define wstr_to_mbstr rb_w32_wstr_to_mbstr 1276 #define acp_to_wstr(str, plen) mbstr_to_wstr(CP_ACP, str, -1, plen) 1277 #define wstr_to_acp(str, plen) wstr_to_mbstr(CP_ACP, str, -1, plen) 1278 #define filecp_to_wstr(str, plen) mbstr_to_wstr(filecp(), str, -1, plen) 1279 #define wstr_to_filecp(str, plen) wstr_to_mbstr(filecp(), str, -1, plen) 1280 #define utf8_to_wstr(str, plen) mbstr_to_wstr(CP_UTF8, str, -1, plen) 1281 #define wstr_to_utf8(str, plen) wstr_to_mbstr(CP_UTF8, str, -1, plen) 1285 w32_spawn(
int mode,
const char *cmd,
const char *prog, UINT cp)
1289 const char *shell =
NULL;
1290 WCHAR *wcmd =
NULL, *wshell =
NULL;
1296 char *cmd_sep =
NULL;
1314 size_t shell_len =
strlen(shell);
1315 char *tmp =
ALLOCV(v, shell_len +
strlen(cmd) +
sizeof(
" -c ") + 2);
1316 memcpy(tmp, shell, shell_len + 1);
1318 sprintf(tmp + shell_len,
" -c \"%s\"", cmd);
1321 else if ((shell =
getenv(
"COMSPEC")) &&
1326 sprintf(tmp, nt ?
"%s /c \"%s\"" :
"%s /c %s", shell, cmd);
1330 int len = 0, quote = (*cmd ==
'"') ?
'"' : (*cmd ==
'\'') ?
'\'' : 0;
1332 for (prog = cmd + !!quote;; prog = CharNextExA(cp, prog, 0)) {
1333 if (*prog ==
'/') slash = 1;
1343 if ((
unsigned char)*prog == quote) {
1344 len = prog++ - cmd - 1;
1349 if (quote)
continue;
1355 sep = *(cmd_sep = &p[
len]);
1365 shell = p ? p : cmd;
1369 if (
strchr(shell,
' ')) quote = -1;
1370 if (shell == fbuf) {
1373 else if (shell != p &&
strchr(shell,
'/')) {
1380 cmd = p =
ALLOCV(v, len + alen + (quote ? 2 : 0) + 1);
1381 if (quote) *p++ =
'"';
1384 if (quote) *p++ =
'"';
1385 memcpy(p, prog, alen + 1);
1393 if (cmd_sep) *cmd_sep = sep;
1419 return w32_spawn(mode, cmd, prog, CP_UTF8);
1428 BOOL ntcmd =
FALSE, tmpnt;
1438 if (!prog) prog = argv[0];
1439 if ((shell =
getenv(
"COMSPEC")) &&
1446 if (cmd == prog)
strlcpy(cmd = fbuf, prog,
sizeof(fbuf));
1450 else if (
strchr(prog,
'/')) {
1452 if (len <
sizeof(fbuf))
1453 strlcpy(cmd = fbuf, prog,
sizeof(fbuf));
1461 progs[0] = (
char *)prog;
1464 if (c_switch) len += 3;
1469 if (c_switch)
strlcat(cmd,
" /c", len);
1471 prog = c_switch ? shell : 0;
1533 #define NTGLOB 0x1 // element contains a wildcard 1534 #define NTMALLOC 0x2 // string in element was malloc'ed 1535 #define NTSTRING 0x4 // element contains a quoted string 1545 if (!tmpcurr)
return -1;
1549 if (!tmpcurr->
str)
return -1;
1552 *tail = &tmpcurr->
next;
1566 if (!(buf =
malloc(patt->
len + 1)))
return 0;
1569 buf[patt->
len] =
'\0';
1575 if (status || last == tail)
return 0;
1599 for (ptr = cmd; *ptr;) {
1605 else if (quote == *ptr)
1621 if (*++ptr !=
'_' && !
ISALPHA(*ptr))
break;
1622 while (*++ptr ==
'_' ||
ISALNUM(*ptr));
1623 if (*ptr++ ==
'%')
return TRUE;
1629 ptr = CharNextExA(cp, ptr, 0);
1637 static inline WCHAR *
1640 while (iswspace(*ptr))
1650 int elements, strsz, done;
1651 int slashes, escape;
1652 WCHAR *ptr, *base, *cmdline;
1653 char *cptr, *buffer;
1662 while (iswspace(*cmd))
1669 ptr = cmdline = wcsdup(cmd);
1682 quote = slashes = globbing = escape = 0;
1683 for (done = 0; !done && *ptr; ) {
1692 if (quote !=
L'\'') slashes++;
1732 if (!(slashes & 1)) {
1735 else if (quote == *ptr) {
1736 if (quote ==
L'"' && quote == ptr[1])
1746 ptr = CharNextW(ptr);
1769 slashes = quote = 0;
1770 while (p < base + len) {
1774 if (quote !=
L'\'') slashes++;
1779 if (!(slashes & 1) && quote && quote != c) {
1784 memcpy(p - ((slashes + 1) >> 1), p + (~slashes & 1),
1785 sizeof(WCHAR) * (base + len - p));
1786 len -= ((slashes + 1) >> 1) + (~slashes & 1);
1787 p -= (slashes + 1) >> 1;
1788 if (!(slashes & 1)) {
1790 if (quote ==
L'"' && quote == *p)
1811 if (!curr)
goto do_nothing;
1815 if (globbing && (tail =
cmdglob(curr, cmdtail, cp, enc))) {
1820 cmdtail = &curr->
next;
1830 for (elements = 0, strsz = 0, curr = cmdhead; curr; curr = curr->
next) {
1832 strsz += (curr->
len + 1);
1835 len = (elements+1)*
sizeof(
char *) + strsz;
1836 buffer = (
char *)
malloc(len);
1839 while ((curr = cmdhead) != 0) {
1840 cmdhead = curr->
next;
1845 for (vptr = *vec; *vptr; ++vptr);
1861 vptr = (
char **) buffer;
1863 cptr = buffer + (elements+1) *
sizeof(
char *);
1865 while ((curr = cmdhead) != 0) {
1868 cptr += curr->
len + 1;
1869 cmdhead = curr->
next;
1875 *vec = (
char **) buffer;
1900 return func(f, buf, len, flag);
1910 const DWORD share_mode =
1911 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
1912 return CreateFileW(path, access, share_mode,
NULL, OPEN_EXISTING,
1913 FILE_FLAG_BACKUP_SEMANTICS|flags,
NULL);
1923 #define GetBit(bits, i) ((bits)[(i) / CHAR_BIT] & (1 << (i) % CHAR_BIT)) 1924 #define SetBit(bits, i) ((bits)[(i) / CHAR_BIT] |= (1 << (i) % CHAR_BIT)) 1926 #define BitOfIsDir(n) ((n) * 2) 1927 #define BitOfIsRep(n) ((n) * 2 + 1) 1928 #define DIRENT_PER_CHAR (CHAR_BIT / 2) 1944 if (fh != INVALID_HANDLE_VALUE) {
1949 len = lstrlenW(filename);
1951 errno = ENAMETOOLONG;
1952 return INVALID_HANDLE_VALUE;
1954 MEMCPY(fullname, filename, WCHAR, len);
1956 p = &fullname[len-1];
1957 if (!(
isdirsep(*p) || *p ==
L':')) *++p =
L'\\';
1964 fh = FindFirstFileW(fullname, fd);
1965 if (fh == INVALID_HANDLE_VALUE) {
1975 struct stati64 sbuf;
1976 WIN32_FIND_DATAW fd;
1992 if (!(sbuf.st_mode & S_IFDIR) &&
1993 (!
ISALPHA(wpath[0]) || wpath[1] !=
L':' || wpath[2] !=
L'\0' ||
1994 ((1 << ((wpath[0] & 0x5f) -
'A')) & GetLogicalDrives()) == 0)) {
1999 if (fh == INVALID_HANDLE_VALUE) {
2010 pathlen = lstrlenW(wpath);
2020 len = lstrlenW(fd.cFileName) + 1;
2021 altlen = lstrlenW(fd.cAlternateFileName) + 1;
2027 tmpW =
realloc(p->
start, (idx + len + altlen) *
sizeof(WCHAR));
2037 memcpy(&p->
start[idx], fd.cFileName, len *
sizeof(WCHAR));
2038 memcpy(&p->
start[idx + len], fd.cAlternateFileName, altlen *
sizeof(WCHAR));
2047 if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
2049 if (fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
2050 WCHAR *tmppath =
malloc((pathlen + len + 1) *
sizeof(WCHAR));
2051 memcpy(tmppath, wpath, pathlen *
sizeof(WCHAR));
2052 tmppath[pathlen] =
L'\\';
2053 memcpy(tmppath + pathlen + 1, fd.cFileName, len *
sizeof(WCHAR));
2060 idx += len + altlen;
2061 }
while (FindNextFileW(fh, &fd));
2072 UINT cp = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
2081 int len = WideCharToMultiByte(cp, 0, wstr, clen,
NULL, 0,
NULL,
NULL);
2082 if (!(ptr =
malloc(len)))
return 0;
2083 WideCharToMultiByte(cp, 0, wstr, clen, ptr, len,
NULL,
NULL);
2086 if (clen == -1) --
len;
2097 int len = MultiByteToWideChar(cp, 0, str, clen,
NULL, 0);
2098 if (!(ptr =
malloc(
sizeof(WCHAR) * len)))
return 0;
2099 MultiByteToWideChar(cp, 0, str, clen, ptr, len);
2102 if (clen == -1) --
len;
2144 dirp->
curr += lstrlenW(dirp->
curr) + 1;
2145 dirp->
curr += lstrlenW(dirp->
curr) + 1;
2160 UINT cp = *((UINT *)enc);
2176 long len = lstrlenW(wstr);
2183 #if SIZEOF_INT < SIZEOF_LONG 2184 # error long should equal to int on Windows 2187 len = WideCharToMultiByte(CP_UTF8, 0, wstr, clen,
NULL, 0,
NULL,
NULL);
2235 static int dummy = 0;
2285 const UINT cp =
filecp();
2289 const UINT cp = CP_UTF8;
2317 while (dirp->
curr && dirp->
loc < loc) {
2355 #if RUBY_MSVCRT_VERSION >= 140 2370 CRITICAL_SECTION _lock;
2372 #define FILE_COUNT(stream) ((vcruntime_file*)stream)->_cnt 2373 #define FILE_READPTR(stream) ((vcruntime_file*)stream)->_ptr 2374 #define FILE_FILENO(stream) ((vcruntime_file*)stream)->_file 2376 #define FILE_COUNT(stream) stream->_cnt 2377 #define FILE_READPTR(stream) stream->_ptr 2378 #define FILE_FILENO(stream) stream->_file 2382 #if RUBY_MSVCRT_VERSION >= 140 2383 typedef char lowio_text_mode;
2384 typedef char lowio_pipe_lookahead[3];
2387 CRITICAL_SECTION lock;
2390 unsigned char osfile;
2391 lowio_text_mode textmode;
2392 lowio_pipe_lookahead _pipe_lookahead;
2406 #if RUBY_MSVCRT_VERSION >= 80 2413 #if !defined _CRTIMP || defined __MINGW32__ 2415 #define _CRTIMP __declspec(dllimport) 2418 #if RUBY_MSVCRT_VERSION >= 140 2420 #define IOINFO_L2E 6 2423 #define IOINFO_L2E 5 2427 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E) 2428 #define _osfhnd(i) (_pioinfo(i)->osfhnd) 2429 #define _osfile(i) (_pioinfo(i)->osfile) 2430 #define rb_acrt_lowio_lock_fh(i) EnterCriticalSection(&_pioinfo(i)->lock) 2431 #define rb_acrt_lowio_unlock_fh(i) LeaveCriticalSection(&_pioinfo(i)->lock) 2433 #if RUBY_MSVCRT_VERSION >= 80 2438 set_pioinfo_extra(
void)
2440 #if RUBY_MSVCRT_VERSION >= 140 2441 # define FUNCTION_RET 0xc3 2443 # define UCRTBASE "ucrtbased.dll" 2445 # define UCRTBASE "ucrtbase.dll" 2456 # define FUNCTION_BEFORE_RET_MARK "\x48\x83\xc4" 2457 # define FUNCTION_SKIP_BYTES 1 2460 # define PIOINFO_MARK "\x48\x8d\x0d" 2463 # define PIOINFO_MARK "\x48\x8d\x15" 2468 # define FUNCTION_BEFORE_RET_MARK "\x5d" 2469 # define FUNCTION_SKIP_BYTES 0 2471 # define PIOINFO_MARK "\x8B\x04\x85" 2474 for (pend += 10; pend < p + 300; pend++) {
2476 if (
memcmp(pend, FUNCTION_BEFORE_RET_MARK,
sizeof(FUNCTION_BEFORE_RET_MARK) - 1) == 0 &&
2477 *(pend + (
sizeof(FUNCTION_BEFORE_RET_MARK) - 1) + FUNCTION_SKIP_BYTES) & FUNCTION_RET == FUNCTION_RET) {
2479 for (pend -= (
sizeof(PIOINFO_MARK) - 1); pend > p; pend--) {
2480 if (
memcmp(pend, PIOINFO_MARK,
sizeof(PIOINFO_MARK) - 1) == 0) {
2489 fprintf(stderr,
"unexpected " UCRTBASE
"\n");
2493 p +=
sizeof(PIOINFO_MARK) - 1;
2495 rel = *(int32_t*)(p);
2496 rip = p +
sizeof(int32_t);
2497 __pioinfo = (
ioinfo**)(rip + rel);
2499 __pioinfo = *(
ioinfo***)(p);
2504 fd = _open(
"NUL", O_RDONLY);
2505 for (pioinfo_extra = 0; pioinfo_extra <= 64; pioinfo_extra +=
sizeof(
void *)) {
2506 if (
_osfhnd(fd) == _get_osfhandle(fd)) {
2512 if (pioinfo_extra > 64) {
2519 #define pioinfo_extra 0 2525 const size_t sizeof_ioinfo =
sizeof(
ioinfo) + pioinfo_extra;
2530 #define _set_osfhnd(fh, osfh) (void)(_osfhnd(fh) = osfh) 2531 #define _set_osflags(fh, flags) (_osfile(fh) = (flags)) 2534 #define FEOFLAG 0x02 2536 #define FNOINHERIT 0x10 2537 #define FAPPEND 0x20 2562 if (flags & O_APPEND)
2568 if (flags & O_NOINHERIT)
2572 hF = CreateFile(
"NUL", 0, 0,
NULL, OPEN_ALWAYS, 0,
NULL);
2573 fh = _open_osfhandle((
intptr_t)hF, 0);
2599 #define open_null(fd) \ 2601 (nullfd = open("NUL", O_RDWR)) : 0), \ 2602 ((nullfd == (fd)) ? (keep = 1) : dup2(nullfd, fd)), \ 2611 if (
fileno(stdout) < 0) {
2614 if (
fileno(stderr) < 0) {
2617 if (nullfd >= 0 && !keep) close(nullfd);
2618 setvbuf(stderr,
NULL, _IONBF, 0);
2652 static char buffer[512];
2659 #if WSAEWOULDBLOCK != EWOULDBLOCK 2664 for (s = 0; s < (int)(
sizeof(
errmap)/
sizeof(*
errmap)); s++)
2667 for (i = s; i < (int)(
sizeof(
errmap)/
sizeof(*errmap)); i++)
2674 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
2675 FORMAT_MESSAGE_IGNORE_INSERTS, &source, e,
2676 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
2677 buffer,
sizeof(buffer),
NULL) == 0 &&
2678 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
2679 FORMAT_MESSAGE_IGNORE_INSERTS, &source, e, 0,
2680 buffer,
sizeof(buffer),
NULL) == 0)
2681 strlcpy(buffer,
"Unknown Error",
sizeof(buffer));
2687 while ((p = strpbrk(p,
"\r\n")) !=
NULL) {
2776 for (i = 0; i <
set->fd_count; i++) {
2777 if (set->fd_array[i] == s) {
2778 memmove(&set->fd_array[i], &set->fd_array[i+1],
2779 sizeof(set->fd_array[0]) * (--set->fd_count - i));
2793 if (s == (SOCKET)INVALID_HANDLE_VALUE)
2803 max = min(src->fd_count, (UINT)max);
2804 if ((UINT)dst->capa < (UINT)max) {
2805 dst->capa = (src->fd_count / FD_SETSIZE + 1) * FD_SETSIZE;
2806 dst->fdset =
xrealloc(dst->fdset,
sizeof(
unsigned int) +
sizeof(SOCKET) * dst->capa);
2809 memcpy(dst->fdset->fd_array, src->fd_array,
2810 max *
sizeof(src->fd_array[0]));
2811 dst->fdset->fd_count = src->fd_count;
2818 if ((UINT)dst->capa < src->fdset->fd_count) {
2819 dst->capa = (src->fdset->fd_count / FD_SETSIZE + 1) * FD_SETSIZE;
2820 dst->fdset =
xrealloc(dst->fdset,
sizeof(
unsigned int) +
sizeof(SOCKET) * dst->capa);
2823 memcpy(dst->fdset->fd_array, src->fdset->fd_array,
2824 src->fdset->fd_count *
sizeof(src->fdset->fd_array[0]));
2825 dst->fdset->fd_count = src->fdset->fd_count;
2844 while (s < src->fd_count) {
2845 SOCKET fd = src->fd_array[s];
2851 for (d = 0; d < dst->fdset->fd_count; d++) {
2852 if (dst->fdset->fd_array[d] == fd)
2855 if (d == dst->fdset->fd_count) {
2856 if ((
int)dst->fdset->fd_count >= dst->capa) {
2857 dst->capa = (dst->fdset->fd_count / FD_SETSIZE + 1) * FD_SETSIZE;
2858 dst->fdset =
xrealloc(dst->fdset,
sizeof(
unsigned int) +
sizeof(SOCKET) * dst->capa);
2860 dst->fdset->fd_array[dst->fdset->fd_count++] = fd;
2864 &src->fd_array[s+1],
2865 sizeof(src->fd_array[0]) * (--src->fd_count - s));
2875 return dst ? dst->fdset->fd_count : m;
2883 if (!src || !dst)
return 0;
2885 for (s = 0; s < src->fd_count; ++s) {
2886 SOCKET fd = src->fd_array[s];
2888 for (d = 0; d < dst->fd_count; ++d) {
2889 if (dst->fd_array[d] == fd)
2892 if (d == dst->fd_count && d < FD_SETSIZE) {
2893 dst->fd_array[dst->fd_count++] = fd;
2897 return dst->fd_count;
2914 ret = (GetFileType((HANDLE)sock) == FILE_TYPE_PIPE);
2928 if (PeekNamedPipe((HANDLE)sock,
NULL, 0,
NULL, &n,
NULL)) {
2932 ret = (GetLastError() == ERROR_BROKEN_PIPE);
2948 ret = (PeekConsoleInput((HANDLE)sock, &ir, 1, &n));
2963 if (PeekConsoleInput((HANDLE)sock, &ir, 1, &n) && n > 0) {
2964 if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown &&
2965 ir.Event.KeyEvent.uChar.AsciiChar) {
2969 ReadConsoleInput((HANDLE)sock, &ir, 1, &n);
2981 return (HANDLE)sock == INVALID_HANDLE_VALUE;
3003 r =
select(nfds, rd, wr, ex, timeout);
3005 if (r == SOCKET_ERROR) {
3061 struct timeval *timeout,
void *th)
3070 struct timeval limit = {0, 0};
3072 if (nfds < 0 || (timeout && (timeout->
tv_sec < 0 || timeout->
tv_usec < 0))) {
3078 if (timeout->
tv_sec < 0 ||
3080 timeout->
tv_usec >= 1000000) {
3087 if (limit.
tv_usec >= 1000000) {
3124 if (rd && (
int)rd->fd_count > r) r = (int)rd->fd_count;
3125 if (wr && (
int)wr->fd_count > r) r = (
int)wr->fd_count;
3126 if (ex && (
int)ex->fd_count > r) r = (
int)ex->fd_count;
3127 if (nfds > r) nfds = r;
3131 const struct timeval wait = {0, 10 * 1000};
3145 if (else_rd.fdset->fd_count || else_wr.fdset->fd_count) {
3148 r +=
copy_fd(rd, else_rd.fdset);
3149 r +=
copy_fd(wr, else_wr.fdset);
3165 if (rd)
copy_fd(&orig_rd, rd);
3166 if (wr)
copy_fd(&orig_wr, wr);
3167 if (ex)
copy_fd(&orig_ex, ex);
3170 if (rd)
copy_fd(rd, &orig_rd);
3171 if (wr)
copy_fd(wr, &orig_wr);
3172 if (ex)
copy_fd(ex, &orig_ex);
3179 if (
compare(&rest, &wait) < 0) dowait = &rest;
3181 Sleep(dowait->
tv_sec * 1000 + (dowait->
tv_usec + 999) / 1000);
3210 WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, guid,
sizeof(*guid),
3211 &ptr,
sizeof(ptr), &dmy,
NULL,
NULL);
3230 r = accept(
TO_SOCKET(s), addr, addrlen);
3231 if (r != INVALID_SOCKET) {
3232 SetHandleInformation((HANDLE)r, HANDLE_FLAG_INHERIT, 0);
3260 if (r == SOCKET_ERROR)
3277 r = connect(
TO_SOCKET(s), addr, addrlen);
3278 if (r == SOCKET_ERROR) {
3279 int err = WSAGetLastError();
3280 if (err != WSAEWOULDBLOCK)
3301 r = getpeername(
TO_SOCKET(s), addr, addrlen);
3302 if (r == SOCKET_ERROR)
3321 r = getsockname(sock, addr, addrlen);
3322 if (r == SOCKET_ERROR) {
3323 DWORD wsaerror = WSAGetLastError();
3324 if (wsaerror == WSAEINVAL) {
3329 memset(addr, 0, *addrlen);
3330 addr->sa_family = af;
3352 r = getsockopt(
TO_SOCKET(s), level, optname, optval, optlen);
3353 if (r == SOCKET_ERROR)
3370 r = ioctlsocket(
TO_SOCKET(s), cmd, argp);
3371 if (r == SOCKET_ERROR)
3389 if (r == SOCKET_ERROR)
3407 if (result != SOCKET_ERROR)
3409 else if ((err = WSAGetLastError()) == WSA_IO_PENDING) {
3413 result = WSAGetOverlappedResult(s, wol, &size,
TRUE, &flg);
3420 result = SOCKET_ERROR;
3423 if ((err = WSAGetLastError()) == WSAECONNABORTED && !input)
3425 else if (err == WSAEMSGSIZE && input) {
3433 case WAIT_OBJECT_0 + 1:
3436 CancelIo((HANDLE)s);
3441 if (err == WSAECONNABORTED && !input)
3447 CloseHandle(wol->hEvent);
3455 struct sockaddr *addr,
int *addrlen)
3473 if (addr && addrlen)
3474 r = recvfrom(s, buf, len, flags, addr, addrlen);
3476 r = recv(s, buf, len, flags);
3477 if (r == SOCKET_ERROR)
3481 if (addr && addrlen)
3482 r = sendto(s, buf, len, flags, addr, *addrlen);
3484 r = send(s, buf, len, flags);
3485 if (r == SOCKET_ERROR) {
3487 if (err == WSAECONNABORTED)
3500 memset(&wol, 0,
sizeof(wol));
3505 if (addr && addrlen)
3506 ret = WSARecvFrom(s, &wbuf, 1, &size, &flg, addr, addrlen,
3509 ret = WSARecv(s, &wbuf, 1, &size, &flg, &wol,
NULL);
3512 if (addr && addrlen)
3513 ret = WSASendTo(s, &wbuf, 1, &size, flags, addr, *addrlen,
3516 ret = WSASend(s, &wbuf, 1, &size, flags, &wol,
NULL);
3537 struct sockaddr *from,
int *fromlen)
3552 const struct sockaddr *to,
int tolen)
3555 (
struct sockaddr *)to, &tolen);
3558 #if !defined(MSG_TRUNC) && !defined(__MINGW32__) 3569 #ifndef WSAID_WSARECVMSG 3570 #define WSAID_WSARECVMSG {0xf689d7c8,0x6f1f,0x436b,{0x8a,0x53,0xe5,0x4f,0xe3,0x51,0xc3,0x22}} 3572 #ifndef WSAID_WSASENDMSG 3573 #define WSAID_WSASENDMSG {0xa441e712,0x754f,0x43ca,{0x84,0xa7,0x0d,0xee,0x44,0xcf,0x60,0x6d}} 3577 #define msghdr_to_wsamsg(msg, wsamsg) \ 3580 (wsamsg)->name = (msg)->msg_name; \ 3581 (wsamsg)->namelen = (msg)->msg_namelen; \ 3582 (wsamsg)->lpBuffers = ALLOCA_N(WSABUF, (msg)->msg_iovlen); \ 3583 (wsamsg)->dwBufferCount = (msg)->msg_iovlen; \ 3584 for (i = 0; i < (msg)->msg_iovlen; ++i) { \ 3585 (wsamsg)->lpBuffers[i].buf = (msg)->msg_iov[i].iov_base; \ 3586 (wsamsg)->lpBuffers[i].len = (msg)->msg_iov[i].iov_len; \ 3588 (wsamsg)->Control.buf = (msg)->msg_control; \ 3589 (wsamsg)->Control.len = (msg)->msg_controllen; \ 3590 (wsamsg)->dwFlags = (msg)->msg_flags; \ 3597 typedef int (WSAAPI *WSARecvMsg_t)(SOCKET,
WSAMSG *,
DWORD *, WSAOVERLAPPED *, LPWSAOVERLAPPED_COMPLETION_ROUTINE);
3598 static WSARecvMsg_t pWSARecvMsg =
NULL;
3623 if ((ret = pWSARecvMsg(s, &wsamsg, &len,
NULL,
NULL)) == SOCKET_ERROR) {
3632 memset(&wol, 0,
sizeof(wol));
3635 ret = pWSARecvMsg(s, &wsamsg, &size, &wol,
NULL);
3640 if (ret == SOCKET_ERROR)
3655 typedef int (WSAAPI *WSASendMsg_t)(SOCKET,
const WSAMSG *,
DWORD, DWORD *, WSAOVERLAPPED *, LPWSAOVERLAPPED_COMPLETION_ROUTINE);
3656 static WSASendMsg_t pWSASendMsg =
NULL;
3680 if ((ret = pWSASendMsg(s, &wsamsg, flags, &len,
NULL,
NULL)) == SOCKET_ERROR) {
3689 memset(&wol, 0,
sizeof(wol));
3692 ret = pWSASendMsg(s, &wsamsg, flags, &size, &wol,
NULL);
3712 r = setsockopt(
TO_SOCKET(s), level, optname, optval, optlen);
3713 if (r == SOCKET_ERROR)
3731 if (r == SOCKET_ERROR)
3741 unsigned long proto_buffers_len = 0;
3743 SOCKET out = INVALID_SOCKET;
3745 if (WSAEnumProtocols(
NULL,
NULL, &proto_buffers_len) == SOCKET_ERROR) {
3746 error_code = WSAGetLastError();
3747 if (error_code == WSAENOBUFS) {
3748 WSAPROTOCOL_INFO *proto_buffers;
3749 int protocols_available = 0;
3751 proto_buffers = (WSAPROTOCOL_INFO *)
malloc(proto_buffers_len);
3752 if (!proto_buffers) {
3753 WSASetLastError(WSA_NOT_ENOUGH_MEMORY);
3754 return INVALID_SOCKET;
3757 protocols_available =
3758 WSAEnumProtocols(
NULL, proto_buffers, &proto_buffers_len);
3759 if (protocols_available != SOCKET_ERROR) {
3761 for (i = 0; i < protocols_available; i++) {
3762 if ((af !=
AF_UNSPEC && af != proto_buffers[i].iAddressFamily) ||
3763 (type != proto_buffers[i].iSocketType) ||
3764 (protocol != 0 && protocol != proto_buffers[i].iProtocol))
3767 if ((proto_buffers[i].dwServiceFlags1 & XP1_IFS_HANDLES) == 0)
3770 out = WSASocket(af, type, protocol, &(proto_buffers[i]), 0,
3771 WSA_FLAG_OVERLAPPED);
3774 if (out == INVALID_SOCKET)
3775 out = WSASocket(af, type, protocol,
NULL, 0, 0);
3776 if (out != INVALID_SOCKET)
3777 SetHandleInformation((HANDLE)out, HANDLE_FLAG_INHERIT, 0);
3780 free(proto_buffers);
3801 if (s == INVALID_SOCKET) {
3816 #undef gethostbyaddr 3819 struct hostent * WSAAPI
3827 r = gethostbyaddr(addr, len, type);
3834 #undef gethostbyname 3837 struct hostent * WSAAPI
3845 r = gethostbyname(name);
3863 r = gethostname(name, len);
3864 if (r == SOCKET_ERROR)
3870 #undef getprotobyname 3873 struct protoent * WSAAPI
3881 r = getprotobyname(name);
3888 #undef getprotobynumber 3891 struct protoent * WSAAPI
3899 r = getprotobynumber(num);
3906 #undef getservbyname 3909 struct servent * WSAAPI
3917 r = getservbyname(name, proto);
3924 #undef getservbyport 3927 struct servent * WSAAPI
3935 r = getservbyport(port, proto);
3946 SOCKET svr = INVALID_SOCKET, r = INVALID_SOCKET, w = INVALID_SOCKET;
3947 struct sockaddr_in sock_in4;
3949 struct sockaddr_in6 sock_in6;
3951 struct sockaddr *addr;
3961 #if defined PF_INET && PF_INET != AF_INET 3964 sock_in4.sin_family = AF_INET;
3965 sock_in4.sin_port = 0;
3967 addr = (
struct sockaddr *)&sock_in4;
3968 len =
sizeof(sock_in4);
3972 memset(&sock_in6, 0,
sizeof(sock_in6));
3973 sock_in6.sin6_family = AF_INET6;
3974 sock_in6.sin6_addr = IN6ADDR_LOOPBACK_INIT;
3975 addr = (
struct sockaddr *)&sock_in6;
3976 len =
sizeof(sock_in6);
3983 if (type != SOCK_STREAM) {
3988 sv[0] = (SOCKET)INVALID_HANDLE_VALUE;
3989 sv[1] = (SOCKET)INVALID_HANDLE_VALUE;
3993 if (svr == INVALID_SOCKET)
3995 if (bind(svr, addr, len) < 0)
3997 if (getsockname(svr, addr, &len) < 0)
3999 if (type == SOCK_STREAM)
4003 if (w == INVALID_SOCKET)
4005 if (connect(w, addr, len) < 0)
4008 r = accept(svr, addr, &len);
4009 if (r == INVALID_SOCKET)
4011 SetHandleInformation((HANDLE)r, HANDLE_FLAG_INHERIT, 0);
4018 if (r != INVALID_SOCKET)
4020 if (w != INVALID_SOCKET)
4027 if (svr != INVALID_SOCKET)
4044 closesocket(pair[0]);
4045 closesocket(pair[1]);
4051 closesocket(pair[1]);
4060 #if !defined(_MSC_VER) || _MSC_VER >= 1400 4065 #define hex2byte(str) \ 4066 ((isdigit(*(str)) ? *(str) - '0' : toupper(*(str)) - 'A' + 10) << 4 | (isdigit(*((str) + 1)) ? *((str) + 1) - '0' : toupper(*((str) + 1)) - 'A' + 10)) 4069 if (*str ==
'{') str++;
4070 guid->Data1 = (long)strtoul(str, &end, 16);
4072 guid->Data2 = (
unsigned short)strtoul(str, &end, 16);
4074 guid->Data3 = (
unsigned short)strtoul(str, &end, 16);
4080 for (i = 0; i < 6; i++) {
4081 guid->Data4[i + 2] =
hex2byte(str);
4087 #ifndef HAVE_TYPE_NET_LUID 4107 IP_ADAPTER_ADDRESSES *root, *addr;
4111 if (ret != ERROR_BUFFER_OVERFLOW) {
4116 ret = GetAdaptersAddresses(
AF_UNSPEC, 0,
NULL, root, &size);
4117 if (ret != ERROR_SUCCESS) {
4123 if (pConvertInterfaceGuidToLuid == (
cigl_t)-1)
4124 pConvertInterfaceGuidToLuid =
4126 "ConvertInterfaceGuidToLuid",
NULL);
4127 if (pConvertInterfaceLuidToNameA == (
cilnA_t)-1)
4128 pConvertInterfaceLuidToNameA =
4130 "ConvertInterfaceLuidToNameA",
NULL);
4132 for (prev =
NULL, addr = root; addr; addr = addr->Next) {
4143 str2guid(addr->AdapterName, &guid);
4144 if (pConvertInterfaceGuidToLuid && pConvertInterfaceLuidToNameA &&
4153 if (addr->IfType & IF_TYPE_SOFTWARE_LOOPBACK)
4155 if (addr->OperStatus == IfOperStatusUp) {
4158 if (addr->FirstUnicastAddress) {
4159 IP_ADAPTER_UNICAST_ADDRESS *cur;
4161 for (cur = addr->FirstUnicastAddress; cur; cur = cur->Next) {
4162 if (cur->Flags & IP_ADAPTER_ADDRESS_TRANSIENT ||
4163 cur->DadState == IpDadStateDeprecated) {
4175 cur->Address.iSockaddrLength);
4246 flag &= ~O_NONBLOCK;
4250 ret = ioctlsocket(sock, FIONBIO, &ioctlArg);
4262 dupfd(HANDLE hDup,
int flags,
int minfd)
4272 goto close_fds_and_return;
4275 goto close_fds_and_return;
4277 fds[filled++] = ret;
4278 }
while (filled < (
int)
numberof(fds));
4280 ret =
dupfd(hDup, flags, minfd);
4282 close_fds_and_return:
4284 while (filled > 0) {
4285 int fd = fds[--filled];
4311 arg = va_arg(va,
int);
4313 return setfl(sock, arg);
4319 if (!(DuplicateHandle(GetCurrentProcess(), (HANDLE)_get_osfhandle(fd),
4320 GetCurrentProcess(), &hDup, 0
L,
4322 DUPLICATE_SAME_ACCESS))) {
4328 arg = va_arg(va,
int);
4334 flag &= ~FNOINHERIT;
4335 if ((ret =
dupfd(hDup, flag, arg)) == -1)
4341 if (h == -1)
return -1;
4342 if (!GetHandleInformation((HANDLE)h, &flag)) {
4346 return (flag & HANDLE_FLAG_INHERIT) ? 0 :
FD_CLOEXEC;
4350 if (h == -1)
return -1;
4352 arg = va_arg(va,
int);
4354 if (!SetHandleInformation((HANDLE)h, HANDLE_FLAG_INHERIT,
4355 (arg &
FD_CLOEXEC) ? 0 : HANDLE_FLAG_INHERIT)) {
4359 if (arg & FD_CLOEXEC)
4381 if (!GetNamedPipeHandleState((HANDLE)sock, &state,
NULL,
NULL,
NULL,
NULL, 0)) {
4385 state |= PIPE_NOWAIT;
4386 if (!SetNamedPipeHandleState((HANDLE)sock, &state,
NULL,
NULL)) {
4409 if (!GetExitCodeProcess(child->
hProcess, &exitcode)) {
4411 err = GetLastError();
4413 case ERROR_INVALID_PARAMETER:
4416 case ERROR_INVALID_HANDLE:
4427 if (exitcode != STILL_ACTIVE) {
4436 *stat_loc = exitcode << 8;
4437 if (exitcode & 0xC0000000) {
4438 static const struct {
4442 {STATUS_ACCESS_VIOLATION, SIGSEGV},
4443 {STATUS_ILLEGAL_INSTRUCTION, SIGILL},
4444 {STATUS_PRIVILEGED_INSTRUCTION, SIGILL},
4445 {STATUS_FLOAT_DENORMAL_OPERAND, SIGFPE},
4446 {STATUS_FLOAT_DIVIDE_BY_ZERO, SIGFPE},
4447 {STATUS_FLOAT_INEXACT_RESULT, SIGFPE},
4448 {STATUS_FLOAT_INVALID_OPERATION, SIGFPE},
4449 {STATUS_FLOAT_OVERFLOW, SIGFPE},
4450 {STATUS_FLOAT_STACK_CHECK, SIGFPE},
4451 {STATUS_FLOAT_UNDERFLOW, SIGFPE},
4452 #ifdef STATUS_FLOAT_MULTIPLE_FAULTS 4453 {STATUS_FLOAT_MULTIPLE_FAULTS, SIGFPE},
4455 #ifdef STATUS_FLOAT_MULTIPLE_TRAPS 4456 {STATUS_FLOAT_MULTIPLE_TRAPS, SIGFPE},
4458 {STATUS_CONTROL_C_EXIT,
SIGINT},
4461 for (i = 0; i < (int)
numberof(table); i++) {
4462 if (table[i].status == exitcode) {
4463 *stat_loc |= table[i].sig;
4469 *stat_loc |= SIGSEGV;
4499 if (!child->pid || child->pid < 0)
continue;
4501 events[count++] = child->hProcess;
4509 if (ret == WAIT_TIMEOUT)
return 0;
4510 if ((ret -= WAIT_OBJECT_0) == count) {
4536 if (ret == WAIT_OBJECT_0 + 1)
return -1;
4537 if (ret != WAIT_OBJECT_0) {
4546 if (pid == -1 && retried) pid = 0;
4552 #include <sys/timeb.h> 4559 unsigned LONG_LONG
lt;
4561 tmp.LowPart = ft->dwLowDateTime;
4562 tmp.HighPart = ft->dwHighDateTime;
4570 lt -= (LONG_LONG)((1970-1601)*365.2425) * 24 * 60 * 60 * 1000 * 1000;
4572 tv->
tv_sec = (long)(lt / (1000 * 1000));
4573 tv->
tv_usec = (long)(lt % (1000 * 1000));
4575 return tv->
tv_sec > 0 ? 0 : -1;
4584 GetSystemTimeAsFileTime(&ft);
4606 LARGE_INTEGER
count;
4607 if (!QueryPerformanceFrequency(&freq)) {
4611 if (!QueryPerformanceCounter(&count)) {
4615 sp->
tv_sec = count.QuadPart / freq.QuadPart;
4616 if (freq.QuadPart < 1000000000)
4617 sp->
tv_nsec = (count.QuadPart % freq.QuadPart) * 1000000000 / freq.QuadPart;
4619 sp->
tv_nsec = (
long)((count.QuadPart % freq.QuadPart) * (1000000000.0 / freq.QuadPart));
4642 if (!QueryPerformanceFrequency(&freq)) {
4647 sp->
tv_nsec = (long)(1000000000.0 / freq.QuadPart);
4663 len = GetCurrentDirectory(0,
NULL);
4684 if (!GetCurrentDirectory(size, p)) {
4698 chown(
const char *path,
int owner,
int group)
4711 lchown(
const char *path,
int owner,
int group)
4729 if (pid < 0 || (pid == 0 && sig !=
SIGINT)) {
4734 if ((
unsigned int)pid == GetCurrentProcessId() &&
4735 (sig != 0 && sig !=
SIGKILL)) {
4736 if ((ret =
raise(sig)) != 0) {
4747 OpenProcess(PROCESS_QUERY_INFORMATION,
FALSE, (
DWORD)pid);
4748 if (hProc ==
NULL || hProc == INVALID_HANDLE_VALUE) {
4749 if (GetLastError() == ERROR_INVALID_PARAMETER) {
4765 DWORD ctrlEvent = CTRL_C_EVENT;
4769 ctrlEvent = CTRL_BREAK_EVENT;
4771 if (!GenerateConsoleCtrlEvent(ctrlEvent, (
DWORD)pid)) {
4772 if ((err = GetLastError()) == 0)
4789 hProc = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION,
FALSE, (
DWORD)pid);
4791 if (hProc ==
NULL || hProc == INVALID_HANDLE_VALUE) {
4792 if (GetLastError() == ERROR_INVALID_PARAMETER) {
4802 if (!GetExitCodeProcess(hProc, &status)) {
4806 else if (status == STILL_ACTIVE) {
4807 if (!TerminateProcess(hProc, 0)) {
4834 wlink(
const WCHAR *from,
const WCHAR *to)
4836 if (!CreateHardLinkW(to, from,
NULL)) {
4858 ret =
wlink(wfrom, wto);
4866 link(
const char *from,
const char *to)
4878 ret =
wlink(wfrom, wto);
4885 #ifndef FILE_DEVICE_FILE_SYSTEM 4886 # define FILE_DEVICE_FILE_SYSTEM 0x00000009 4888 #ifndef FSCTL_GET_REPARSE_POINT 4889 # define FSCTL_GET_REPARSE_POINT ((0x9<<16)|(42<<2)) 4891 #ifndef IO_REPARSE_TAG_SYMLINK 4892 # define IO_REPARSE_TAG_SYMLINK 0xA000000CL 4903 f =
open_special(path, 0, FILE_FLAG_OPEN_REPARSE_POINT);
4904 if (f == INVALID_HANDLE_VALUE) {
4905 return GetLastError();
4909 rp, size, &ret,
NULL)) {
4913 rp->
ReparseTag != IO_REPARSE_TAG_MOUNT_POINT) {
4914 e = ERROR_INVALID_PARAMETER;
4931 if (e == ERROR_MORE_DATA) {
4939 case ERROR_MORE_DATA:
4953 if (!e || e == ERROR_MORE_DATA) {
4959 *len = ret /
sizeof(WCHAR);
4962 static const WCHAR *volume =
L"Volume{";
4966 volume_prefix_len *
sizeof(WCHAR));
4968 *len = ret /
sizeof(WCHAR);
4969 ret -= volume_prefix_len *
sizeof(WCHAR);
4970 if (ret >
sizeof(volume) - 1 *
sizeof(WCHAR) &&
4971 memcmp(name, volume,
sizeof(volume) - 1 *
sizeof(WCHAR)) == 0)
4976 if ((
char *)name + ret +
sizeof(WCHAR) > (
char *)rp + bufsize)
4980 ((WCHAR *)name)[ret/
sizeof(WCHAR)] =
L'\0';
4994 DWORD len = MultiByteToWideChar(cp, 0, path, -1,
NULL, 0);
4996 WCHAR *wname, *wpath =
ALLOCV(wtmp, size +
sizeof(WCHAR) * len);
5001 MultiByteToWideChar(cp, 0, path, -1, wpath, len);
5003 if (e && e != ERROR_MORE_DATA) {
5008 len = lstrlenW(wname) + 1;
5009 ret = WideCharToMultiByte(cp, 0, wname, len, buf, bufsize,
NULL,
NULL);
5036 #ifndef SYMBOLIC_LINK_FLAG_DIRECTORY 5037 #define SYMBOLIC_LINK_FLAG_DIRECTORY (0x1) 5044 int atts, len1, len2;
5046 WCHAR *wsrc, *
wlink;
5050 typedef BOOLEAN (WINAPI *create_symbolic_link_func)(WCHAR*, WCHAR*,
DWORD);
5051 static create_symbolic_link_func create_symbolic_link =
5052 (create_symbolic_link_func)-1;
5054 if (create_symbolic_link == (create_symbolic_link_func)-1) {
5055 create_symbolic_link = (create_symbolic_link_func)
5058 if (!create_symbolic_link) {
5063 len1 = MultiByteToWideChar(cp, 0, src, -1,
NULL, 0);
5064 len2 = MultiByteToWideChar(cp, 0, link, -1,
NULL, 0);
5065 wsrc =
ALLOCV_N(WCHAR, buf, len1+len2);
5066 wlink = wsrc + len1;
5067 MultiByteToWideChar(cp, 0, src, -1, wsrc, len1);
5068 MultiByteToWideChar(cp, 0, link, -1, wlink, len2);
5071 atts = GetFileAttributesW(wsrc);
5072 if (atts != -1 && atts & FILE_ATTRIBUTE_DIRECTORY)
5074 ret = create_symbolic_link(wlink, wsrc, flag);
5078 int e = GetLastError();
5103 return waitpid(-1, status, 0);
5110 WCHAR *wenvarea, *wenv;
5115 if (len == 0)
return NULL;
5121 wenvarea = GetEnvironmentStringsW();
5126 for (wenv = wenvarea, wlen = 1; *wenv; wenv += lstrlenW(wenv) + 1)
5127 wlen += lstrlenW(wenv) + 1;
5129 FreeEnvironmentStringsW(wenvarea);
5135 return env + len + 1;
5158 BY_HANDLE_FILE_INFORMATION st = {0};
5160 HANDLE h =
open_special(path, 0, FILE_FLAG_OPEN_REPARSE_POINT);
5162 if (h == INVALID_HANDLE_VALUE) {
5163 ASSUME(e = GetLastError());
5166 if (!GetFileInformationByHandle(h, &st)) {
5167 ASSUME(e = GetLastError());
5170 *atts = st.dwFileAttributes;
5171 *vsn = st.dwVolumeSerialNumber;
5179 wrename(
const WCHAR *oldpath,
const WCHAR *newpath)
5183 DWORD oldvsn = 0, newvsn = 0, e;
5190 if (oldatts & FILE_ATTRIBUTE_REPARSE_POINT) {
5192 if (fh == INVALID_HANDLE_VALUE) {
5194 if (e == ERROR_CANT_RESOLVE_FILENAME) {
5204 if (newatts != (
DWORD)-1 && newatts & FILE_ATTRIBUTE_READONLY)
5205 SetFileAttributesW(newpath, newatts & ~ FILE_ATTRIBUTE_READONLY);
5207 if (!MoveFileExW(oldpath, newpath, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED))
5211 DWORD e = GetLastError();
5212 if ((e == ERROR_ACCESS_DENIED) && (oldatts & FILE_ATTRIBUTE_DIRECTORY) &&
5219 SetFileAttributesW(newpath, oldatts);
5267 if (path[0] ==
L'\\' && path[1] ==
L'\\') {
5268 const WCHAR *p = path + 2;
5269 if (p[0] ==
L'?' && p[1] ==
L'\\') {
5277 for (p++; *p; p++) {
5281 if (!p[0] || !p[1] || (p[1] ==
L'.' && !p[2]))
5288 #define COPY_STAT(src, dest, size_cast) do { \ 5289 (dest).st_dev = (src).st_dev; \ 5290 (dest).st_ino = (src).st_ino; \ 5291 (dest).st_mode = (src).st_mode; \ 5292 (dest).st_nlink = (src).st_nlink; \ 5293 (dest).st_uid = (src).st_uid; \ 5294 (dest).st_gid = (src).st_gid; \ 5295 (dest).st_rdev = (src).st_rdev; \ 5296 (dest).st_size = size_cast(src).st_size; \ 5297 (dest).st_atime = (src).st_atime; \ 5298 (dest).st_mtime = (src).st_mtime; \ 5299 (dest).st_ctime = (src).st_ctime; \ 5327 unsigned short *p2 = (
unsigned short *)st;
5328 unsigned int *p4 = (
unsigned int *)st;
5329 DWORD high = pinfo->nFileIndexHigh;
5331 p2[7] = high & 0xFFFF;
5332 p4[5] = pinfo->nFileIndexLow;
5339 BY_HANDLE_FILE_INFORMATION info;
5342 if (GetFileInformationByHandle(h, &info)) {
5353 BY_HANDLE_FILE_INFORMATION info;
5354 int ret =
fstat(fd, st);
5356 if (ret)
return ret;
5357 if (GetEnvironmentVariableW(
L"TZ",
NULL, 0) == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)
return ret;
5358 if (GetFileInformationByHandle((HANDLE)_get_osfhandle(fd), &info)) {
5373 if (GetEnvironmentVariableW(
L"TZ",
NULL, 0) == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
5374 ret = _fstati64(fd, st);
5378 ret =
fstat(fd, &tmp);
5380 if (ret)
return ret;
5390 BY_HANDLE_FILE_INFORMATION info;
5393 if (GetFileInformationByHandle(h, &info)) {
5394 st->st_size = ((__int64)info.nFileSizeHigh << 32) | info.nFileSizeLow;
5398 st->st_nlink = info.nNumberOfLinks;
5399 attr = info.dwFileAttributes;
5423 if (attr & FILE_ATTRIBUTE_READONLY) {
5427 mode |= S_IREAD | S_IWRITE |
S_IWUSR;
5430 if (attr & FILE_ATTRIBUTE_REPARSE_POINT) {
5434 mode |= S_IFDIR | S_IEXEC;
5436 else if (attr & FILE_ATTRIBUTE_DIRECTORY) {
5437 mode |= S_IFDIR | S_IEXEC;
5443 if (path && (mode & S_IFREG)) {
5444 const WCHAR *end = path + lstrlenW(path);
5445 while (path < end) {
5446 end = CharPrevW(path, end);
5448 if ((_wcsicmp(end,
L".bat") == 0) ||
5449 (_wcsicmp(end,
L".cmd") == 0) ||
5450 (_wcsicmp(end,
L".com") == 0) ||
5451 (_wcsicmp(end,
L".exe") == 0)) {
5456 if (!iswalnum(*end))
break;
5460 mode |= (mode & 0500) >> 3;
5461 mode |= (mode & 0500) >> 6;
5470 WIN32_FIND_DATAW fd;
5478 if (!(p = wcsstr(path,
L"...")))
5480 q = p + wcsspn(p,
L".");
5481 if ((p == path || wcschr(
L":/\\", *(p - 1))) &&
5482 (!*q || wcschr(
L":/\\", *q))) {
5489 if (!GetFullPathNameW(path,
sizeof(full) /
sizeof(WCHAR), full, &dmy)) {
5493 if (full[1] ==
L':' && !full[3] && GetDriveTypeW(full) != DRIVE_NO_ROOT_DIR)
5497 if (fh == INVALID_HANDLE_VALUE)
5508 WIN32_FIND_DATAW wfd;
5510 int e = GetLastError();
5512 if ((e == ERROR_FILE_NOT_FOUND) || (e == ERROR_INVALID_NAME)
5513 || (e == ERROR_PATH_NOT_FOUND || (e == ERROR_BAD_NETPATH))) {
5519 h = FindFirstFileW(path, &wfd);
5520 if (h == INVALID_HANDLE_VALUE) {
5529 st->st_size = ((__int64)wfd.nFileSizeHigh << 32) | wfd.nFileSizeLow;
5538 return (iswalpha(path[0]) && path[1] ==
L':') ?
5539 towupper(path[0]) -
L'A' : _getdrive() - 1;
5551 memset(st, 0,
sizeof(*st));
5553 if (f != INVALID_HANDLE_VALUE) {
5557 if (attr & FILE_ATTRIBUTE_DIRECTORY) {
5562 finalname[min(len,
numberof(finalname)-1)] = L
'\0';
5564 if (wcsncmp(path, namespace_prefix,
numberof(namespace_prefix)) == 0)
5565 path +=
numberof(namespace_prefix);
5581 WIN32_FILE_ATTRIBUTE_DATA wfa;
5582 const WCHAR *p = path;
5584 memset(st, 0,
sizeof(*st));
5587 if (wcsncmp(p, namespace_prefix,
numberof(namespace_prefix)) == 0)
5589 if (wcspbrk(p, L
"?*")) {
5593 if (GetFileAttributesExW(path, GetFileExInfoStandard, (
void*)&wfa)) {
5594 if (wfa.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
5599 wfa.dwFileAttributes &= ~FILE_ATTRIBUTE_REPARSE_POINT;
5601 if (wfa.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
5606 st->st_size = ((__int64)wfa.nFileSizeHigh << 32) | wfa.nFileSizeLow;
5645 size = lstrlenW(path) + 2;
5668 size = lstrlenW(path) + 2;
5687 for (p = path, s = buf1; *p; p++, s++) {
5695 if (!len || L
'\"' == *(--s)) {
5699 end = buf1 + len - 1;
5704 else if (*end != L
'\\')
5705 lstrcatW(buf1, L
"\\");
5707 else if (*end == L
'\\' || (buf1 + 1 == end && *end == L
':'))
5708 lstrcatW(buf1, L
".");
5773 struct stati64 stat;
5777 if ((stat.st_mode & mode) != mode) {
5788 struct stati64 stat;
5792 if ((stat.st_mode & mode) != mode) {
5803 long upos, lpos, usize, lsize;
5807 if ((lpos = SetFilePointer(h, 0, (upos = 0, &upos),
SEEK_CUR)) == -1L &&
5808 (e = GetLastError())) {
5812 usize = (long)(size >> 32);
5814 if (SetFilePointer(h, lsize, &usize,
SEEK_SET) == (
DWORD)-1L &&
5815 (e = GetLastError())) {
5818 else if (!SetEndOfFile(h)) {
5824 SetFilePointer(h, lpos, &upos,
SEEK_SET);
5838 h = CreateFileW(wpath, GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
5839 if (h == INVALID_HANDLE_VALUE) {
5870 h = (HANDLE)_get_osfhandle(fd);
5871 if (h == (HANDLE)-1)
return -1;
5879 __int64 qw = ft->dwHighDateTime;
5881 qw |= ft->dwLowDateTime;
5890 FILETIME create, exit, kernel, user;
5892 if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
5909 #define yield_once() Sleep(0) 5910 #define yield_until(condition) do yield_once(); while (!(condition)) 5943 BOOL interrupted =
FALSE;
5964 if (TerminateThread(thr, intrval)) {
5969 GetExitCodeThread(thr, &val);
5974 MEMORY_BASIC_INFORMATION m;
5976 memset(&m, 0,
sizeof(m));
5977 if (!VirtualQuery(arg.
stackaddr, &m,
sizeof(m))) {
5978 Debug(fprintf(stderr,
"couldn't get stack base:%p:%d\n",
5981 else if (!VirtualFree(m.AllocationBase, 0, MEM_RELEASE)) {
5982 Debug(fprintf(stderr,
"couldn't release stack:%p:%d\n",
5983 m.AllocationBase, GetLastError()));
5994 rb_fatal(
"failed to launch waiter thread:%ld", GetLastError());
6004 WCHAR *envtop, *
env;
6005 char **myenvtop, **myenv;
6018 envtop = GetEnvironmentStringsW();
6019 for (env = envtop, num = 0; *
env; env += lstrlenW(env) + 1)
6020 if (*env !=
'=') num++;
6022 myenvtop = (
char **)
malloc(
sizeof(
char *) * (num + 1));
6023 for (env = envtop, myenv = myenvtop; *
env; env += lstrlenW(env) + 1) {
6032 FreeEnvironmentStringsW(envtop);
6043 while (*t)
free(*t++);
6051 return GetCurrentProcessId();
6059 typedef long (WINAPI query_func)(HANDLE, int,
void *,
ULONG, ULONG *);
6060 static query_func *pNtQueryInformationProcess = (query_func *)-1;
6063 if (pNtQueryInformationProcess == (query_func *)-1)
6064 pNtQueryInformationProcess = (query_func *)
get_proc_address(
"ntdll.dll",
"NtQueryInformationProcess",
NULL);
6065 if (pNtQueryInformationProcess) {
6068 void* PebBaseAddress;
6075 long ret = pNtQueryInformationProcess(GetCurrentProcess(), 0, &pbi,
sizeof(pbi), &len);
6077 ppid = pbi.ParentProcessId;
6084 STATIC_ASSERT(std_handle, (STD_OUTPUT_HANDLE-STD_INPUT_HANDLE)==(STD_ERROR_HANDLE-STD_OUTPUT_HANDLE));
6087 #define set_new_std_handle(newfd, handle) do { \ 6088 if ((unsigned)(newfd) > 2) break; \ 6089 SetStdHandle(STD_INPUT_HANDLE+(STD_OUTPUT_HANDLE-STD_INPUT_HANDLE)*(newfd), \ 6092 #define set_new_std_fd(newfd) set_new_std_handle(newfd, (HANDLE)rb_w32_get_osfhandle(newfd)) 6100 if (oldfd == newfd)
return newfd;
6101 ret =
dup2(oldfd, newfd);
6102 if (ret < 0)
return ret;
6116 va_start(arg, oflag);
6117 pmode = va_arg(arg,
int);
6131 DWORD attr = GetFileAttributesW(wfile);
6132 if (attr == (
DWORD)-1L ||
6133 !(attr & FILE_ATTRIBUTE_DIRECTORY) ||
6150 va_start(arg, oflag);
6151 pmode = va_arg(arg,
int);
6167 if (oflag & O_CREAT) {
6169 va_start(arg, oflag);
6170 pmode = va_arg(arg,
int);
6184 DWORD attr = FILE_ATTRIBUTE_NORMAL;
6185 SECURITY_ATTRIBUTES sec;
6191 if ((oflag & O_TEXT) || !(oflag &
O_BINARY)) {
6192 fd = _wopen(file, oflag, pmode);
6206 sec.nLength =
sizeof(sec);
6207 sec.lpSecurityDescriptor =
NULL;
6208 if (oflag & O_NOINHERIT) {
6209 sec.bInheritHandle =
FALSE;
6213 sec.bInheritHandle =
TRUE;
6215 oflag &= ~O_NOINHERIT;
6218 oflag &= ~(O_BINARY | O_TEXT);
6220 switch (oflag & (O_RDWR | O_RDONLY | O_WRONLY)) {
6222 access = GENERIC_READ | GENERIC_WRITE;
6225 access = GENERIC_READ;
6228 access = GENERIC_WRITE;
6234 oflag &= ~(O_RDWR | O_RDONLY | O_WRONLY);
6236 switch (oflag & (O_CREAT | O_EXCL | O_TRUNC)) {
6238 create = OPEN_ALWAYS;
6242 create = OPEN_EXISTING;
6244 case O_CREAT | O_EXCL:
6245 case O_CREAT | O_EXCL | O_TRUNC:
6246 create = CREATE_NEW;
6249 case O_TRUNC | O_EXCL:
6250 create = TRUNCATE_EXISTING;
6252 case O_CREAT | O_TRUNC:
6253 create = CREATE_ALWAYS;
6259 if (oflag & O_CREAT) {
6261 if (!(pmode & S_IWRITE))
6262 attr = FILE_ATTRIBUTE_READONLY;
6264 oflag &= ~(O_CREAT | O_EXCL | O_TRUNC);
6266 if (oflag & O_TEMPORARY) {
6267 attr |= FILE_FLAG_DELETE_ON_CLOSE;
6270 oflag &= ~O_TEMPORARY;
6272 if (oflag & _O_SHORT_LIVED)
6273 attr |= FILE_ATTRIBUTE_TEMPORARY;
6274 oflag &= ~_O_SHORT_LIVED;
6276 switch (oflag & (O_SEQUENTIAL | O_RANDOM)) {
6280 attr |= FILE_FLAG_SEQUENTIAL_SCAN;
6283 attr |= FILE_FLAG_RANDOM_ACCESS;
6289 oflag &= ~(O_SEQUENTIAL | O_RANDOM);
6291 if (oflag & ~O_APPEND) {
6298 h = CreateFile(
"NUL", 0, 0,
NULL, OPEN_ALWAYS, 0,
NULL);
6299 fd = _open_osfhandle((
intptr_t)h, 0);
6311 h = CreateFileW(file, access, FILE_SHARE_READ | FILE_SHARE_WRITE | share_delete, &sec, create, attr,
NULL);
6312 if (h == INVALID_HANDLE_VALUE) {
6313 DWORD e = GetLastError();
6321 switch (GetFileType(h)) {
6322 case FILE_TYPE_CHAR:
6325 case FILE_TYPE_PIPE:
6328 case FILE_TYPE_UNKNOWN:
6335 if (!(flags & (
FDEV |
FPIPE)) && (oflag & O_APPEND))
6355 int save_errno =
errno;
6357 if (fflush(fp))
return -1;
6365 if (closesocket(sock) == SOCKET_ERROR) {
6376 static DWORD serial = 0;
6377 static const char prefix[] =
"\\\\.\\pipe\\ruby";
6379 width_of_prefix = (int)
sizeof(prefix) - 1,
6380 width_of_pid = (int)
sizeof(rb_pid_t) * 2,
6381 width_of_serial = (int)
sizeof(serial) * 2,
6382 width_of_ids = width_of_pid + 1 + width_of_serial + 1
6384 char name[
sizeof(prefix) + width_of_ids];
6385 SECURITY_ATTRIBUTES sec;
6386 HANDLE hRead, hWrite, h;
6387 int fdRead, fdWrite;
6391 snprintf(
name + width_of_prefix, width_of_ids,
"%.*"PRI_PIDT_PREFIX
"x-%.*lx",
6394 sec.nLength =
sizeof(sec);
6395 sec.lpSecurityDescriptor =
NULL;
6396 sec.bInheritHandle =
FALSE;
6399 hRead = CreateNamedPipe(
name, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
6400 0, 2, 65536, 65536, 0, &sec);
6402 if (hRead == INVALID_HANDLE_VALUE) {
6404 if (err == ERROR_PIPE_BUSY)
6412 hWrite = CreateFile(
name, GENERIC_READ | GENERIC_WRITE, 0, &sec,
6413 OPEN_EXISTING, FILE_FLAG_OVERLAPPED,
NULL);
6415 if (hWrite == INVALID_HANDLE_VALUE) {
6423 h = CreateFile(
"NUL", 0, 0,
NULL, OPEN_ALWAYS, 0,
NULL);
6424 fdRead = _open_osfhandle((
intptr_t)h, 0);
6428 CloseHandle(hWrite);
6443 h = CreateFile(
"NUL", 0, 0,
NULL, OPEN_ALWAYS, 0,
NULL);
6444 fdWrite = _open_osfhandle((
intptr_t)h, 0);
6446 if (fdWrite == -1) {
6448 CloseHandle(hWrite);
6475 const void *
const func = WriteConsoleW;
6477 MEMORY_BASIC_INFORMATION m;
6479 memset(&m, 0,
sizeof(m));
6480 if (!VirtualQuery(func, &m,
sizeof(m))) {
6483 k = GetModuleHandle(
"kernel32.dll");
6484 if (!k)
return FALSE;
6485 return (HMODULE)m.AllocationBase != k;
6509 CONSOLE_SCREEN_BUFFER_INFO csbi;
6512 p->
vt100.
attr = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
6515 if (GetConsoleScreenBufferInfo(h, &csbi)) {
6535 #define FOREGROUND_MASK (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY) 6536 #define BACKGROUND_MASK (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY) 6538 #define constat_attr_color_reverse(attr) \ 6539 ((attr) & ~(FOREGROUND_MASK | BACKGROUND_MASK)) | \ 6540 (((attr) & FOREGROUND_MASK) << 4) | \ 6541 (((attr) & BACKGROUND_MASK) >> 4) 6550 if (!count)
return attr;
6552 bold = attr & FOREGROUND_INTENSITY;
6553 attr &= ~(FOREGROUND_INTENSITY | BACKGROUND_INTENSITY);
6555 while (count-- > 0) {
6558 attr = default_attr;
6563 bold = FOREGROUND_INTENSITY;
6566 #ifndef COMMON_LVB_UNDERSCORE 6567 #define COMMON_LVB_UNDERSCORE 0x8000 6576 attr &= ~(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
6580 attr = (attr & ~(FOREGROUND_BLUE | FOREGROUND_GREEN)) | FOREGROUND_RED;
6584 attr = (attr & ~(FOREGROUND_BLUE | FOREGROUND_RED)) | FOREGROUND_GREEN;
6588 attr = (attr & ~FOREGROUND_BLUE) | FOREGROUND_GREEN | FOREGROUND_RED;
6592 attr = (attr & ~(FOREGROUND_GREEN | FOREGROUND_RED)) | FOREGROUND_BLUE;
6596 attr = (attr & ~FOREGROUND_GREEN) | FOREGROUND_BLUE | FOREGROUND_RED;
6600 attr = (attr & ~FOREGROUND_RED) | FOREGROUND_BLUE | FOREGROUND_GREEN;
6604 attr |= FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
6608 attr &= ~(BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED);
6611 attr = (attr & ~(BACKGROUND_BLUE | BACKGROUND_GREEN)) | BACKGROUND_RED;
6614 attr = (attr & ~(BACKGROUND_BLUE | BACKGROUND_RED)) | BACKGROUND_GREEN;
6617 attr = (attr & ~BACKGROUND_BLUE) | BACKGROUND_GREEN | BACKGROUND_RED;
6620 attr = (attr & ~(BACKGROUND_GREEN | BACKGROUND_RED)) | BACKGROUND_BLUE;
6623 attr = (attr & ~BACKGROUND_GREEN) | BACKGROUND_BLUE | BACKGROUND_RED;
6626 attr = (attr & ~BACKGROUND_RED) | BACKGROUND_BLUE | BACKGROUND_GREEN;
6629 attr |= BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
6643 CONSOLE_SCREEN_BUFFER_INFO csbi;
6650 if (!GetConsoleScreenBufferInfo(handle, &csbi))
return;
6651 if (count > 0 && seq[0] > 0) arg1 = seq[0];
6657 csbi.dwCursorPosition.X = 0;
6659 csbi.dwCursorPosition.Y -= arg1;
6660 if (csbi.dwCursorPosition.Y < 0)
6661 csbi.dwCursorPosition.Y = 0;
6662 SetConsoleCursorPosition(handle, csbi.dwCursorPosition);
6665 csbi.dwCursorPosition.X = 0;
6668 csbi.dwCursorPosition.Y += arg1;
6669 if (csbi.dwCursorPosition.Y >= csbi.dwSize.Y)
6670 csbi.dwCursorPosition.Y = csbi.dwSize.Y;
6671 SetConsoleCursorPosition(handle, csbi.dwCursorPosition);
6674 csbi.dwCursorPosition.X += arg1;
6675 if (csbi.dwCursorPosition.X >= csbi.dwSize.X)
6676 csbi.dwCursorPosition.X = csbi.dwSize.X;
6677 SetConsoleCursorPosition(handle, csbi.dwCursorPosition);
6680 csbi.dwCursorPosition.X -= arg1;
6681 if (csbi.dwCursorPosition.X < 0)
6682 csbi.dwCursorPosition.X = 0;
6683 SetConsoleCursorPosition(handle, csbi.dwCursorPosition);
6687 csbi.dwCursorPosition.X = (arg1 > csbi.dwSize.X ? csbi.dwSize.X : arg1) - 1;
6688 SetConsoleCursorPosition(handle, csbi.dwCursorPosition);
6691 csbi.dwCursorPosition.Y = (arg1 > csbi.dwSize.Y ? csbi.dwSize.Y : arg1) - 1;
6692 SetConsoleCursorPosition(handle, csbi.dwCursorPosition);
6696 pos.Y = (arg1 > csbi.dwSize.Y ? csbi.dwSize.Y : arg1) - 1;
6697 if (count < 2 || (arg1 = seq[1]) <= 0) arg1 = 1;
6698 pos.X = (arg1 > csbi.dwSize.X ? csbi.dwSize.X : arg1) - 1;
6699 SetConsoleCursorPosition(handle, pos);
6704 FillConsoleOutputCharacterW(handle, L
' ',
6705 csbi.dwSize.X * (csbi.dwSize.Y - csbi.dwCursorPosition.Y) - csbi.dwCursorPosition.X,
6706 csbi.dwCursorPosition, &written);
6710 pos.Y = csbi.dwCursorPosition.Y;
6711 FillConsoleOutputCharacterW(handle, L
' ',
6712 csbi.dwSize.X * csbi.dwCursorPosition.Y + csbi.dwCursorPosition.X,
6718 FillConsoleOutputCharacterW(handle, L
' ', csbi.dwSize.X * csbi.dwSize.Y, pos, &written);
6725 FillConsoleOutputCharacterW(handle, L
' ', csbi.dwSize.X - csbi.dwCursorPosition.X, csbi.dwCursorPosition, &written);
6729 pos.Y = csbi.dwCursorPosition.Y;
6730 FillConsoleOutputCharacterW(handle, L
' ', csbi.dwCursorPosition.X, pos, &written);
6734 pos.Y = csbi.dwCursorPosition.Y;
6735 FillConsoleOutputCharacterW(handle, L
' ', csbi.dwSize.X, pos, &written);
6743 SetConsoleCursorPosition(handle, s->
vt100.
saved);
6746 if (count >= 2 && seq[0] == -1 && seq[1] == 25) {
6747 CONSOLE_CURSOR_INFO cci;
6748 GetConsoleCursorInfo(handle, &cci);
6749 cci.bVisible =
TRUE;
6750 SetConsoleCursorInfo(handle, &cci);
6754 if (count >= 2 && seq[0] == -1 && seq[1] == 25) {
6755 CONSOLE_CURSOR_INFO cci;
6756 GetConsoleCursorInfo(handle, &cci);
6757 cci.bVisible =
FALSE;
6758 SetConsoleCursorInfo(handle, &cci);
6768 const WCHAR *ptr = *ptrp;
6769 long rest,
len = *lenp;
6773 rest = *lenp - len - 1;
6778 if (len > 0 && *ptr != L
'[')
continue;
6787 rest = *lenp - len - 1;
6788 if (rest > 0) --rest;
6793 if (wc >= L
'0' && wc <= L
'9') {
6796 *seq = (*seq * 10) + (wc - L
'0');
6837 int save_errno =
errno;
6848 if (closesocket(sock) == SOCKET_ERROR) {
6858 memset(ol, 0,
sizeof(*ol));
6866 DWORD low = SetFilePointer((HANDLE)
_osfhnd(fd), 0, &high, method);
6867 #ifndef INVALID_SET_FILE_POINTER 6868 #define INVALID_SET_FILE_POINTER ((DWORD)-1) 6872 if (err != NO_ERROR) {
6878 ol->OffsetHigh = high;
6891 CloseHandle(ol->hEvent);
6894 LONG high = ol->OffsetHigh;
6896 if (low < ol->Offset)
6898 SetFilePointer((HANDLE)
_osfhnd(fd), low, &high, FILE_BEGIN);
6915 BOOL islineinput =
FALSE;
6922 if (_get_osfhandle(fd) == -1) {
6927 return _read(fd, buf, size);
6942 GetConsoleMode((HANDLE)
_osfhnd(fd),&mode);
6943 islineinput = (mode & ENABLE_LINE_INPUT) != 0;
6965 if (!ReadFile((HANDLE)
_osfhnd(fd), buf, len, &read, &ol)) {
6966 err = GetLastError();
6969 if (GetNamedPipeHandleState((HANDLE)
_osfhnd(fd), &state,
NULL,
NULL,
NULL,
NULL, 0) && (state & PIPE_NOWAIT)) {
6978 else if (err != ERROR_IO_PENDING) {
6979 CloseHandle(ol.hEvent);
6980 if (err == ERROR_ACCESS_DENIED)
6982 else if (err == ERROR_BROKEN_PIPE || err == ERROR_HANDLE_EOF) {
6994 if (wait != WAIT_OBJECT_0) {
6995 if (wait == WAIT_OBJECT_0 + 1)
6999 CloseHandle(ol.hEvent);
7000 CancelIo((HANDLE)
_osfhnd(fd));
7005 if (!GetOverlappedResult((HANDLE)
_osfhnd(fd), &ol, &read,
TRUE) &&
7006 (err = GetLastError()) != ERROR_HANDLE_EOF) {
7008 if (err != ERROR_BROKEN_PIPE) {
7012 CloseHandle(ol.hEvent);
7013 CancelIo((HANDLE)
_osfhnd(fd));
7019 err = GetLastError();
7027 buf = (
char *)buf + read;
7028 if (err != ERROR_OPERATION_ABORTED &&
7029 !(isconsole && len == 1 && (!islineinput || *((
char *)buf - 1) ==
'\n')) && size > 0)
7058 if (_get_osfhandle(fd) == -1) {
7064 return _write(fd, buf, size);
7086 if (!WriteFile((HANDLE)
_osfhnd(fd), buf, len, &written, &ol)) {
7087 err = GetLastError();
7088 if (err != ERROR_IO_PENDING) {
7089 CloseHandle(ol.hEvent);
7090 if (err == ERROR_ACCESS_DENIED)
7100 if (wait != WAIT_OBJECT_0) {
7101 if (wait == WAIT_OBJECT_0 + 1)
7105 CloseHandle(ol.hEvent);
7106 CancelIo((HANDLE)
_osfhnd(fd));
7111 if (!GetOverlappedResult((HANDLE)
_osfhnd(fd), &ol, &written,
TRUE)) {
7113 CloseHandle(ol.hEvent);
7114 CancelIo((HANDLE)
_osfhnd(fd));
7123 if (written == len) {
7124 buf = (
const char *)buf + len;
7129 size_t newlen = len / 2;
7131 size += len - newlen;
7149 DWORD dwMode, reslen;
7153 const WCHAR *ptr, *next;
7158 if (!GetConsoleMode(handle, &dwMode))
7176 if (!ptr)
return -1
L;
7185 if (!WriteConsoleW(handle, ptr, len, &reslen,
NULL))
7190 long curlen =
constat_parse(handle, s, (next = ptr, &next), &len);
7191 reslen += next - ptr;
7194 if (!WriteConsoleW(handle, ptr, curlen, &written,
NULL)) {
7195 reslen = (
DWORD)-1L;
7203 if (wbuffer)
free(wbuffer);
7204 return (
long)reslen;
7213 tmp.QuadPart = ((LONG_LONG)time + (LONG_LONG)((1970-1601)*365.2425) * 24 * 60 * 60) * 10 * 1000 * 1000;
7214 ft->dwLowDateTime = tmp.LowPart;
7215 ft->dwHighDateTime = tmp.HighPart;
7224 FILETIME atime, mtime;
7225 struct stati64 stat;
7241 GetSystemTimeAsFileTime(&atime);
7246 const DWORD attr = GetFileAttributesW(path);
7247 if (attr != (
DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY))
7248 SetFileAttributesW(path, attr & ~FILE_ATTRIBUTE_READONLY);
7250 if (hFile == INVALID_HANDLE_VALUE) {
7255 if (!SetFileTime(hFile,
NULL, &atime, &mtime)) {
7261 if (attr != (
DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY))
7262 SetFileAttributesW(path, attr);
7277 ret =
wutime(wpath, times);
7291 ret =
wutime(wpath, times);
7305 ret = _wchdir(wpath);
7317 if (CreateDirectoryW(wpath,
NULL) ==
FALSE) {
7321 if (_wchmod(wpath, mode) == -1) {
7322 RemoveDirectoryW(wpath);
7339 ret =
wmkdir(wpath, mode);
7353 ret =
wmkdir(wpath, mode);
7364 const DWORD attr = GetFileAttributesW(wpath);
7365 if (attr != (
DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
7366 SetFileAttributesW(wpath, attr & ~FILE_ATTRIBUTE_READONLY);
7368 if (RemoveDirectoryW(wpath) ==
FALSE) {
7371 if (attr != (
DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
7372 SetFileAttributesW(wpath, attr);
7412 const DWORD SYMLINKD = FILE_ATTRIBUTE_REPARSE_POINT|FILE_ATTRIBUTE_DIRECTORY;
7414 const DWORD attr = GetFileAttributesW(path);
7415 if (attr == (
DWORD)-1) {
7417 else if ((attr & SYMLINKD) == SYMLINKD) {
7418 ret = RemoveDirectoryW(path);
7421 if (attr & FILE_ATTRIBUTE_READONLY) {
7422 SetFileAttributesW(path, attr & ~FILE_ATTRIBUTE_READONLY);
7424 ret = DeleteFileW(path);
7429 if (attr != (
DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
7430 SetFileAttributesW(path, attr);
7474 ret = _wchmod(wpath, mode);
7483 typedef BOOL (WINAPI *set_file_information_by_handle_func)
7484 (HANDLE, int,
void*,
DWORD);
7485 static set_file_information_by_handle_func set_file_info =
7486 (set_file_information_by_handle_func)-1;
7490 LARGE_INTEGER CreationTime;
7491 LARGE_INTEGER LastAccessTime;
7492 LARGE_INTEGER LastWriteTime;
7493 LARGE_INTEGER ChangeTime;
7494 DWORD FileAttributes;
7495 } info = {{{0}}, {{0}}, {{0}},};
7496 HANDLE h = (HANDLE)_get_osfhandle(fd);
7498 if (h == INVALID_HANDLE_VALUE) {
7502 if (set_file_info == (set_file_information_by_handle_func)-1) {
7503 set_file_info = (set_file_information_by_handle_func)
7506 if (!set_file_info) {
7511 info.FileAttributes = FILE_ATTRIBUTE_NORMAL;
7512 if (!(mode & 0200)) info.FileAttributes |= FILE_ATTRIBUTE_READONLY;
7513 if (!set_file_info(h, 0, &info,
sizeof(info))) {
7527 if (_get_osfhandle(fd) == -1) {
7530 if (!GetConsoleMode((HANDLE)
_osfhnd(fd), &mode)) {
7537 #if defined(_MSC_VER) && RUBY_MSVCRT_VERSION <= 60 7538 extern long _ftol(
double);
7548 _ftol2_sse(
double d)
7559 int *ip = (
int *)(&x + 1) - 1;
7568 typedef char *(WSAAPI inet_ntop_t)(
int,
void *,
char *,
size_t);
7569 static inet_ntop_t *pInetNtop = (inet_ntop_t *)-1;
7570 if (pInetNtop == (inet_ntop_t *)-1)
7573 return pInetNtop(af, (
void *)addr, numaddr, numaddr_len);
7577 memcpy(&in.s_addr, addr,
sizeof(in.s_addr));
7578 snprintf(numaddr, numaddr_len,
"%s", inet_ntoa(in));
7587 typedef int (WSAAPI inet_pton_t)(int,
const char*,
void *);
7588 static inet_pton_t *pInetPton = (inet_pton_t *)-1;
7589 if (pInetPton == (inet_pton_t *)-1)
7592 return pInetPton(af, src, dst);
7604 #if RUBY_MSVCRT_VERSION < 80 && !defined(HAVE__GMTIME64_S) 7611 if (!FileTimeToSystemTime(&ft, st))
return -1;
7619 int y = st->wYear, m = st->wMonth, d = st->wDay;
7620 t->tm_sec = st->wSecond;
7621 t->tm_min = st->wMinute;
7622 t->tm_hour = st->wHour;
7623 t->tm_mday = st->wDay;
7624 t->tm_mon = st->wMonth - 1;
7625 t->tm_year = y - 1900;
7626 t->tm_wday = st->wDayOfWeek;
7634 d += 31 + 28 + (!(y % 4) && ((y % 100) || !(y % 400)));
7635 d += ((m - 3) * 153 + 2) / 5;
7645 TIME_ZONE_INFORMATION stdtz;
7648 if (!SystemTimeToTzSpecificLocalTime(tz, gst, lst))
return -1;
7650 GetTimeZoneInformation(&stdtz);
7653 if (tz->StandardBias == tz->DaylightBias)
return 0;
7654 if (!tz->StandardDate.wMonth)
return 0;
7655 if (!tz->DaylightDate.wMonth)
return 0;
7656 if (tz != &stdtz) stdtz = *tz;
7658 stdtz.StandardDate.wMonth = stdtz.DaylightDate.wMonth = 0;
7659 if (!SystemTimeToTzSpecificLocalTime(&stdtz, gst, &sst))
return 0;
7660 if (lst->wMinute == sst.wMinute && lst->wHour == sst.wHour)
7666 #ifdef HAVE__GMTIME64_S 7667 # ifndef HAVE__LOCALTIME64_S 7669 # define HAVE__LOCALTIME64_S 1 7671 # ifndef MINGW_HAS_SECURE_API 7672 _CRTIMP errno_t __cdecl _gmtime64_s(
struct tm* tm,
const __time64_t *time);
7673 _CRTIMP errno_t __cdecl _localtime64_s(
struct tm* tm,
const __time64_t *time);
7675 # define gmtime_s _gmtime64_s 7676 # define localtime_s _localtime64_s 7689 #if RUBY_MSVCRT_VERSION >= 80 || defined(HAVE__GMTIME64_S) 7690 e = gmtime_s(rp, tp);
7691 if (e != 0)
goto error;
7713 #if RUBY_MSVCRT_VERSION >= 80 || defined(HAVE__LOCALTIME64_S) 7714 e = localtime_s(rp, tp);
7718 SYSTEMTIME gst, lst;
7732 int len =
sizeof(tmp);
7733 int r = getsockopt((SOCKET)h, SOL_SOCKET, SO_DEBUG, (
char *)&tmp, &len);
7734 if (r != SOCKET_ERROR || WSAGetLastError() != WSAENOTSOCK) {
7737 flags &= ~O_NONBLOCK;
7765 #if !defined(__MINGW64__) && defined(__MINGW64_VERSION_MAJOR) 7771 rb_w32_pow(
double x,
double y)
7775 unsigned int default_control = _controlfp(0, 0);
7776 _controlfp(_PC_64, _MCW_PC);
7779 _controlfp(default_control, _MCW_PC);
7786 #if RUBY_MSVCRT_VERSION < 120 struct tm * localtime_r(const time_t *tp, struct tm *rp)
static WORD constat_attr(int count, const int *seq, WORD attr, WORD default_attr, int *reverse)
static const char * NTLoginName
void setnetent(int stayopen)
rb_pid_t rb_w32_uspawn(int mode, const char *cmd, const char *prog)
static void regulate_path(WCHAR *path)
static int free_conlist(st_data_t key, st_data_t val, st_data_t arg)
#define ENCINDEX_US_ASCII
static rb_pid_t w32_aspawn_flags(int mode, const char *prog, char *const *argv, DWORD flags, UINT cp)
int rb_w32_set_nonblock(int fd)
static DWORD WINAPI get_final_path_unknown(HANDLE f, WCHAR *buf, DWORD len, DWORD flag)
static struct ChildRecord * FindFreeChildSlot(void)
char * rb_w32_ugetenv(const char *name)
rb_pid_t rb_w32_getppid(void)
rb_pid_t rb_w32_getpid(void)
static time_t filetime_to_unixtime(const FILETIME *ft)
uintptr_t(* func)(uintptr_t self, int argc, uintptr_t *argv)
int rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout)
int rb_w32_map_errno(DWORD winerr)
static void init_stdhandle(void)
size_t strlen(const char *)
#define rb_w32_stati64(path, st)
int rb_w32_wait_events(HANDLE *events, int num, DWORD timeout)
int rb_w32_access(const char *path, int mode)
#define CSIDL_LOCAL_APPDATA
int ruby_brace_glob_with_enc(const char *str, int flags, ruby_glob_func *func, VALUE arg, rb_encoding *enc)
static int dupfd(HANDLE hDup, int flags, int minfd)
struct servent *WSAAPI rb_w32_getservbyport(int port, const char *proto)
int rb_w32_umkdir(const char *path, int mode)
EXTERN_C _CRTIMP ioinfo * __pioinfo[]
STATIC_ASSERT(std_handle,(STD_OUTPUT_HANDLE-STD_INPUT_HANDLE)==(STD_ERROR_HANDLE-STD_OUTPUT_HANDLE))
static int is_command_com(const char *interp)
void rb_w32_fd_dup(rb_fdset_t *dst, const rb_fdset_t *src)
static int max(int a, int b)
#define ENCINDEX_UTF_16LE
static void StartSockets(void)
static FARPROC get_wsa_extension_function(SOCKET s, GUID *guid)
#define access(path, mode)
int rb_w32_pipe(int fds[2])
int rb_w32_wopen(const WCHAR *file, int oflag,...)
static ioinfo * _pioinfo(int)
static void get_version(void)
static int compare(const struct timeval *t1, const struct timeval *t2)
ssize_t rb_w32_read(int fd, void *buf, size_t size)
VALUE rb_str_cat(VALUE, const char *, long)
static int w32_wopen(const WCHAR *file, int oflag, int perm)
struct constat::@212 vt100
static rb_pid_t poll_child_status(struct ChildRecord *child, int *stat_loc)
static int NtSocketsInitialized
int WSAAPI rb_w32_connect(int s, const struct sockaddr *addr, int addrlen)
DIR * rb_w32_uopendir(const char *filename)
int clock_getres(clockid_t clock_id, struct timespec *sp)
void rb_write_error2(const char *, long)
int rb_w32_io_cancelable_p(int fd)
void rb_w32_rewinddir(DIR *dirp)
static DWORD WINAPI get_final_path_fail(HANDLE f, WCHAR *buf, DWORD len, DWORD flag)
static void stati64_set_inode(BY_HANDLE_FILE_INFORMATION *pinfo, struct stati64 *st)
int rb_w32_ulchown(const char *path, int owner, int group)
static unsigned fileattr_to_unixmode(DWORD attr, const WCHAR *path)
void rb_w32_fdset(int fd, fd_set *set)
int rb_w32_truncate(const char *path, off_t length)
static void constat_apply(HANDLE handle, struct constat *s, WCHAR w)
static st_table * socklist
int rb_w32_unwrap_io_handle(int fd)
static int reparse_symlink(const WCHAR *path, rb_w32_reparse_buffer_t *rp, size_t size)
int WSAAPI rb_w32_bind(int s, const struct sockaddr *addr, int addrlen)
ssize_t rb_w32_ureadlink(const char *path, char *buf, size_t bufsize)
static int is_batch(const char *cmd)
struct servent *WSAAPI rb_w32_getservbyname(const char *name, const char *proto)
DWORD(WINAPI * get_final_path_func)(HANDLE, WCHAR *, DWORD, DWORD)
#define INVALID_SET_FILE_POINTER
uintptr_t(* asynchronous_func_t)(uintptr_t self, int argc, uintptr_t *argv)
SSL_METHOD *(* func)(void)
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
rb_pid_t rb_w32_aspawn(int mode, const char *prog, char *const *argv)
static int extract_fd(rb_fdset_t *dst, fd_set *src, int(*func)(SOCKET))
int WSAAPI rb_w32_accept(int s, struct sockaddr *addr, int *addrlen)
void freeifaddrs(struct ifaddrs *ifp)
static int is_socket(SOCKET)
static int wmkdir(const WCHAR *wpath, int mode)
static long filetime_to_clock(FILETIME *ft)
#define COPY_STAT(src, dest, size_cast)
static int is_invalid_handle(SOCKET sock)
void rb_w32_seekdir(DIR *dirp, long loc)
int rb_w32_urmdir(const char *path)
static WCHAR * translate_wchar(WCHAR *p, int from, int to)
#define STRNDUPV(ptr, v, src, len)
static int wlstati64(const WCHAR *path, struct stati64 *st)
static void exit_handler(void)
struct _NtCmdLineElement * next
#define IO_REPARSE_TAG_SYMLINK
static NtCmdLineElement ** cmdglob(NtCmdLineElement *patt, NtCmdLineElement **tail, UINT cp, rb_encoding *enc)
int rb_w32_fclose(FILE *fp)
int rb_w32_open(const char *file, int oflag,...)
struct sockaddr * ifa_addr
#define msghdr_to_wsamsg(msg, wsamsg)
struct protoent * getprotoent(void)
static FARPROC get_proc_address(const char *module, const char *func, HANDLE *mh)
static int socklist_insert(SOCKET sock, int flag)
char * rb_w32_conv_from_wstr(const WCHAR *wstr, long *lenp, rb_encoding *enc)
VALUE rb_f_notimplement(int argc, const VALUE *argv, VALUE obj)
ssize_t rb_w32_write(int fd, const void *buf, size_t size)
static BOOL win32_direct_conv(const WCHAR *file, const WCHAR *alt, struct direct *entry, const void *enc)
#define filecp_to_wstr(str, plen)
VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts)
int WSAAPI rb_w32_sendto(int fd, const char *buf, int len, int flags, const struct sockaddr *to, int tolen)
static int w32_lstati64(const char *path, struct stati64 *st, UINT cp)
static SOCKET open_ifs_socket(int af, int type, int protocol)
const char *WSAAPI rb_w32_inet_ntop(int af, const void *addr, char *numaddr, size_t numaddr_len)
RUBY_EXTERN void * memmove(void *, const void *, size_t)
int recvmsg(int fd, struct msghdr *msg, int flags)
struct protoent *WSAAPI rb_w32_getprotobynumber(int num)
static const char szInternalCmds[][InternalCmdsMax+2]
int rb_w32_wrap_io_handle(HANDLE h, int flags)
static BOOL get_special_folder(int n, WCHAR *buf, size_t len)
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
static DWORD stati64_set_inode_handle(HANDLE h, struct stati64 *st)
int rb_w32_ustati64(const char *path, struct stati64 *st)
static uintptr_t flock_winnt(uintptr_t self, int argc, uintptr_t *argv)
#define FSCTL_GET_REPARSE_POINT
struct rb_w32_reparse_buffer_t::@206::@208 SymbolicLinkReparseBuffer
static const WCHAR namespace_prefix[]
int fcntl(int fd, int cmd,...)
void * ruby_xcalloc(size_t n, size_t size)
int WSAAPI rb_w32_socket(int af, int type, int protocol)
static int internal_cmd_match(const char *cmdname, int nt)
#define wstr_to_utf8(str, plen)
#define MEMZERO(p, type, n)
#define FILE_FILENO(stream)
int rb_enc_to_index(rb_encoding *enc)
int rb_w32_lstati64(const char *path, struct stati64 *st)
unsigned long long uint64_t
VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc)
static HANDLE open_special(const WCHAR *path, DWORD access, DWORD flags)
struct ifaddrs * ifa_next
char * rb_w32_getenv(const char *name)
static DIR * w32_wopendir(const WCHAR *wpath)
rb_pid_t waitpid(rb_pid_t pid, int *stat_loc, int options)
static int is_pipe(SOCKET sock)
#define END_FOREACH_CHILD
#define SYMBOLIC_LINK_FLAG_DIRECTORY
DWORD(WINAPI * cilnA_t)(const NET_LUID *, char *, size_t)
char * ruby_strdup(const char *)
#define wstr_to_filecp(str, plen)
int rb_w32_stat(const char *path, struct stat *st)
int rb_w32_uaccess(const char *path, int mode)
#define ECONV_INVALID_REPLACE
long rb_w32_telldir(DIR *dirp)
static ssize_t w32_readlink(UINT cp, const char *path, char *buf, size_t bufsize)
static rb_pid_t w32_spawn(int mode, const char *cmd, const char *prog, UINT cp)
int rb_w32_fstat(int fd, struct stat *st)
int rb_econv_has_convpath_p(const char *from_encoding, const char *to_encoding)
static int copy_fd(fd_set *dst, fd_set *src)
static void CloseChildHandle(struct ChildRecord *child)
static int winnt_stat(const WCHAR *path, struct stati64 *st)
int rb_w32_uopen(const char *file, int oflag,...)
static char * w32_getenv(const char *name, UINT cp)
#define IOINFO_ARRAY_ELTS
int rb_w32_uchdir(const char *path)
void rb_w32_fd_copy(rb_fdset_t *dst, const fd_set *src, int max)
int link(const char *from, const char *to)
int fchmod(int fd, int mode)
int WSAAPI rb_w32_ioctlsocket(int s, long cmd, u_long *argp)
struct netent * getnetbyname(const char *name)
static int wutime(const WCHAR *path, const struct utimbuf *times)
static HANDLE open_dir_handle(const WCHAR *filename, WIN32_FIND_DATAW *fd)
int rb_w32_isatty(int fd)
int rb_w32_sleep(unsigned long msec)
int rb_w32_rename(const char *from, const char *to)
static get_final_path_func get_final_path
#define ALLOCV_N(type, v, n)
int clock_gettime(clockid_t clock_id, struct timespec *sp)
UINT rb_w32_system_tmpdir(WCHAR *path, UINT len)
int rb_w32_select_with_thread(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *timeout, void *th)
#define MAKE_SOCKDATA(af, fl)
#define rb_acrt_lowio_lock_fh(i)
int rb_w32_utime(const char *path, const struct utimbuf *times)
#define MEMCPY(p1, p2, type, n)
static int socklist_lookup(SOCKET sock, int *flagp)
rb_pid_t rb_w32_aspawn_flags(int mode, const char *prog, char *const *argv, DWORD flags)
static int winnt_lstat(const WCHAR *path, struct stati64 *st)
void sethostent(int stayopen)
struct servent * getservent(void)
static int check_spawn_mode(int mode)
static WCHAR * skipspace(WCHAR *ptr)
ssize_t readlink(const char *path, char *buf, size_t bufsize)
static cilnA_t pConvertInterfaceLuidToNameA
static void init_env(void)
static struct @210 errmap[]
static int filetime_to_timeval(const FILETIME *ft, struct timeval *tv)
static int is_not_socket(SOCKET sock)
static BOOL ruby_direct_conv(const WCHAR *file, const WCHAR *alt, struct direct *entry, const void *enc)
#define REALLOC_N(var, type, n)
static int do_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *timeout)
char * rb_w32_wstr_to_mbstr(UINT cp, const WCHAR *wstr, int clen, long *plen)
static int w32_stati64(const char *path, struct stati64 *st, UINT cp)
int WSAAPI rb_w32_getpeername(int s, struct sockaddr *addr, int *addrlen)
VALUE rb_sprintf(const char *format,...)
void setservent(int stayopen)
rb_pid_t rb_w32_spawn(int mode, const char *cmd, const char *prog)
DIR * rb_w32_opendir(const char *filename)
static long constat_parse(HANDLE h, struct constat *s, const WCHAR **ptrp, long *lenp)
static int has_redirection(const char *, UINT)
void rb_w32_sysinit(int *argc, char ***argv)
void rb_fatal(const char *fmt,...)
static struct ChildRecord * FindChildSlot(rb_pid_t pid)
static cigl_t pConvertInterfaceGuidToLuid
#define rb_strlen_lit(str)
static char * translate_char(char *p, int from, int to, UINT cp)
VALUE(*const rb_f_notimplement_)(int, const VALUE *, VALUE)
int WSAAPI rb_w32_shutdown(int s, int how)
VALUE rb_str_vcatf(VALUE, const char *, va_list)
static int console_emulator_p(void)
static int finish_overlapped_socket(BOOL input, SOCKET s, WSAOVERLAPPED *wol, int result, DWORD *len, DWORD size)
WCHAR * rb_w32_home_dir(void)
static CRITICAL_SECTION select_mutex
int ruby_glob_func(const char *, VALUE, void *)
struct netent * getnetent(void)
void setprotoent(int stayopen)
static int unixtime_to_systemtime(const time_t t, SYSTEMTIME *st)
int sendmsg(int fd, const struct msghdr *msg, int flags)
int ioctl(int i, int u,...)
ONIG_EXTERN const OnigEncodingType OnigEncodingUTF_8
unsigned char buf[MIME_BUF_SIZE]
static int rb_chsize(HANDLE h, off_t size)
struct tm * gmtime_r(const time_t *tp, struct tm *rp)
static int join_argv(char *cmd, char *const *argv, BOOL escape, UINT cp, int backslash)
int flock(int fd, int oper)
int __cdecl gettimeofday(struct timeval *tv, struct timezone *tz)
static int options(unsigned char *cp)
static int unixtime_to_filetime(time_t time, FILETIME *ft)
char * strchr(char *, char)
struct protoent *WSAAPI rb_w32_getprotobyname(const char *name)
#define utf8_to_wstr(str, plen)
int rb_w32_mkdir(const char *path, int mode)
RUBY_EXTERN size_t strlcpy(char *, const char *, size_t)
int WSAAPI rb_w32_inet_pton(int af, const char *src, void *dst)
int rb_w32_unlink(const char *path)
int memcmp(const void *s1, const void *s2, size_t len)
int WSAAPI rb_w32_gethostname(char *name, int len)
static int insert(const char *path, VALUE vinfo, void *enc)
static int isUNCRoot(const WCHAR *path)
int rb_w32_ulstati64(const char *path, struct stati64 *st)
int chown(const char *path, int owner, int group)
static rb_pid_t child_result(struct ChildRecord *child, int mode)
int rb_w32_fstati64(int fd, struct stati64 *st)
static int internal_match(const void *key, const void *elem)
#define rb_w32_reparse_buffer_size(n)
int rb_w32_usymlink(const char *src, const char *link)
char * rb_w32_strerror(int e)
int rb_w32_time_subtract(struct timeval *rest, const struct timeval *wait)
static int is_internal_cmd(const char *cmd, int nt)
int rb_w32_uchown(const char *path, int owner, int group)
static DWORD stati64_handle(HANDLE h, struct stati64 *st)
register unsigned int len
int rb_w32_rmdir(const char *path)
int WSAAPI rb_w32_listen(int s, int backlog)
int kill(int pid, int sig)
void * ruby_xmalloc(size_t size)
static void constat_delete(HANDLE h)
#define ECONV_UNDEF_REPLACE
#define ENCODING_GET(obj)
static int w32_symlink(UINT cp, const char *src, const char *link)
uintptr_t rb_w32_asynchronize(asynchronous_func_t func, uintptr_t self, int argc, uintptr_t *argv, uintptr_t intrval)
static int wstati64(const WCHAR *path, struct stati64 *st)
static struct ChildRecord * FindChildSlotByHandle(HANDLE h)
static struct direct * readdir_internal(DIR *dirp, BOOL(*conv)(const WCHAR *, const WCHAR *, struct direct *, const void *), const void *enc)
char ** rb_w32_get_environ(void)
rb_pid_t rb_w32_uaspawn_flags(int mode, const char *prog, char *const *argv, DWORD flags)
#define set_new_std_fd(newfd)
void rb_w32_closedir(DIR *dirp)
static int wlink(const WCHAR *from, const WCHAR *to)
static int stat_by_find(const WCHAR *path, struct stati64 *st)
VALUE rb_w32_special_folder(int type)
static int socklist_delete(SOCKET *sockp, int *flagp)
int rb_w32_uchmod(const char *path, int mode)
static DWORD WINAPI call_asynchronous(PVOID argp)
int WSAAPI rb_w32_send(int fd, const char *buf, int len, int flags)
static int wrmdir(const WCHAR *wpath)
static WCHAR * name_for_stat(WCHAR *buf, const WCHAR *path)
static struct constat * constat_handle(HANDLE h)
int rb_w32_reparse_symlink_p(const WCHAR *path)
#define _set_osfhnd(fh, osfh)
static int systemtime_to_localtime(TIME_ZONE_INFORMATION *tz, SYSTEMTIME *gst, SYSTEMTIME *lst)
struct hostent *WSAAPI rb_w32_gethostbyname(const char *name)
static int w32_cmdvector(const WCHAR *, char ***, UINT, rb_encoding *)
int symlink(const char *src, const char *link)
RUBY_EXTERN char * strerror(int)
static int is_console(SOCKET)
static int is_readable_pipe(SOCKET sock)
static void str2guid(const char *str, GUID *guid)
int socketpair(int af, int type, int protocol, int *sv)
int WSAAPI rb_w32_getsockname(int fd, struct sockaddr *addr, int *addrlen)
rb_encoding * rb_filesystem_encoding(void)
SOCKET rb_w32_get_osfhandle(int fh)
int rb_w32_uutime(const char *path, const struct utimbuf *times)
struct _NtCmdLineElement NtCmdLineElement
#define set_env_val(vname)
int WSAAPI rb_w32_recv(int fd, char *buf, int len, int flags)
static int check_if_wdir(const WCHAR *wfile)
static int setfl(SOCKET sock, int arg)
rb_pid_t rb_w32_uaspawn(int mode, const char *prog, char *const *argv)
static int path_drive(const WCHAR *path)
int getifaddrs(struct ifaddrs **ifap)
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
int rb_w32_is_socket(int fd)
static int wrename(const WCHAR *oldpath, const WCHAR *newpath)
long rb_w32_write_console(uintptr_t strarg, int fd)
RUBY_EXTERN size_t strlcat(char *, const char *, size_t)
#define COMMON_LVB_UNDERSCORE
RUBY_EXTERN int dup2(int, int)
static void move_to_next_entry(DIR *dirp)
static void systemtime_to_tm(const SYSTEMTIME *st, struct tm *t)
#define constat_attr_color_reverse(attr)
#define rb_acrt_lowio_unlock_fh(i)
char * rb_w32_getcwd(char *buffer, int size)
#define yield_until(condition)
static int setup_overlapped(OVERLAPPED *ol, int fd, int iswrite)
static int overlapped_socket_io(BOOL input, int fd, char *buf, int len, int flags, struct sockaddr *addr, int *addrlen)
struct netent * getnetbyaddr(long net, int type)
static struct ChildRecord * CreateChild(const WCHAR *, const WCHAR *, SECURITY_ATTRIBUTES *, HANDLE, HANDLE, HANDLE, DWORD)
int WSAAPI rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *timeout)
int rb_w32_ulink(const char *from, const char *to)
int WSAAPI rb_w32_recvfrom(int fd, char *buf, int len, int flags, struct sockaddr *from, int *fromlen)
int rb_w32_dup2(int oldfd, int newfd)
static int socketpair_internal(int af, int type, int protocol, SOCKET *sv)
int WSAAPI rb_w32_getsockopt(int s, int level, int optname, char *optval, int *optlen)
int lchown(const char *path, int owner, int group)
int rb_w32_urename(const char *from, const char *to)
static void finish_overlapped(OVERLAPPED *ol, int fd, DWORD size)
struct direct * rb_w32_readdir(DIR *dirp, rb_encoding *enc)
void rb_w32_free_environ(char **env)
int WSAAPI rb_w32_setsockopt(int s, int level, int optname, const char *optval, int optlen)
static OSVERSIONINFO osver
DWORD(WINAPI * cigl_t)(const GUID *, NET_LUID *)
WCHAR * rb_w32_mbstr_to_wstr(UINT cp, const char *str, int clen, long *plen)
static int w32_truncate(const char *path, off_t length, UINT cp)
int rb_w32_fdisset(int fd, fd_set *set)
static int rb_w32_open_osfhandle(intptr_t osfhandle, int flags)
int rb_w32_uunlink(const char *path)
int rb_w32_utruncate(const char *path, off_t length)
static int is_readable_console(SOCKET sock)
char rb_w32_fd_is_text(int fd)
static int eq(VALUE x, VALUE y)
static ULONG(STDMETHODCALLTYPE AddRef)(IDispatch __RPC_FAR *This)
int rb_w32_check_interrupt(void *)
int rb_w32_read_reparse_point(const WCHAR *path, rb_w32_reparse_buffer_t *rp, size_t bufsize, WCHAR **result, DWORD *len)
int rb_w32_times(struct tms *tmbuf)
static DWORD get_attr_vsn(const WCHAR *path, DWORD *atts, DWORD *vsn)
void rb_w32_fdclr(int fd, fd_set *set)
int select(int num_fds, fd_set *in_fds, fd_set *out_fds, fd_set *ex_fds, struct timeval *timeout)
struct hostent *WSAAPI rb_w32_gethostbyaddr(const char *addr, int len, int type)
int rb_w32_ftruncate(int fd, off_t length)
struct rb_w32_reparse_buffer_t::@206::@209 MountPointReparseBuffer
static int check_valid_dir(const WCHAR *path)
static st_table * conlist
#define _set_osflags(fh, flags)
rb_encoding * rb_enc_from_index(int index)
static void constat_reset(HANDLE h)
static int wunlink(const WCHAR *path)