50 #define isdirsep(x) ((x) == '/' || (x) == '\\')
57 #if defined __BORLANDC__
58 # define _filbuf _fgetc
59 # define _flsbuf _fputc
60 # define enough_to_get(n) (--(n) >= 0)
61 # define enough_to_put(n) (++(n) < 0)
63 # define enough_to_get(n) (--(n) >= 0)
64 # define enough_to_put(n) (--(n) >= 0)
68 #define Debug(something) something
70 #define Debug(something)
73 #define TO_SOCKET(x) _get_osfhandle(x)
79 static int wstati64(
const WCHAR *path,
struct stati64 *st);
82 #define RUBY_CRITICAL(expr) do { expr; } while (0)
89 { ERROR_INVALID_FUNCTION, EINVAL },
90 { ERROR_FILE_NOT_FOUND, ENOENT },
91 { ERROR_PATH_NOT_FOUND, ENOENT },
92 { ERROR_TOO_MANY_OPEN_FILES, EMFILE },
93 { ERROR_ACCESS_DENIED, EACCES },
94 { ERROR_INVALID_HANDLE, EBADF },
95 { ERROR_ARENA_TRASHED, ENOMEM },
96 { ERROR_NOT_ENOUGH_MEMORY, ENOMEM },
97 { ERROR_INVALID_BLOCK, ENOMEM },
98 { ERROR_BAD_ENVIRONMENT, E2BIG },
99 { ERROR_BAD_FORMAT, ENOEXEC },
100 { ERROR_INVALID_ACCESS, EINVAL },
101 { ERROR_INVALID_DATA, EINVAL },
102 { ERROR_INVALID_DRIVE, ENOENT },
103 { ERROR_CURRENT_DIRECTORY, EACCES },
104 { ERROR_NOT_SAME_DEVICE, EXDEV },
105 { ERROR_NO_MORE_FILES, ENOENT },
106 { ERROR_WRITE_PROTECT, EROFS },
107 { ERROR_BAD_UNIT, ENODEV },
108 { ERROR_NOT_READY, ENXIO },
109 { ERROR_BAD_COMMAND, EACCES },
110 { ERROR_CRC, EACCES },
111 { ERROR_BAD_LENGTH, EACCES },
113 { ERROR_NOT_DOS_DISK, EACCES },
114 { ERROR_SECTOR_NOT_FOUND, EACCES },
115 { ERROR_OUT_OF_PAPER, EACCES },
116 { ERROR_WRITE_FAULT, EIO },
117 { ERROR_READ_FAULT, EIO },
118 { ERROR_GEN_FAILURE, EACCES },
119 { ERROR_LOCK_VIOLATION, EACCES },
120 { ERROR_SHARING_VIOLATION, EACCES },
121 { ERROR_WRONG_DISK, EACCES },
122 { ERROR_SHARING_BUFFER_EXCEEDED, EACCES },
123 { ERROR_BAD_NETPATH, ENOENT },
124 { ERROR_NETWORK_ACCESS_DENIED, EACCES },
125 { ERROR_BAD_NET_NAME, ENOENT },
126 { ERROR_FILE_EXISTS, EEXIST },
127 { ERROR_CANNOT_MAKE, EACCES },
128 { ERROR_FAIL_I24, EACCES },
129 { ERROR_INVALID_PARAMETER, EINVAL },
130 { ERROR_NO_PROC_SLOTS, EAGAIN },
131 { ERROR_DRIVE_LOCKED, EACCES },
132 { ERROR_BROKEN_PIPE, EPIPE },
133 { ERROR_DISK_FULL, ENOSPC },
134 { ERROR_INVALID_TARGET_HANDLE, EBADF },
135 { ERROR_INVALID_HANDLE, EINVAL },
136 { ERROR_WAIT_NO_CHILDREN, ECHILD },
137 { ERROR_CHILD_NOT_COMPLETE, ECHILD },
138 { ERROR_DIRECT_ACCESS_HANDLE, EBADF },
139 { ERROR_NEGATIVE_SEEK, EINVAL },
140 { ERROR_SEEK_ON_DEVICE, EACCES },
141 { ERROR_DIR_NOT_EMPTY, ENOTEMPTY },
142 { ERROR_DIRECTORY, ENOTDIR },
143 { ERROR_NOT_LOCKED, EACCES },
144 { ERROR_BAD_PATHNAME, ENOENT },
145 { ERROR_MAX_THRDS_REACHED, EAGAIN },
146 { ERROR_LOCK_FAILED, EACCES },
147 { ERROR_ALREADY_EXISTS, EEXIST },
148 { ERROR_INVALID_STARTING_CODESEG, ENOEXEC },
149 { ERROR_INVALID_STACKSEG, ENOEXEC },
150 { ERROR_INVALID_MODULETYPE, ENOEXEC },
151 { ERROR_INVALID_EXE_SIGNATURE, ENOEXEC },
152 { ERROR_EXE_MARKED_INVALID, ENOEXEC },
153 { ERROR_BAD_EXE_FORMAT, ENOEXEC },
154 { ERROR_ITERATED_DATA_EXCEEDS_64k,ENOEXEC },
155 { ERROR_INVALID_MINALLOCSIZE, ENOEXEC },
156 { ERROR_DYNLINK_FROM_INVALID_RING,ENOEXEC },
157 { ERROR_IOPL_NOT_ENABLED, ENOEXEC },
158 { ERROR_INVALID_SEGDPL, ENOEXEC },
159 { ERROR_AUTODATASEG_EXCEEDS_64k, ENOEXEC },
160 { ERROR_RING2SEG_MUST_BE_MOVABLE, ENOEXEC },
161 { ERROR_RELOC_CHAIN_XEEDS_SEGLIM, ENOEXEC },
162 { ERROR_INFLOOP_IN_RELOC_CHAIN, ENOEXEC },
163 { ERROR_FILENAME_EXCED_RANGE, ENOENT },
164 { ERROR_NESTING_NOT_ALLOWED, EAGAIN },
165 #ifndef ERROR_PIPE_LOCAL
166 #define ERROR_PIPE_LOCAL 229L
169 { ERROR_BAD_PIPE, EPIPE },
170 { ERROR_PIPE_BUSY, EAGAIN },
171 { ERROR_NO_DATA, EPIPE },
172 { ERROR_PIPE_NOT_CONNECTED, EPIPE },
173 { ERROR_OPERATION_ABORTED, EINTR },
174 { ERROR_NOT_ENOUGH_QUOTA, ENOMEM },
175 { ERROR_MOD_NOT_FOUND, ENOENT },
178 { WSAEACCES, EACCES },
179 { WSAEFAULT, EFAULT },
180 { WSAEINVAL, EINVAL },
181 { WSAEMFILE, EMFILE },
210 { WSAENAMETOOLONG, ENAMETOOLONG },
214 { WSAENOTEMPTY, ENOTEMPTY },
231 for (i = 0; i < (int)(
sizeof(
errmap) /
sizeof(*
errmap)); i++) {
232 if (
errmap[i].winerr == winerr) {
237 if (winerr >= WSABASEERR) {
243 #define map_errno rb_w32_map_errno
253 memset(&
osver, 0,
sizeof(OSVERSIONINFO));
254 osver.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
255 GetVersionEx(&
osver);
263 return osver.dwPlatformId;
271 return osver.dwMajorVersion;
277 #define LK_ERR(f,i) \
282 DWORD err = GetLastError(); \
283 if (err == ERROR_LOCK_VIOLATION || err == ERROR_IO_PENDING) \
284 errno = EWOULDBLOCK; \
285 else if (err == ERROR_NOT_LOCKED) \
288 errno = map_errno(err); \
291 #define LK_LEN ULONG_MAX
299 const HANDLE fh = (HANDLE)
self;
300 const int oper =
argc;
302 memset(&o, 0,
sizeof(o));
316 LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY,
344 static inline WCHAR *
359 if ((
unsigned char)*p == from)
366 #ifndef CSIDL_LOCAL_APPDATA
367 #define CSIDL_LOCAL_APPDATA 28
369 #ifndef CSIDL_COMMON_APPDATA
370 #define CSIDL_COMMON_APPDATA 35
372 #ifndef CSIDL_WINDOWS
373 #define CSIDL_WINDOWS 36
376 #define CSIDL_SYSTEM 37
378 #ifndef CSIDL_PROFILE
379 #define CSIDL_PROFILE 40
389 if (SHGetSpecialFolderLocation(
NULL, n, &pidl) == 0) {
390 f = SHGetPathFromIDListW(pidl, env);
392 alloc->lpVtbl->Free(alloc, pidl);
393 alloc->lpVtbl->Release(alloc);
403 if (p - path == 2 && path[1] == L
':') {
417 h = LoadLibrary(module);
419 h = GetModuleHandle(module);
423 ptr = GetProcAddress(h, func);
437 typedef UINT WINAPI wgetdir_func(WCHAR*, UINT);
441 return (*(wgetdir_func *)ptr)(path, len);
442 return GetWindowsDirectoryW(path, len);
445 #define numberof(array) (sizeof(array) / sizeof(*array))
451 WCHAR path[_MAX_PATH];
462 static const WCHAR temp[] = L
"temp";
469 if (*(p - 1) != L
'/') *p++ = L
'/';
470 if (p - path +
numberof(temp) >= len)
return 0;
471 memcpy(p, temp,
sizeof(temp));
472 return p - path +
numberof(temp) - 1;
479 static const WCHAR TMPDIR[] = L
"TMPDIR";
480 struct {WCHAR
name[6],
eq,
val[_MAX_PATH];} wk;
484 #define set_env_val(vname) do { \
485 typedef char namesizecheck[numberof(wk.name) < numberof(vname) - 1 ? -1 : 1]; \
486 WCHAR *const buf = wk.name + numberof(wk.name) - numberof(vname) + 1; \
487 MEMCPY(buf, vname, WCHAR, numberof(vname) - 1); \
499 if (GetEnvironmentVariableW(L
"HOMEPATH",
env + len,
numberof(
env) - len) || len) {
502 else if (GetEnvironmentVariableW(L
"USERPROFILE",
env,
numberof(
env))) {
552 #if RUBY_MSVCRT_VERSION >= 80
555 invalid_parameter(
const wchar_t *expr,
const wchar_t *
func,
const wchar_t *file,
unsigned int line,
uintptr_t dummy)
560 int ruby_w32_rtc_error;
564 rtc_error_handler(
int e,
const char *src,
int line,
const char *exe,
const char *fmt, ...)
569 if (!ruby_w32_rtc_error)
return 0;
620 if (NtSocketsInitialized) {
626 DeleteCriticalSection(&select_mutex);
627 NtSocketsInitialized = 0;
635 FreeEnvironmentStrings(envarea);
655 version = MAKEWORD(2, 0);
656 if (WSAStartup(version, &retdata))
657 rb_fatal (
"Unable to locate winsock library!\n");
658 if (LOBYTE(retdata.wVersion) != 2)
659 rb_fatal(
"could not find version 2 of winsock dll\n");
661 InitializeCriticalSection(&select_mutex);
663 NtSocketsInitialized = 1;
666 #define MAKE_SOCKDATA(af, fl) ((int)((((int)af)<<4)|((fl)&0xFFFF)))
667 #define GET_FAMILY(v) ((int)(((v)>>4)&0xFFFF))
668 #define GET_FLAGS(v) ((int)((v)&0xFFFF))
710 *sockp = (SOCKET)key;
725 #if RUBY_MSVCRT_VERSION >= 80
726 static void set_pioinfo_extra(
void);
728 _CrtSetReportMode(_CRT_ASSERT, 0);
729 _set_invalid_parameter_handler(invalid_parameter);
730 _RTC_SetErrorFunc(rtc_error_handler);
733 SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOGPFAULTERRORBOX);
767 #define MAXCHILDNUM 256
776 #define FOREACH_CHILD(v) do { \
777 struct ChildRecord* v; \
778 for (v = ChildRecord; v < ChildRecord + sizeof(ChildRecord) / sizeof(ChildRecord[0]); ++v)
779 #define END_FOREACH_CHILD } while (0)
787 if (child->pid == pid) {
800 if (child->hProcess == h) {
824 child->hProcess =
NULL;
894 return strcmp(key, (*(
const char *
const *)elem) + 1);
903 if ((i == 0 || i > 0 &&
isdirsep(interp[i-1])) &&
916 char cmdname[9], *b = cmdname, c;
919 if (!(c = *cmd++))
return 0;
920 }
while (isspace(c));
925 if (b == cmdname +
sizeof(cmdname))
return 0;
928 if (c ==
'.') c = *cmd;
930 case '<':
case '>':
case '|':
932 case '\0':
case ' ':
case '\t':
case '\n':
947 nm = bsearch(cmdname, szInternalCmds,
948 sizeof(szInternalCmds) /
sizeof(*szInternalCmds),
949 sizeof(*szInternalCmds),
951 if (!nm || !(nm[0][0] & (nt ? 2 : 1)))
960 return _get_osfhandle(fh);
969 int len, n, bs, quote;
971 for (t = argv, q = cmd, len = 0; p = *t; t++) {
974 if (!*p || strpbrk(p,
" \t\"'")) {
979 for (bs = 0; *
p; ++
p) {
998 case '<':
case '>':
case '|':
case '^':
999 if (escape && !quote) {
1000 len += (n = p - s) + 1;
1015 len += (n = p - s) + 1;
1020 if (quote) *q++ =
'"';
1032 #ifdef HAVE_SYS_PARAM_H
1033 # include <sys/param.h>
1035 # define MAXPATHLEN 512
1039 #define STRNDUPV(ptr, v, src, len) \
1040 (((char *)memcpy(((ptr) = ALLOCV((v), (len) + 1)), (src), (len)))[len] = 0)
1066 if (mode == P_OVERLAY) {
1067 WaitForSingleObject(child->
hProcess, INFINITE);
1068 GetExitCodeProcess(child->
hProcess, &exitcode);
1077 CreateChild(
const WCHAR *cmd,
const WCHAR *prog, SECURITY_ATTRIBUTES *psa,
1078 HANDLE hInput, HANDLE hOutput, HANDLE hError,
DWORD dwCreationFlags)
1081 STARTUPINFOW aStartupInfo;
1082 PROCESS_INFORMATION aProcessInformation;
1083 SECURITY_ATTRIBUTES sa;
1086 if (!cmd && !prog) {
1098 sa.nLength =
sizeof (SECURITY_ATTRIBUTES);
1099 sa.lpSecurityDescriptor =
NULL;
1100 sa.bInheritHandle =
TRUE;
1104 memset(&aStartupInfo, 0,
sizeof(aStartupInfo));
1105 memset(&aProcessInformation, 0,
sizeof(aProcessInformation));
1106 aStartupInfo.cb =
sizeof(aStartupInfo);
1107 aStartupInfo.dwFlags = STARTF_USESTDHANDLES;
1109 aStartupInfo.hStdInput = hInput;
1112 aStartupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
1115 aStartupInfo.hStdOutput = hOutput;
1118 aStartupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
1121 aStartupInfo.hStdError = hError;
1124 aStartupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
1127 dwCreationFlags |= NORMAL_PRIORITY_CLASS;
1129 if (lstrlenW(cmd) > 32767) {
1136 fRet = CreateProcessW(prog, (WCHAR *)cmd, psa, psa,
1137 psa->bInheritHandle, dwCreationFlags,
NULL,
NULL,
1138 &aStartupInfo, &aProcessInformation);
1147 CloseHandle(aProcessInformation.hThread);
1149 child->
hProcess = aProcessInformation.hProcess;
1150 child->
pid = (rb_pid_t)aProcessInformation.dwProcessId;
1160 if (len <= 4)
return 0;
1162 if (*cmd++ !=
'.')
return 0;
1168 static UINT
filecp(
void);
1169 static WCHAR *
mbstr_to_wstr(UINT,
const char *,
int,
long *);
1170 static char *
wstr_to_mbstr(UINT,
const WCHAR *,
int,
long *);
1171 #define acp_to_wstr(str, plen) mbstr_to_wstr(CP_ACP, str, -1, plen)
1172 #define wstr_to_acp(str, plen) wstr_to_mbstr(CP_ACP, str, -1, plen)
1173 #define filecp_to_wstr(str, plen) mbstr_to_wstr(filecp(), str, -1, plen)
1174 #define wstr_to_filecp(str, plen) wstr_to_mbstr(filecp(), str, -1, plen)
1175 #define utf8_to_wstr(str, plen) mbstr_to_wstr(CP_UTF8, str, -1, plen)
1176 #define wstr_to_utf8(str, plen) wstr_to_mbstr(CP_UTF8, str, -1, plen)
1184 const char *shell =
NULL;
1185 WCHAR *wcmd =
NULL, *wshell =
NULL;
1208 sprintf(tmp,
"%s -c \"%s\"", shell, cmd);
1211 else if ((shell =
getenv(
"COMSPEC")) &&
1216 sprintf(tmp, nt ?
"%s /c \"%s\"" :
"%s /c %s", shell, cmd);
1220 int len = 0, quote = (*cmd ==
'"') ?
'"' : (*cmd ==
'\'') ?
'\'' : 0;
1221 for (prog = cmd + !!quote;; prog =
CharNext(prog)) {
1227 if ((
unsigned char)*prog == quote) {
1228 len = prog++ - cmd - 1;
1233 if (quote)
continue;
1243 shell = p ? p : cmd;
1247 if (
strchr(shell,
' ')) quote = -1;
1248 if (shell == fbuf) {
1251 else if (shell != p &&
strchr(shell,
'/')) {
1258 cmd = p =
ALLOCV(v, len + alen + (quote ? 2 : 0) + 1);
1259 if (quote) *p++ =
'"';
1260 memcpy(p, shell, len);
1262 if (quote) *p++ =
'"';
1263 memcpy(p, prog, alen + 1);
1291 BOOL ntcmd =
FALSE, tmpnt;
1301 if (!prog) prog = argv[0];
1302 if ((shell =
getenv(
"COMSPEC")) &&
1309 if (cmd == prog)
strlcpy(cmd = fbuf, prog,
sizeof(fbuf));
1313 else if (
strchr(prog,
'/')) {
1315 if (len <
sizeof(fbuf))
1316 strlcpy(cmd = fbuf, prog,
sizeof(fbuf));
1324 progs[0] = (
char *)prog;
1327 if (c_switch) len += 3;
1332 if (c_switch)
strlcat(cmd,
" /c", len);
1334 prog = c_switch ? shell : 0;
1374 #define NTGLOB 0x1 // element contains a wildcard
1375 #define NTMALLOC 0x2 // string in element was malloc'ed
1376 #define NTSTRING 0x4 // element contains a quoted string
1386 if (!tmpcurr)
return -1;
1390 if (!tmpcurr->
str)
return -1;
1393 *tail = &tmpcurr->
next;
1408 if (!(buf =
malloc(patt->
len + 1)))
return 0;
1411 buf[patt->
len] =
'\0';
1419 if (status || last == tail)
return 0;
1443 for (ptr = cmd; *ptr;) {
1449 else if (quote == *ptr)
1465 if (*++ptr !=
'_' && !
ISALPHA(*ptr))
break;
1466 while (*++ptr ==
'_' ||
ISALNUM(*ptr));
1467 if (*ptr++ ==
'%')
return TRUE;
1481 static inline char *
1494 int elements, strsz, done;
1495 int slashes, escape;
1496 char *ptr, *base, *buffer, *cmdline;
1513 ptr = cmdline =
strdup(cmd);
1526 quote = slashes = globbing = escape = 0;
1527 for (done = 0; !done && *ptr; ) {
1536 if (quote !=
'\'') slashes++;
1576 if (!(slashes & 1)) {
1579 else if (quote == *ptr) {
1580 if (quote ==
'"' && quote == ptr[1])
1613 slashes = quote = 0;
1614 while (p < base + len) {
1618 if (quote !=
'\'') slashes++;
1623 if (!(slashes & 1) && quote && quote != c) {
1628 memcpy(p - ((slashes + 1) >> 1), p + (~slashes & 1),
1630 len -= ((slashes + 1) >> 1) + (~slashes & 1);
1631 p -= (slashes + 1) >> 1;
1632 if (!(slashes & 1)) {
1634 if (quote ==
'"' && quote == *p)
1655 if (!curr)
goto do_nothing;
1659 if (globbing && (tail =
cmdglob(curr, cmdtail))) {
1664 cmdtail = &curr->
next;
1674 for (elements = 0, strsz = 0, curr = cmdhead; curr; curr = curr->
next) {
1676 strsz += (curr->
len + 1);
1679 len = (elements+1)*
sizeof(
char *) + strsz;
1680 buffer = (
char *)
malloc(len);
1683 while (curr = cmdhead) {
1684 cmdhead = curr->
next;
1689 for (vptr = *vec; *vptr; ++vptr);
1705 vptr = (
char **) buffer;
1707 ptr = buffer + (elements+1) *
sizeof(
char *);
1709 while (curr = cmdhead) {
1712 ptr += curr->
len + 1;
1713 cmdhead = curr->
next;
1719 *vec = (
char **) buffer;
1728 #define PATHLEN 1024
1737 #define GetBit(bits, i) ((bits)[(i) / CHAR_BIT] & (1 << (i) % CHAR_BIT))
1738 #define SetBit(bits, i) ((bits)[(i) / CHAR_BIT] |= (1 << (i) % CHAR_BIT))
1740 #define BitOfIsDir(n) ((n) * 2)
1741 #define BitOfIsRep(n) ((n) * 2 + 1)
1742 #define DIRENT_PER_CHAR (CHAR_BIT / 2)
1749 static const WCHAR wildcard[] = L
"\\*";
1758 len = lstrlenW(filename);
1759 scanname =
ALLOCV_N(WCHAR, v, len +
sizeof(wildcard) /
sizeof(WCHAR));
1760 lstrcpyW(scanname, filename);
1761 p = CharPrevW(scanname, scanname + len);
1762 if (*p == L
'/' || *p == L
'\\' || *p == L
':')
1763 lstrcatW(scanname, wildcard + 1);
1765 lstrcatW(scanname, wildcard);
1770 fh = FindFirstFileW(scanname, fd);
1772 if (fh == INVALID_HANDLE_VALUE) {
1782 struct stati64 sbuf;
1783 WIN32_FIND_DATAW fd;
1797 if (!(sbuf.st_mode & S_IFDIR) &&
1798 (!
ISALPHA(filename[0]) || filename[1] !=
':' || filename[2] !=
'\0' ||
1799 ((1 << ((filename[0] & 0x5f) -
'A')) & GetLogicalDrives()) == 0)) {
1804 if (fh == INVALID_HANDLE_VALUE) {
1824 len = lstrlenW(fd.cFileName) + 1;
1840 memcpy(&p->
start[idx], fd.cFileName, len *
sizeof(WCHAR));
1849 if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1851 if (fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
1856 }
while (FindNextFileW(fh, &fd));
1867 UINT cp = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
1876 int len = WideCharToMultiByte(cp, 0, wstr, clen,
NULL, 0,
NULL,
NULL) - 1;
1877 if (!(ptr =
malloc(len + 1)))
return 0;
1878 WideCharToMultiByte(cp, 0, wstr, clen, ptr, len + 1,
NULL,
NULL);
1879 if (plen) *plen = len;
1888 int len = MultiByteToWideChar(cp, 0, str, clen,
NULL, 0) - 1;
1889 if (!(ptr =
malloc(
sizeof(WCHAR) * (len + 1))))
return 0;
1890 MultiByteToWideChar(cp, 0, str, clen, ptr, len + 1);
1891 if (plen) *plen = len;
1931 dirp->
curr += lstrlenW(dirp->
curr) + 1;
1967 src =
rb_enc_str_new((
char *)wstr, lstrlenW(wstr) *
sizeof(WCHAR), utf16);
1999 static int dummy = 0;
2065 while (dirp->
curr && dirp->
loc < loc) {
2101 #if (defined _MT || defined __MSVCRT__) && !defined __BORLANDC__
2102 #define MSVCRT_THREADS
2104 #ifdef MSVCRT_THREADS
2105 # define MTHREAD_ONLY(x) x
2106 # define STHREAD_ONLY(x)
2107 #elif defined(__BORLANDC__)
2108 # define MTHREAD_ONLY(x)
2109 # define STHREAD_ONLY(x)
2111 # define MTHREAD_ONLY(x)
2112 # define STHREAD_ONLY(x) x
2120 #ifdef MSVCRT_THREADS
2122 CRITICAL_SECTION lock;
2124 #if RUBY_MSVCRT_VERSION >= 80
2130 #if !defined _CRTIMP || defined __MINGW32__
2132 #define _CRTIMP __declspec(dllimport)
2135 #if !defined(__BORLANDC__)
2139 #define IOINFO_L2E 5
2140 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
2141 #define _osfhnd(i) (_pioinfo(i)->osfhnd)
2142 #define _osfile(i) (_pioinfo(i)->osfile)
2143 #define _pipech(i) (_pioinfo(i)->pipech)
2145 #if RUBY_MSVCRT_VERSION >= 80
2150 set_pioinfo_extra(
void)
2154 fd = _open(
"NUL", O_RDONLY);
2155 for (pioinfo_extra = 0; pioinfo_extra <= 64; pioinfo_extra +=
sizeof(
void *)) {
2156 if (
_osfhnd(fd) == _get_osfhandle(fd)) {
2162 if (pioinfo_extra > 64) {
2168 #define pioinfo_extra 0
2174 const size_t sizeof_ioinfo =
sizeof(
ioinfo) + pioinfo_extra;
2179 #define _set_osfhnd(fh, osfh) (void)(_osfhnd(fh) = osfh)
2180 #define _set_osflags(fh, flags) (_osfile(fh) = (flags))
2183 #define FEOFLAG 0x02
2185 #define FNOINHERIT 0x10
2186 #define FAPPEND 0x20
2211 if (flags & O_APPEND)
2217 if (flags & O_NOINHERIT)
2221 hF = CreateFile(
"NUL", 0, 0,
NULL, OPEN_ALWAYS, 0,
NULL);
2222 fh = _open_osfhandle((
intptr_t)hF, 0);
2248 #define open_null(fd) \
2250 (nullfd = open("NUL", O_RDWR)) : 0), \
2251 ((nullfd == (fd)) ? (keep = 1) : dup2(nullfd, fd)), \
2260 if (
fileno(stdout) < 0) {
2263 if (
fileno(stderr) < 0) {
2266 if (nullfd >= 0 && !keep) close(nullfd);
2267 setvbuf(stderr,
NULL, _IONBF, 0);
2271 #define _set_osfhnd(fh, osfh) (void)((fh), (osfh))
2272 #define _set_osflags(fh, flags) (void)((fh), (flags))
2286 int fd = _open_osfhandle(osfhandle, flags);
2326 static char buffer[512];
2330 #if defined __BORLANDC__ && defined ENOTEMPTY // _sys_errlist is broken
2333 return "Filename too long";
2335 return "Directory not empty";
2342 #if WSAEWOULDBLOCK != EWOULDBLOCK
2347 for (s = 0; s < (int)(
sizeof(
errmap)/
sizeof(*
errmap)); s++)
2350 for (i = s; i < (int)(
sizeof(
errmap)/
sizeof(*errmap)); i++)
2357 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
2358 FORMAT_MESSAGE_IGNORE_INSERTS, &source, e,
2359 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
2360 buffer,
sizeof(buffer),
NULL) == 0 &&
2361 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
2362 FORMAT_MESSAGE_IGNORE_INSERTS, &source, e, 0,
2363 buffer,
sizeof(buffer),
NULL) == 0)
2364 strlcpy(buffer,
"Unknown Error",
sizeof(buffer));
2370 while ((p = strpbrk(p,
"\r\n")) !=
NULL) {
2459 for (i = 0; i < set->fd_count; i++) {
2460 if (set->fd_array[i] == s) {
2461 memmove(&set->fd_array[i], &set->fd_array[i+1],
2462 sizeof(set->fd_array[0]) * (--set->fd_count - i));
2476 if (s == (SOCKET)INVALID_HANDLE_VALUE)
2486 max = min(src->fd_count, (UINT)max);
2487 if ((UINT)dst->capa < (UINT)max) {
2488 dst->capa = (src->fd_count / FD_SETSIZE + 1) * FD_SETSIZE;
2489 dst->fdset =
xrealloc(dst->fdset,
sizeof(
unsigned int) +
sizeof(SOCKET) * dst->capa);
2492 memcpy(dst->fdset->fd_array, src->fd_array,
2493 max *
sizeof(src->fd_array[0]));
2494 dst->fdset->fd_count = src->fd_count;
2501 if ((UINT)dst->capa < src->fdset->fd_count) {
2502 dst->capa = (src->fdset->fd_count / FD_SETSIZE + 1) * FD_SETSIZE;
2503 dst->fdset =
xrealloc(dst->fdset,
sizeof(
unsigned int) +
sizeof(SOCKET) * dst->capa);
2506 memcpy(dst->fdset->fd_array, src->fdset->fd_array,
2507 src->fdset->fd_count *
sizeof(src->fdset->fd_array[0]));
2508 dst->fdset->fd_count = src->fdset->fd_count;
2527 while (s < src->fd_count) {
2528 SOCKET fd = src->fd_array[s];
2534 for (d = 0; d < dst->fdset->fd_count; d++) {
2535 if (dst->fdset->fd_array[d] == fd)
2538 if (d == dst->fdset->fd_count) {
2539 if ((
int)dst->fdset->fd_count >= dst->capa) {
2540 dst->capa = (dst->fdset->fd_count / FD_SETSIZE + 1) * FD_SETSIZE;
2541 dst->fdset =
xrealloc(dst->fdset,
sizeof(
unsigned int) +
sizeof(SOCKET) * dst->capa);
2543 dst->fdset->fd_array[dst->fdset->fd_count++] = fd;
2547 &src->fd_array[s+1],
2548 sizeof(src->fd_array[0]) * (--src->fd_count - s));
2558 return dst ? dst->fdset->fd_count : m;
2566 if (!src || !dst)
return 0;
2568 for (s = 0; s < src->fd_count; ++s) {
2569 SOCKET fd = src->fd_array[s];
2571 for (d = 0; d < dst->fd_count; ++d) {
2572 if (dst->fd_array[d] == fd)
2575 if (d == dst->fd_count && d < FD_SETSIZE) {
2576 dst->fd_array[dst->fd_count++] = fd;
2580 return dst->fd_count;
2597 ret = (GetFileType((HANDLE)sock) == FILE_TYPE_PIPE);
2611 if (PeekNamedPipe((HANDLE)sock,
NULL, 0,
NULL, &n,
NULL)) {
2615 ret = (GetLastError() == ERROR_BROKEN_PIPE);
2631 ret = (PeekConsoleInput((HANDLE)sock, &ir, 1, &n))
2646 if (PeekConsoleInput((HANDLE)sock, &ir, 1, &n) && n > 0) {
2647 if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown &&
2648 ir.Event.KeyEvent.uChar.AsciiChar) {
2652 ReadConsoleInput((HANDLE)sock, &ir, 1, &n);
2664 return (HANDLE)sock == INVALID_HANDLE_VALUE;
2681 if (!NtSocketsInitialized)
2685 EnterCriticalSection(&select_mutex);
2686 r =
select(nfds, rd, wr, ex, timeout);
2687 LeaveCriticalSection(&select_mutex);
2688 if (r == SOCKET_ERROR) {
2744 struct timeval *timeout,
void *th)
2753 struct timeval limit = {0, 0};
2755 if (nfds < 0 || (timeout && (timeout->
tv_sec < 0 || timeout->
tv_usec < 0))) {
2761 if (timeout->
tv_sec < 0 ||
2763 timeout->
tv_usec >= 1000000) {
2770 if (limit.
tv_usec >= 1000000) {
2807 if (rd && (
int)rd->fd_count > r) r = (int)rd->fd_count;
2808 if (wr && (
int)wr->fd_count > r) r = (
int)wr->fd_count;
2809 if (ex && (
int)ex->fd_count > r) r = (
int)ex->fd_count;
2810 if (nfds > r) nfds = r;
2830 if (else_rd.fdset->fd_count || else_wr.fdset->fd_count) {
2833 r +=
copy_fd(rd, else_rd.fdset);
2834 r +=
copy_fd(wr, else_wr.fdset);
2850 if (rd)
copy_fd(&orig_rd, rd);
2851 if (wr)
copy_fd(&orig_wr, wr);
2852 if (ex)
copy_fd(&orig_ex, ex);
2855 if (rd)
copy_fd(rd, &orig_rd);
2856 if (wr)
copy_fd(wr, &orig_wr);
2857 if (ex)
copy_fd(ex, &orig_ex);
2864 if (
compare(&rest, &wait) < 0) dowait = &rest;
2895 WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, guid,
sizeof(*guid),
2896 &ptr,
sizeof(ptr), &dmy,
NULL,
NULL);
2911 if (!NtSocketsInitialized) {
2915 HANDLE h = CreateFile(
"NUL", 0, 0,
NULL, OPEN_ALWAYS, 0,
NULL);
2918 r = accept(
TO_SOCKET(s), addr, addrlen);
2919 if (r != INVALID_SOCKET) {
2946 if (!NtSocketsInitialized) {
2951 if (r == SOCKET_ERROR)
2964 if (!NtSocketsInitialized) {
2968 r = connect(
TO_SOCKET(s), addr, addrlen);
2969 if (r == SOCKET_ERROR) {
2970 int err = WSAGetLastError();
2971 if (err != WSAEWOULDBLOCK)
2988 if (!NtSocketsInitialized) {
2992 r = getpeername(
TO_SOCKET(s), addr, addrlen);
2993 if (r == SOCKET_ERROR)
3007 if (!NtSocketsInitialized) {
3012 r = getsockname(sock, addr, addrlen);
3013 if (r == SOCKET_ERROR) {
3014 DWORD wsaerror = WSAGetLastError();
3015 if (wsaerror == WSAEINVAL) {
3020 memset(addr, 0, *addrlen);
3021 addr->sa_family = af;
3039 if (!NtSocketsInitialized) {
3043 r = getsockopt(
TO_SOCKET(s), level, optname, optval, optlen);
3044 if (r == SOCKET_ERROR)
3057 if (!NtSocketsInitialized) {
3061 r = ioctlsocket(
TO_SOCKET(s), cmd, argp);
3062 if (r == SOCKET_ERROR)
3075 if (!NtSocketsInitialized) {
3080 if (r == SOCKET_ERROR)
3098 if (result != SOCKET_ERROR)
3100 else if ((err = WSAGetLastError()) == WSA_IO_PENDING) {
3104 result = WSAGetOverlappedResult(s, wol, &size,
TRUE, &flg)
3112 if ((err = WSAGetLastError()) == WSAECONNABORTED && !input)
3117 case WAIT_OBJECT_0 + 1:
3125 if (err == WSAECONNABORTED && !input)
3131 CloseHandle(wol->hEvent);
3139 struct sockaddr *addr,
int *addrlen)
3149 if (!NtSocketsInitialized)
3157 if (addr && addrlen)
3158 r = recvfrom(s, buf, len, flags, addr, addrlen);
3160 r = recv(s, buf, len, flags);
3161 if (r == SOCKET_ERROR)
3165 if (addr && addrlen)
3166 r = sendto(s, buf, len, flags, addr, *addrlen);
3168 r = send(s, buf, len, flags);
3169 if (r == SOCKET_ERROR) {
3171 if (err == WSAECONNABORTED)
3184 memset(&wol, 0,
sizeof(wol));
3189 if (addr && addrlen)
3190 ret = WSARecvFrom(s, &wbuf, 1, &size, &flg, addr, addrlen,
3193 ret = WSARecv(s, &wbuf, 1, &size, &flg, &wol,
NULL);
3196 if (addr && addrlen)
3197 ret = WSASendTo(s, &wbuf, 1, &size, flags, addr, *addrlen,
3200 ret = WSASend(s, &wbuf, 1, &size, flags, &wol,
NULL);
3221 struct sockaddr *from,
int *fromlen)
3236 const struct sockaddr *to,
int tolen)
3239 (
struct sockaddr *)to, &tolen);
3242 #if !defined(MSG_TRUNC) && !defined(__MINGW32__)
3253 #ifndef WSAID_WSARECVMSG
3254 #define WSAID_WSARECVMSG {0xf689d7c8,0x6f1f,0x436b,{0x8a,0x53,0xe5,0x4f,0xe3,0x51,0xc3,0x22}}
3256 #ifndef WSAID_WSASENDMSG
3257 #define WSAID_WSASENDMSG {0xa441e712,0x754f,0x43ca,{0x84,0xa7,0x0d,0xee,0x44,0xcf,0x60,0x6d}}
3261 #define msghdr_to_wsamsg(msg, wsamsg) \
3264 (wsamsg)->name = (msg)->msg_name; \
3265 (wsamsg)->namelen = (msg)->msg_namelen; \
3266 (wsamsg)->lpBuffers = ALLOCA_N(WSABUF, (msg)->msg_iovlen); \
3267 (wsamsg)->dwBufferCount = (msg)->msg_iovlen; \
3268 for (i = 0; i < (msg)->msg_iovlen; ++i) { \
3269 (wsamsg)->lpBuffers[i].buf = (msg)->msg_iov[i].iov_base; \
3270 (wsamsg)->lpBuffers[i].len = (msg)->msg_iov[i].iov_len; \
3272 (wsamsg)->Control.buf = (msg)->msg_control; \
3273 (wsamsg)->Control.len = (msg)->msg_controllen; \
3274 (wsamsg)->dwFlags = (msg)->msg_flags; \
3281 typedef int (WSAAPI *WSARecvMsg_t)(SOCKET,
WSAMSG *,
DWORD *, WSAOVERLAPPED *, LPWSAOVERLAPPED_COMPLETION_ROUTINE);
3282 static WSARecvMsg_t pWSARecvMsg =
NULL;
3289 if (!NtSocketsInitialized)
3307 if ((ret = pWSARecvMsg(s, &wsamsg, &len,
NULL,
NULL)) == SOCKET_ERROR) {
3316 memset(&wol, 0,
sizeof(wol));
3319 ret = pWSARecvMsg(s, &wsamsg, &size, &wol,
NULL);
3324 if (ret == SOCKET_ERROR)
3339 typedef int (WSAAPI *WSASendMsg_t)(SOCKET,
const WSAMSG *,
DWORD, DWORD *, WSAOVERLAPPED *, LPWSAOVERLAPPED_COMPLETION_ROUTINE);
3340 static WSASendMsg_t pWSASendMsg =
NULL;
3347 if (!NtSocketsInitialized)
3364 if ((ret = pWSASendMsg(s, &wsamsg, flags, &len,
NULL,
NULL)) == SOCKET_ERROR) {
3373 memset(&wol, 0,
sizeof(wol));
3376 ret = pWSASendMsg(s, &wsamsg, flags, &size, &wol,
NULL);
3392 if (!NtSocketsInitialized) {
3396 r = setsockopt(
TO_SOCKET(s), level, optname, optval, optlen);
3397 if (r == SOCKET_ERROR)
3410 if (!NtSocketsInitialized) {
3415 if (r == SOCKET_ERROR)
3425 unsigned long proto_buffers_len = 0;
3427 SOCKET out = INVALID_SOCKET;
3429 if (WSAEnumProtocols(
NULL,
NULL, &proto_buffers_len) == SOCKET_ERROR) {
3430 error_code = WSAGetLastError();
3431 if (error_code == WSAENOBUFS) {
3432 WSAPROTOCOL_INFO *proto_buffers;
3433 int protocols_available = 0;
3435 proto_buffers = (WSAPROTOCOL_INFO *)
malloc(proto_buffers_len);
3436 if (!proto_buffers) {
3437 WSASetLastError(WSA_NOT_ENOUGH_MEMORY);
3438 return INVALID_SOCKET;
3441 protocols_available =
3442 WSAEnumProtocols(
NULL, proto_buffers, &proto_buffers_len);
3443 if (protocols_available != SOCKET_ERROR) {
3445 for (i = 0; i < protocols_available; i++) {
3446 if ((af !=
AF_UNSPEC && af != proto_buffers[i].iAddressFamily) ||
3447 (type != proto_buffers[i].iSocketType) ||
3448 (protocol != 0 && protocol != proto_buffers[i].iProtocol))
3451 if ((proto_buffers[i].dwServiceFlags1 & XP1_IFS_HANDLES) == 0)
3454 out = WSASocket(af, type, protocol, &(proto_buffers[i]), 0,
3455 WSA_FLAG_OVERLAPPED);
3458 if (out == INVALID_SOCKET)
3459 out = WSASocket(af, type, protocol,
NULL, 0, 0);
3462 free(proto_buffers);
3478 if (!NtSocketsInitialized) {
3483 if (s == INVALID_SOCKET) {
3498 #undef gethostbyaddr
3501 struct hostent * WSAAPI
3505 if (!NtSocketsInitialized) {
3509 r = gethostbyaddr(addr, len, type);
3516 #undef gethostbyname
3519 struct hostent * WSAAPI
3523 if (!NtSocketsInitialized) {
3527 r = gethostbyname(name);
3541 if (!NtSocketsInitialized) {
3545 r = gethostname(name, len);
3546 if (r == SOCKET_ERROR)
3552 #undef getprotobyname
3555 struct protoent * WSAAPI
3559 if (!NtSocketsInitialized) {
3563 r = getprotobyname(name);
3570 #undef getprotobynumber
3573 struct protoent * WSAAPI
3577 if (!NtSocketsInitialized) {
3581 r = getprotobynumber(num);
3588 #undef getservbyname
3591 struct servent * WSAAPI
3595 if (!NtSocketsInitialized) {
3599 r = getservbyname(name, proto);
3606 #undef getservbyport
3609 struct servent * WSAAPI
3613 if (!NtSocketsInitialized) {
3617 r = getservbyport(port, proto);
3628 SOCKET svr = INVALID_SOCKET, r = INVALID_SOCKET, w = INVALID_SOCKET;
3629 struct sockaddr_in sock_in4;
3631 struct sockaddr_in6 sock_in6;
3633 struct sockaddr *addr;
3637 if (!NtSocketsInitialized) {
3643 #if defined PF_INET && PF_INET != AF_INET
3646 sock_in4.sin_family = AF_INET;
3647 sock_in4.sin_port = 0;
3649 addr = (
struct sockaddr *)&sock_in4;
3650 len =
sizeof(sock_in4);
3654 memset(&sock_in6, 0,
sizeof(sock_in6));
3655 sock_in6.sin6_family = AF_INET6;
3656 sock_in6.sin6_addr = IN6ADDR_LOOPBACK_INIT;
3657 addr = (
struct sockaddr *)&sock_in6;
3658 len =
sizeof(sock_in6);
3665 if (type != SOCK_STREAM) {
3670 sv[0] = (SOCKET)INVALID_HANDLE_VALUE;
3671 sv[1] = (SOCKET)INVALID_HANDLE_VALUE;
3675 if (svr == INVALID_SOCKET)
3677 if (bind(svr, addr, len) < 0)
3679 if (getsockname(svr, addr, &len) < 0)
3681 if (type == SOCK_STREAM)
3685 if (w == INVALID_SOCKET)
3687 if (connect(w, addr, len) < 0)
3690 r = accept(svr, addr, &len);
3691 if (r == INVALID_SOCKET)
3699 if (r != INVALID_SOCKET)
3701 if (w != INVALID_SOCKET)
3708 if (svr != INVALID_SOCKET)
3725 closesocket(pair[0]);
3726 closesocket(pair[1]);
3732 closesocket(pair[1]);
3785 flag &= ~O_NONBLOCK;
3789 ret = ioctlsocket(sock, FIONBIO, &ioctlArg);
3801 dupfd(HANDLE hDup,
char flags,
int minfd)
3811 goto close_fds_and_return;
3814 goto close_fds_and_return;
3816 fds[filled++] = ret;
3817 }
while (filled < (
int)
numberof(fds));
3819 ret =
dupfd(hDup, flags, minfd);
3821 close_fds_and_return:
3823 while (filled > 0) {
3824 int fd = fds[--filled];
3848 arg = va_arg(va,
int);
3850 return setfl(sock, arg);
3855 if (!(DuplicateHandle(GetCurrentProcess(), (HANDLE)_get_osfhandle(fd),
3856 GetCurrentProcess(), &hDup, 0L,
3858 DUPLICATE_SAME_ACCESS))) {
3864 arg = va_arg(va,
int);
3888 if (!GetExitCodeProcess(child->
hProcess, &exitcode)) {
3891 err = GetLastError();
3892 if (err == ERROR_INVALID_PARAMETER)
3895 if (GetLastError() == ERROR_INVALID_HANDLE)
3903 if (exitcode != STILL_ACTIVE) {
3911 if (stat_loc) *stat_loc = exitcode << 8;
3939 if (!child->pid || child->pid < 0)
continue;
3941 events[count++] = child->hProcess;
3949 if (ret == WAIT_TIMEOUT)
return 0;
3950 if ((ret -= WAIT_OBJECT_0) == count) {
3985 #include <sys/timeb.h>
3992 unsigned LONG_LONG
lt;
3994 tmp.LowPart = ft->dwLowDateTime;
3995 tmp.HighPart = ft->dwHighDateTime;
4003 lt -= (LONG_LONG)((1970-1601)*365.2425) * 24 * 60 * 60 * 1000 * 1000;
4005 tv->
tv_sec = (long)(lt / (1000 * 1000));
4006 tv->
tv_usec = (long)(lt % (1000 * 1000));
4008 return tv->
tv_sec > 0 ? 0 : -1;
4017 GetSystemTimeAsFileTime(&ft);
4030 len = GetCurrentDirectory(0,
NULL);
4051 if (!GetCurrentDirectory(size, p)) {
4065 chown(
const char *path,
int owner,
int group)
4084 if (pid < 0 || pid == 0 && sig !=
SIGINT) {
4089 if ((
unsigned int)pid == GetCurrentProcessId() &&
4090 (sig != 0 && sig !=
SIGKILL)) {
4091 if ((ret =
raise(sig)) != 0) {
4102 OpenProcess(PROCESS_QUERY_INFORMATION,
FALSE, (
DWORD)pid);
4103 if (hProc ==
NULL || hProc == INVALID_HANDLE_VALUE) {
4104 if (GetLastError() == ERROR_INVALID_PARAMETER) {
4120 DWORD ctrlEvent = CTRL_C_EVENT;
4124 ctrlEvent = CTRL_BREAK_EVENT;
4126 if (!GenerateConsoleCtrlEvent(ctrlEvent, (
DWORD)pid)) {
4127 if ((err = GetLastError()) == 0)
4144 hProc = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION,
FALSE, (
DWORD)pid);
4146 if (hProc ==
NULL || hProc == INVALID_HANDLE_VALUE) {
4147 if (GetLastError() == ERROR_INVALID_PARAMETER) {
4157 if (!GetExitCodeProcess(hProc, &status)) {
4161 else if (status == STILL_ACTIVE) {
4162 if (!TerminateProcess(hProc, 0)) {
4189 wlink(
const WCHAR *from,
const WCHAR *to)
4191 typedef BOOL (WINAPI link_func)(LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES);
4192 static link_func *pCreateHardLinkW =
NULL;
4193 static int myerrno = 0;
4195 if (!pCreateHardLinkW && !myerrno) {
4197 if (!pCreateHardLinkW)
4200 if (!pCreateHardLinkW) {
4205 if (!pCreateHardLinkW(to, from,
NULL)) {
4227 ret =
wlink(wfrom, wto);
4235 link(
const char *from,
const char *to)
4247 ret =
wlink(wfrom, wto);
4257 return waitpid(-1, status, 0);
4264 WCHAR *wenvarea, *wenv;
4269 if (len == 0)
return NULL;
4276 FreeEnvironmentStrings(envarea);
4279 wenvarea = GetEnvironmentStringsW();
4284 for (wenv = wenvarea, wlen = 1; *wenv; wenv += lstrlenW(wenv) + 1)
4285 wlen += lstrlenW(wenv) + 1;
4287 FreeEnvironmentStringsW(wenvarea);
4291 for (env = uenvarea; *
env; env +=
strlen(env) + 1)
4292 if (
strncasecmp(env, name, len) == 0 && *(env + len) ==
'=')
4293 return env + len + 1;
4305 if (len == 0)
return NULL;
4311 FreeEnvironmentStrings(envarea);
4314 envarea = GetEnvironmentStrings();
4320 for (env = envarea; *
env; env +=
strlen(env) + 1)
4321 if (
strncasecmp(env, name, len) == 0 && *(env + len) ==
'=')
4322 return env + len + 1;
4329 wrename(
const WCHAR *oldpath,
const WCHAR *newpath)
4335 oldatts = GetFileAttributesW(oldpath);
4336 newatts = GetFileAttributesW(newpath);
4338 if (oldatts == -1) {
4344 if (newatts != -1 && newatts & FILE_ATTRIBUTE_READONLY)
4345 SetFileAttributesW(newpath, newatts & ~ FILE_ATTRIBUTE_READONLY);
4347 if (!MoveFileExW(oldpath, newpath, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED))
4353 SetFileAttributesW(newpath, oldatts);
4401 if (path[0] == L
'\\' && path[1] == L
'\\') {
4402 const WCHAR *
p = path + 2;
4403 if (p[0] == L
'?' && p[1] == L
'\\') {
4411 for (p++; *
p; p++) {
4415 if (!p[0] || !p[1] || (p[1] == L
'.' && !p[2]))
4422 #define COPY_STAT(src, dest, size_cast) do { \
4423 (dest).st_dev = (src).st_dev; \
4424 (dest).st_ino = (src).st_ino; \
4425 (dest).st_mode = (src).st_mode; \
4426 (dest).st_nlink = (src).st_nlink; \
4427 (dest).st_uid = (src).st_uid; \
4428 (dest).st_gid = (src).st_gid; \
4429 (dest).st_rdev = (src).st_rdev; \
4430 (dest).st_size = size_cast(src).st_size; \
4431 (dest).st_atime = (src).st_atime; \
4432 (dest).st_mtime = (src).st_mtime; \
4433 (dest).st_ctime = (src).st_ctime; \
4443 BY_HANDLE_FILE_INFORMATION info;
4444 int ret =
fstat(fd, st);
4446 if (ret)
return ret;
4450 if (GetFileInformationByHandle((HANDLE)_get_osfhandle(fd), &info)) {
4452 if (!(info.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
4467 BY_HANDLE_FILE_INFORMATION info;
4469 int ret =
fstat(fd, &tmp);
4471 if (ret)
return ret;
4476 if (GetFileInformationByHandle((HANDLE)_get_osfhandle(fd), &info)) {
4478 if (!(info.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
4482 st->st_size = ((__int64)info.nFileSizeHigh << 32) | info.nFileSizeLow;
4508 if (attr & FILE_ATTRIBUTE_READONLY) {
4512 mode |= S_IREAD | S_IWRITE |
S_IWUSR;
4515 if (attr & FILE_ATTRIBUTE_DIRECTORY) {
4516 mode |= S_IFDIR | S_IEXEC;
4522 if (path && (mode & S_IFREG)) {
4523 const WCHAR *end = path + lstrlenW(path);
4524 while (path < end) {
4525 end = CharPrevW(path, end);
4527 if ((_wcsicmp(end, L
".bat") == 0) ||
4528 (_wcsicmp(end, L
".cmd") == 0) ||
4529 (_wcsicmp(end, L
".com") == 0) ||
4530 (_wcsicmp(end, L
".exe") == 0)) {
4538 mode |= (mode & 0700) >> 3;
4539 mode |= (mode & 0700) >> 6;
4548 WIN32_FIND_DATAW fd;
4550 WCHAR full[MAX_PATH];
4556 if (!(p = wcsstr(path, L
"...")))
4558 q = p + wcsspn(p, L
".");
4559 if ((p == path || wcschr(L
":/\\", *(p - 1))) &&
4560 (!*q || wcschr(L
":/\\", *q))) {
4567 if (!GetFullPathNameW(path,
sizeof(full) /
sizeof(WCHAR), full, &dmy)) {
4571 if (full[1] == L
':' && !full[3] && GetDriveTypeW(full) != DRIVE_NO_ROOT_DIR)
4575 if (fh == INVALID_HANDLE_VALUE)
4586 WIN32_FIND_DATAW wfd;
4587 WIN32_FILE_ATTRIBUTE_DATA wfa;
4588 const WCHAR *
p = path;
4590 memset(st, 0,
sizeof(*st));
4593 if (wcsncmp(p, L
"\\\\?\\", 4) == 0) p += 4;
4594 if (wcspbrk(p, L
"?*")) {
4598 if (GetFileAttributesExW(path, GetFileExInfoStandard, (
void*)&wfa)) {
4599 if (wfa.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
4604 st->st_size = ((__int64)wfa.nFileSizeHigh << 32) | wfa.nFileSizeLow;
4613 int e = GetLastError();
4615 if ((e == ERROR_FILE_NOT_FOUND) || (e == ERROR_INVALID_NAME)
4616 || (e == ERROR_PATH_NOT_FOUND || (e == ERROR_BAD_NETPATH))) {
4622 h = FindFirstFileW(path, &wfd);
4623 if (h != INVALID_HANDLE_VALUE) {
4629 st->st_size = ((__int64)wfd.nFileSizeHigh << 32) | wfd.nFileSizeLow;
4637 st->st_dev = st->st_rdev = (iswalpha(path[0]) && path[1] == L
':') ?
4638 towupper(path[0]) - L
'A' : _getdrive() - 1;
4659 WCHAR *buf1, *s, *end;
4668 size = lstrlenW(path) + 2;
4670 for (p = path, s = buf1; *
p; p++, s++) {
4678 if (!len || L
'\"' == *(--s)) {
4682 end = buf1 + len - 1;
4687 else if (*end != L
'\\')
4688 lstrcatW(buf1, L
"\\");
4690 else if (*end == L
'\\' || (buf1 + 1 == end && *end == L
':'))
4691 lstrcatW(buf1, L
".");
4735 struct stati64 stat;
4739 if ((stat.st_mode & mode) != mode) {
4750 struct stati64 stat;
4754 if ((stat.st_mode & mode) != mode) {
4765 long upos, lpos, usize, lsize;
4769 if ((lpos = SetFilePointer(h, 0, (upos = 0, &upos),
SEEK_CUR)) == -1L &&
4770 (e = GetLastError())) {
4774 usize = (long)(size >> 32);
4776 if (SetFilePointer(h, lsize, &usize,
SEEK_SET) == (
DWORD)-1L &&
4777 (e = GetLastError())) {
4780 else if (!SetEndOfFile(h)) {
4786 SetFilePointer(h, lpos, &upos,
SEEK_SET);
4796 h = CreateFile(path, GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
4797 if (h == INVALID_HANDLE_VALUE) {
4812 h = (HANDLE)_get_osfhandle(fd);
4813 if (h == (HANDLE)-1)
return -1;
4820 _filelengthi64(
int fd)
4825 l = GetFileSize((HANDLE)_get_osfhandle(fd), &u);
4826 if (l == (
DWORD)-1L && (e = GetLastError())) {
4830 return ((
off_t)u << 32) | l;
4835 _lseeki64(
int fd,
off_t offset,
int whence)
4839 HANDLE h = (HANDLE)_get_osfhandle(fd);
4845 u = (long)(offset >> 32);
4846 if ((l = SetFilePointer(h, (
long)offset, &u, whence)) == -1L &&
4847 (e = GetLastError())) {
4851 return ((
off_t)u << 32) | l;
4862 if (fgetpos(stream, (fpos_t *)&pos))
4867 if ((pos = _filelengthi64(
fileno(stream))) == (
off_t)-1)
4875 return fsetpos(stream, (fpos_t *)&pos);
4883 if (fgetpos(stream, (fpos_t *)&pos))
return (
off_t)-1;
4891 __int64 qw = ft->dwHighDateTime;
4893 qw |= ft->dwLowDateTime;
4902 FILETIME create, exit, kernel, user;
4904 if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
4919 #define yield_once() Sleep(0)
4920 #define yield_until(condition) do yield_once(); while (!(condition))
4930 #if defined __BORLANDC__
4934 read(
int fd,
void *
buf,
size_t size)
4936 int ret = _read(fd, buf, size);
4937 if ((ret < 0) && (
errno == EPIPE)) {
4947 #define FILE_COUNT _cnt
4948 #define FILE_READPTR _ptr
4957 c = (
unsigned char)*stream->FILE_READPTR++;
4960 c = _filbuf(stream);
4961 #if defined __BORLANDC__
4962 if ((c ==
EOF) && (
errno == EPIPE)) {
4977 c = (
unsigned char)(*stream->FILE_READPTR++ = (
char)c);
4980 c = _flsbuf(c, stream);
5017 BOOL interrupted =
FALSE;
5038 if (TerminateThread(thr, intrval)) {
5043 GetExitCodeThread(thr, &val);
5048 MEMORY_BASIC_INFORMATION m;
5050 memset(&m, 0,
sizeof(m));
5051 if (!VirtualQuery(arg.
stackaddr, &m,
sizeof(m))) {
5052 Debug(fprintf(stderr,
"couldn't get stack base:%p:%d\n",
5055 else if (!VirtualFree(m.AllocationBase, 0, MEM_RELEASE)) {
5056 Debug(fprintf(stderr,
"couldn't release stack:%p:%d\n",
5057 m.AllocationBase, GetLastError()));
5068 rb_fatal(
"failed to launch waiter thread:%ld", GetLastError());
5078 WCHAR *envtop, *
env;
5079 char **myenvtop, **myenv;
5092 envtop = GetEnvironmentStringsW();
5093 for (env = envtop, num = 0; *
env; env += lstrlenW(env) + 1)
5094 if (*env !=
'=') num++;
5096 myenvtop = (
char **)
malloc(
sizeof(
char *) * (num + 1));
5097 for (env = envtop, myenv = myenvtop; *
env; env += lstrlenW(env) + 1) {
5106 FreeEnvironmentStringsW(envtop);
5117 while (*t)
free(*t++);
5125 return GetCurrentProcessId();
5133 typedef long (WINAPI query_func)(HANDLE, int,
void *,
ULONG, ULONG *);
5134 static query_func *pNtQueryInformationProcess =
NULL;
5138 if (!pNtQueryInformationProcess)
5139 pNtQueryInformationProcess = (query_func *)
get_proc_address(
"ntdll.dll",
"NtQueryInformationProcess",
NULL);
5140 if (pNtQueryInformationProcess) {
5143 void* PebBaseAddress;
5150 long ret = pNtQueryInformationProcess(GetCurrentProcess(), 0, &pbi,
sizeof(pbi), &len);
5152 ppid = pbi.ParentProcessId;
5169 va_start(arg, oflag);
5170 pmode = va_arg(arg,
int);
5184 DWORD attr = GetFileAttributesW(wfile);
5185 if (attr == (
DWORD)-1L ||
5186 !(attr & FILE_ATTRIBUTE_DIRECTORY) ||
5217 va_start(arg, oflag);
5218 pmode = va_arg(arg,
int);
5221 if ((oflag & O_TEXT) || !(oflag &
O_BINARY)) {
5222 ret = _open(file, oflag, pmode);
5241 DWORD attr = FILE_ATTRIBUTE_NORMAL;
5242 SECURITY_ATTRIBUTES sec;
5245 if ((oflag & O_TEXT) || !(oflag &
O_BINARY)) {
5248 va_start(arg, oflag);
5249 pmode = va_arg(arg,
int);
5251 fd = _wopen(file, oflag, pmode);
5256 sec.nLength =
sizeof(sec);
5257 sec.lpSecurityDescriptor =
NULL;
5258 if (oflag & O_NOINHERIT) {
5259 sec.bInheritHandle =
FALSE;
5263 sec.bInheritHandle =
TRUE;
5265 oflag &= ~O_NOINHERIT;
5268 oflag &= ~(O_BINARY | O_TEXT);
5270 switch (oflag & (O_RDWR | O_RDONLY | O_WRONLY)) {
5272 access = GENERIC_READ | GENERIC_WRITE;
5275 access = GENERIC_READ;
5278 access = GENERIC_WRITE;
5284 oflag &= ~(O_RDWR | O_RDONLY | O_WRONLY);
5286 switch (oflag & (O_CREAT | O_EXCL | O_TRUNC)) {
5288 create = OPEN_ALWAYS;
5292 create = OPEN_EXISTING;
5294 case O_CREAT | O_EXCL:
5295 case O_CREAT | O_EXCL | O_TRUNC:
5296 create = CREATE_NEW;
5299 case O_TRUNC | O_EXCL:
5300 create = TRUNCATE_EXISTING;
5302 case O_CREAT | O_TRUNC:
5303 create = CREATE_ALWAYS;
5309 if (oflag & O_CREAT) {
5312 va_start(arg, oflag);
5313 pmode = va_arg(arg,
int);
5316 if (!(pmode & S_IWRITE))
5317 attr = FILE_ATTRIBUTE_READONLY;
5319 oflag &= ~(O_CREAT | O_EXCL | O_TRUNC);
5321 if (oflag & O_TEMPORARY) {
5322 attr |= FILE_FLAG_DELETE_ON_CLOSE;
5325 oflag &= ~O_TEMPORARY;
5327 if (oflag & _O_SHORT_LIVED)
5328 attr |= FILE_ATTRIBUTE_TEMPORARY;
5329 oflag &= ~_O_SHORT_LIVED;
5331 switch (oflag & (O_SEQUENTIAL | O_RANDOM)) {
5335 attr |= FILE_FLAG_SEQUENTIAL_SCAN;
5338 attr |= FILE_FLAG_RANDOM_ACCESS;
5344 oflag &= ~(O_SEQUENTIAL | O_RANDOM);
5346 if (oflag & ~O_APPEND) {
5353 h = CreateFile(
"NUL", 0, 0,
NULL, OPEN_ALWAYS, 0,
NULL);
5354 fd = _open_osfhandle((
intptr_t)h, 0);
5366 h = CreateFileW(file, access, FILE_SHARE_READ | FILE_SHARE_WRITE, &sec,
5367 create, attr,
NULL);
5368 if (h == INVALID_HANDLE_VALUE) {
5369 DWORD e = GetLastError();
5377 switch (GetFileType(h)) {
5378 case FILE_TYPE_CHAR:
5381 case FILE_TYPE_PIPE:
5384 case FILE_TYPE_UNKNOWN:
5391 if (!(flags & (
FDEV |
FPIPE)) && (oflag & O_APPEND))
5411 int save_errno =
errno;
5413 if (fflush(fp))
return -1;
5421 if (closesocket(sock) == SOCKET_ERROR) {
5432 static DWORD serial = 0;
5433 char name[] =
"\\\\.\\pipe\\ruby0000000000000000-0000000000000000";
5435 SECURITY_ATTRIBUTES sec;
5436 HANDLE hRead, hWrite, h;
5437 int fdRead, fdWrite;
5442 return _pipe(fds, 65536L, _O_NOINHERIT);
5447 sec.nLength =
sizeof(sec);
5448 sec.lpSecurityDescriptor =
NULL;
5449 sec.bInheritHandle =
FALSE;
5452 hRead = CreateNamedPipe(name, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
5453 0, 2, 65536, 65536, 0, &sec);
5455 if (hRead == INVALID_HANDLE_VALUE) {
5457 if (err == ERROR_PIPE_BUSY)
5465 hWrite = CreateFile(name, GENERIC_READ | GENERIC_WRITE, 0, &sec,
5466 OPEN_EXISTING, FILE_FLAG_OVERLAPPED,
NULL);
5468 if (hWrite == INVALID_HANDLE_VALUE) {
5476 h = CreateFile(
"NUL", 0, 0,
NULL, OPEN_ALWAYS, 0,
NULL);
5477 fdRead = _open_osfhandle((
intptr_t)h, 0);
5481 CloseHandle(hWrite);
5496 h = CreateFile(
"NUL", 0, 0,
NULL, OPEN_ALWAYS, 0,
NULL);
5497 fdWrite = _open_osfhandle((
intptr_t)h, 0);
5499 if (fdWrite == -1) {
5501 CloseHandle(hWrite);
5534 CONSOLE_SCREEN_BUFFER_INFO csbi;
5537 p->
vt100.
attr = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
5539 if (GetConsoleScreenBufferInfo(h, &csbi)) {
5553 if (!conlist)
return;
5563 #define FOREGROUND_MASK (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)
5564 #define BACKGROUND_MASK (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED)
5565 DWORD bold = attr & (FOREGROUND_INTENSITY | BACKGROUND_INTENSITY);
5568 if (!count)
return attr;
5569 while (count-- > 0) {
5572 attr = default_attr;
5577 bold |= rev ? BACKGROUND_INTENSITY : FOREGROUND_INTENSITY;
5580 #ifndef COMMON_LVB_UNDERSCORE
5581 #define COMMON_LVB_UNDERSCORE 0x8000
5590 attr &= ~(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
5594 attr = attr & ~(FOREGROUND_BLUE | FOREGROUND_GREEN) | FOREGROUND_RED;
5598 attr = attr & ~(FOREGROUND_BLUE | FOREGROUND_RED) | FOREGROUND_GREEN;
5602 attr = attr & ~FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
5606 attr = attr & ~(FOREGROUND_GREEN | FOREGROUND_RED) | FOREGROUND_BLUE;
5610 attr = attr & ~FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED;
5614 attr = attr & ~FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN;
5618 attr |= FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
5622 attr &= ~(BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED);
5625 attr = attr & ~(BACKGROUND_BLUE | BACKGROUND_GREEN) | BACKGROUND_RED;
5628 attr = attr & ~(BACKGROUND_BLUE | BACKGROUND_RED) | BACKGROUND_GREEN;
5631 attr = attr & ~BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
5634 attr = attr & ~(BACKGROUND_GREEN | BACKGROUND_RED) | BACKGROUND_BLUE;
5637 attr = attr & ~BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_RED;
5640 attr = attr & ~BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN;
5643 attr |= BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
5659 CONSOLE_SCREEN_BUFFER_INFO csbi;
5666 if (!GetConsoleScreenBufferInfo(handle, &csbi))
return;
5667 if (count > 0 && seq[0] > 0) arg1 = seq[0];
5673 csbi.dwCursorPosition.X = 0;
5675 csbi.dwCursorPosition.Y -= arg1;
5676 if (csbi.dwCursorPosition.Y < 0)
5677 csbi.dwCursorPosition.Y = 0;
5678 SetConsoleCursorPosition(handle, csbi.dwCursorPosition);
5681 csbi.dwCursorPosition.X = 0;
5684 csbi.dwCursorPosition.Y += arg1;
5685 if (csbi.dwCursorPosition.Y >= csbi.dwSize.Y)
5686 csbi.dwCursorPosition.Y = csbi.dwSize.Y;
5687 SetConsoleCursorPosition(handle, csbi.dwCursorPosition);
5690 csbi.dwCursorPosition.X += arg1;
5691 if (csbi.dwCursorPosition.X >= csbi.dwSize.X)
5692 csbi.dwCursorPosition.X = csbi.dwSize.X;
5693 SetConsoleCursorPosition(handle, csbi.dwCursorPosition);
5696 csbi.dwCursorPosition.X -= arg1;
5697 if (csbi.dwCursorPosition.X < 0)
5698 csbi.dwCursorPosition.X = 0;
5699 SetConsoleCursorPosition(handle, csbi.dwCursorPosition);
5703 csbi.dwCursorPosition.X = (arg1 > csbi.dwSize.X ? csbi.dwSize.X : arg1) - 1;
5704 SetConsoleCursorPosition(handle, csbi.dwCursorPosition);
5707 csbi.dwCursorPosition.Y = (arg1 > csbi.dwSize.Y ? csbi.dwSize.Y : arg1) - 1;
5708 SetConsoleCursorPosition(handle, csbi.dwCursorPosition);
5712 pos.Y = (arg1 > csbi.dwSize.Y ? csbi.dwSize.Y : arg1) - 1;
5713 if (count < 2 || (arg1 = seq[1]) <= 0) arg1 = 1;
5714 pos.X = (arg1 > csbi.dwSize.X ? csbi.dwSize.X : arg1) - 1;
5715 SetConsoleCursorPosition(handle, pos);
5720 FillConsoleOutputCharacterW(handle, L
' ',
5721 csbi.dwSize.X * (csbi.dwSize.Y - csbi.dwCursorPosition.Y) - csbi.dwCursorPosition.X,
5722 csbi.dwCursorPosition, &written);
5726 pos.Y = csbi.dwCursorPosition.Y;
5727 FillConsoleOutputCharacterW(handle, L
' ',
5728 csbi.dwSize.X * csbi.dwCursorPosition.Y + csbi.dwCursorPosition.X,
5734 FillConsoleOutputCharacterW(handle, L
' ', csbi.dwSize.X * csbi.dwSize.Y, pos, &written);
5741 FillConsoleOutputCharacterW(handle, L
' ', csbi.dwSize.X - csbi.dwCursorPosition.X, csbi.dwCursorPosition, &written);
5745 pos.Y = csbi.dwCursorPosition.Y;
5746 FillConsoleOutputCharacterW(handle, L
' ', csbi.dwCursorPosition.X, pos, &written);
5750 pos.Y = csbi.dwCursorPosition.Y;
5751 FillConsoleOutputCharacterW(handle, L
' ', csbi.dwSize.X, pos, &written);
5759 SetConsoleCursorPosition(handle, s->
vt100.
saved);
5762 if (count >= 2 && seq[0] == -1 && seq[1] == 25) {
5763 CONSOLE_CURSOR_INFO cci;
5764 GetConsoleCursorInfo(handle, &cci);
5765 cci.bVisible =
TRUE;
5766 SetConsoleCursorInfo(handle, &cci);
5770 if (count >= 2 && seq[0] == -1 && seq[1] == 25) {
5771 CONSOLE_CURSOR_INFO cci;
5772 GetConsoleCursorInfo(handle, &cci);
5773 cci.bVisible =
FALSE;
5774 SetConsoleCursorInfo(handle, &cci);
5784 const WCHAR *ptr = *ptrp;
5785 long rest, len = *lenp;
5789 rest = *lenp - len - 1;
5793 rest = *lenp - len - 1;
5794 if (rest > 0) --rest;
5799 if (wc >= L
'0' && wc <= L
'9') {
5802 *seq = (*seq * 10) + (wc - L
'0');
5843 int save_errno =
errno;
5854 if (closesocket(sock) == SOCKET_ERROR) {
5864 memset(ol, 0,
sizeof(*ol));
5868 DWORD low = SetFilePointer((HANDLE)
_osfhnd(fd), 0, &high, method);
5869 #ifndef INVALID_SET_FILE_POINTER
5870 #define INVALID_SET_FILE_POINTER ((DWORD)-1)
5874 if (err != NO_ERROR) {
5880 ol->OffsetHigh = high;
5893 CloseHandle(ol->hEvent);
5896 LONG high = ol->OffsetHigh;
5898 if (low < ol->Offset)
5900 SetFilePointer((HANDLE)
_osfhnd(fd), low, &high, FILE_BEGIN);
5915 OVERLAPPED ol, *pol =
NULL;
5917 BOOL islineinput =
FALSE;
5924 if (_get_osfhandle(fd) == -1) {
5929 return _read(fd, buf, size);
5944 GetConsoleMode((HANDLE)
_osfhnd(fd),&mode);
5945 islineinput = (mode & ENABLE_LINE_INPUT) != 0;
5972 if (!ReadFile((HANDLE)
_osfhnd(fd), buf, len, &read, pol)) {
5973 err = GetLastError();
5974 if (err != ERROR_IO_PENDING) {
5975 if (pol) CloseHandle(ol.hEvent);
5976 if (err == ERROR_ACCESS_DENIED)
5978 else if (err == ERROR_BROKEN_PIPE || err == ERROR_HANDLE_EOF) {
5991 if (wait != WAIT_OBJECT_0) {
5992 if (wait == WAIT_OBJECT_0 + 1)
5996 CloseHandle(ol.hEvent);
6002 if (!GetOverlappedResult((HANDLE)
_osfhnd(fd), &ol, &read,
TRUE) &&
6003 (err = GetLastError()) != ERROR_HANDLE_EOF) {
6005 if (err != ERROR_BROKEN_PIPE) {
6009 CloseHandle(ol.hEvent);
6017 err = GetLastError();
6027 buf = (
char *)buf + read;
6028 if (err != ERROR_OPERATION_ABORTED &&
6029 !(isconsole && len == 1 && (!islineinput || *((
char *)buf - 1) ==
'\n')) && size > 0)
6052 OVERLAPPED ol, *pol =
NULL;
6058 if (_get_osfhandle(fd) == -1) {
6064 return _write(fd, buf, size);
6090 if (!WriteFile((HANDLE)
_osfhnd(fd), buf, len, &written, pol)) {
6091 err = GetLastError();
6092 if (err != ERROR_IO_PENDING) {
6093 if (pol) CloseHandle(ol.hEvent);
6094 if (err == ERROR_ACCESS_DENIED)
6105 if (wait != WAIT_OBJECT_0) {
6106 if (wait == WAIT_OBJECT_0 + 1)
6110 CloseHandle(ol.hEvent);
6116 if (!GetOverlappedResult((HANDLE)
_osfhnd(fd), &ol, &written,
6119 CloseHandle(ol.hEvent);
6132 if (written == len) {
6133 buf = (
const char *)buf + len;
6149 DWORD dwMode, reslen;
6152 const WCHAR *ptr, *next;
6156 if (disable)
return -1L;
6158 if (!GetConsoleMode(handle, &dwMode) ||
6168 long curlen =
constat_parse(handle, s, (next = ptr, &next), &len);
6170 if (!WriteConsoleW(handle, ptr, curlen, &reslen,
NULL)) {
6171 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
6179 return (
long)reslen;
6188 tmp.QuadPart = ((LONG_LONG)time + (LONG_LONG)((1970-1601)*365.2425) * 24 * 60 * 60) * 10 * 1000 * 1000;
6189 ft->dwLowDateTime = tmp.LowPart;
6190 ft->dwHighDateTime = tmp.HighPart;
6199 FILETIME atime, mtime;
6200 struct stati64 stat;
6216 GetSystemTimeAsFileTime(&atime);
6221 const DWORD attr = GetFileAttributesW(path);
6222 if (attr != (
DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY))
6223 SetFileAttributesW(path, attr & ~FILE_ATTRIBUTE_READONLY);
6224 hFile = CreateFileW(path, GENERIC_WRITE, 0, 0, OPEN_EXISTING,
6225 FILE_FLAG_BACKUP_SEMANTICS, 0);
6226 if (hFile == INVALID_HANDLE_VALUE) {
6231 if (!SetFileTime(hFile,
NULL, &atime, &mtime)) {
6237 if (attr != (
DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY))
6238 SetFileAttributesW(path, attr);
6253 ret =
wutime(wpath, times);
6267 ret =
wutime(wpath, times);
6281 ret = _wchdir(wpath);
6293 if (CreateDirectoryW(wpath,
NULL) ==
FALSE) {
6297 if (_wchmod(wpath, mode) == -1) {
6298 RemoveDirectoryW(wpath);
6315 ret =
wmkdir(wpath, mode);
6329 ret =
wmkdir(wpath, mode);
6340 const DWORD attr = GetFileAttributesW(wpath);
6341 if (attr != (
DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
6342 SetFileAttributesW(wpath, attr & ~FILE_ATTRIBUTE_READONLY);
6344 if (RemoveDirectoryW(wpath) ==
FALSE) {
6347 if (attr != (
DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
6348 SetFileAttributesW(wpath, attr);
6389 const DWORD attr = GetFileAttributesW(path);
6390 if (attr != (
DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
6391 SetFileAttributesW(path, attr & ~FILE_ATTRIBUTE_READONLY);
6393 if (!DeleteFileW(path)) {
6396 if (attr != (
DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
6397 SetFileAttributesW(path, attr);
6441 ret = _wchmod(wpath, mode);
6446 #if !defined(__BORLANDC__)
6454 if (_get_osfhandle(fd) == -1) {
6457 if (!GetConsoleMode((HANDLE)
_osfhnd(fd), &mode)) {
6472 too_many_files(
void)
6475 for (f = _streams; f < _streams + _nfile; f++) {
6476 if (f->fd < 0)
return 0;
6484 rb_w32_fopen(
const char *path,
const char *mode)
6486 FILE *f = (
errno = 0, fopen(path, mode));
6488 if (too_many_files())
6496 rb_w32_fdopen(
int handle,
const char *
type)
6498 FILE *f = (
errno = 0, _fdopen(handle, (
char *)type));
6502 else if (too_many_files())
6510 rb_w32_fsopen(
const char *path,
const char *mode,
int shflags)
6512 FILE *f = (
errno = 0, _fsopen(path, mode, shflags));
6514 if (too_many_files())
6521 #if defined(_MSC_VER) && RUBY_MSVCRT_VERSION <= 60
6522 extern long _ftol(
double);
6532 _ftol2_sse(
double d)
6543 int *ip = (
int *)(&x + 1) - 1;
6552 typedef char *(WSAAPI inet_ntop_t)(
int,
void *,
char *,
size_t);
6553 inet_ntop_t *pInetNtop;
6556 return pInetNtop(af, (
void *)addr, numaddr, numaddr_len);
6560 memcpy(&in.s_addr, addr,
sizeof(in.s_addr));
6561 snprintf(numaddr, numaddr_len,
"%s", inet_ntoa(in));
6573 #if RUBY_MSVCRT_VERSION < 80 && !defined(__MINGW64__)
6580 if (!FileTimeToSystemTime(&ft, st))
return -1;
6588 int y = st->wYear, m = st->wMonth, d = st->wDay;
6589 t->tm_sec = st->wSecond;
6590 t->tm_min = st->wMinute;
6591 t->tm_hour = st->wHour;
6592 t->tm_mday = st->wDay;
6593 t->tm_mon = st->wMonth - 1;
6594 t->tm_year = y - 1900;
6595 t->tm_wday = st->wDayOfWeek;
6603 d += 31 + 28 + (!(y % 4) && ((y % 100) || !(y % 400)));
6604 d += ((m - 3) * 153 + 2) / 5;
6614 TIME_ZONE_INFORMATION stdtz;
6617 if (!SystemTimeToTzSpecificLocalTime(tz, gst, lst))
return -1;
6619 GetTimeZoneInformation(&stdtz);
6622 if (tz->StandardBias == tz->DaylightBias)
return 0;
6623 if (!tz->StandardDate.wMonth)
return 0;
6624 if (!tz->DaylightDate.wMonth)
return 0;
6625 if (tz != &stdtz) stdtz = *tz;
6627 stdtz.StandardDate.wMonth = stdtz.DaylightDate.wMonth = 0;
6628 if (!SystemTimeToTzSpecificLocalTime(&stdtz, gst, &sst))
return 0;
6629 if (lst->wMinute == sst.wMinute && lst->wHour == sst.wHour)
6636 # ifndef MINGW_HAS_SECURE_API
6637 _CRTIMP errno_t __cdecl _gmtime64_s(
struct tm* tm,
const __time64_t *time);
6638 _CRTIMP errno_t __cdecl _localtime64_s(
struct tm* tm,
const __time64_t *time);
6640 # define gmtime_s _gmtime64_s
6641 # define localtime_s _localtime64_s
6654 #if RUBY_MSVCRT_VERSION >= 80 || defined(__MINGW64__)
6655 e = gmtime_s(rp, tp);
6656 if (e != 0)
goto error;
6678 #if RUBY_MSVCRT_VERSION >= 80 || defined(__MINGW64__)
6679 e = localtime_s(rp, tp);
6683 SYSTEMTIME gst, lst;
6697 int len =
sizeof(tmp);
6698 int r = getsockopt((SOCKET)h, SOL_SOCKET, SO_DEBUG, (
char *)&tmp, &len);
6699 if (r != SOCKET_ERROR || WSAGetLastError() != WSAENOTSOCK) {
6702 flags &= ~O_NONBLOCK;
struct tm * localtime_r(const time_t *tp, struct tm *rp)
static const char * NTLoginName
void setnetent(int stayopen)
static void regulate_path(WCHAR *path)
static int free_conlist(st_data_t key, st_data_t val, st_data_t arg)
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)
static WCHAR * mbstr_to_wstr(UINT, const char *, int, long *)
static char * skipspace(char *ptr)
int _cdecl gettimeofday(struct timeval *tv, struct timezone *tz)
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 *)
int rb_w32_wait_events(HANDLE *events, int num, DWORD timeout)
int rb_w32_access(const char *path, int mode)
#define CSIDL_LOCAL_APPDATA
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 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)
static void StartSockets(void)
static FARPROC get_wsa_extension_function(SOCKET s, GUID *guid)
if(dispIdMember==DISPID_VALUE)
#define access(path, mode)
static void init_func(void)
int rb_w32_pipe(int fds[2])
int rb_w32_wopen(const WCHAR *file, int oflag,...)
static ioinfo * _pioinfo(int)
static void catch_interrupt(void)
static void get_version(void)
static struct direct * readdir_internal(DIR *dirp, BOOL(*conv)(const WCHAR *, struct direct *, rb_encoding *), rb_encoding *enc)
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 rb_pid_t poll_child_status(struct ChildRecord *child, int *stat_loc)
static int NtSocketsInitialized
int st_insert(st_table *, st_data_t, st_data_t)
int WSAAPI rb_w32_connect(int s, const struct sockaddr *addr, int addrlen)
DIR * rb_w32_uopendir(const char *filename)
void rb_write_error2(const char *, long)
int rb_w32_io_cancelable_p(int fd)
void rb_w32_rewinddir(DIR *dirp)
VALUE rb_enc_from_encoding(rb_encoding *encoding)
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)
int WSAAPI rb_w32_bind(int s, const struct sockaddr *addr, int addrlen)
static int is_batch(const char *cmd)
struct servent *WSAAPI rb_w32_getservbyname(const char *name, const char *proto)
#define INVALID_SET_FILE_POINTER
uintptr_t(* asynchronous_func_t)(uintptr_t self, int argc, uintptr_t *argv)
SSL_METHOD *(* func)(void)
void st_free_table(st_table *)
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)
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 check_if_dir(const char *file)
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 void exit_handler(void)
struct _NtCmdLineElement * next
int rb_w32_fclose(FILE *fp)
int rb_w32_open(const char *file, int oflag,...)
BOOL(WINAPI * cancel_io_t)(HANDLE)
#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)
ssize_t rb_w32_write(int fd, const void *buf, size_t size)
#define filecp_to_wstr(str, plen)
int WSAAPI rb_w32_sendto(int fd, const char *buf, int len, int flags, const struct sockaddr *to, int tolen)
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 char * translate_char(char *p, int from, int to)
static BOOL ruby_direct_conv(const WCHAR *file, struct direct *entry, rb_encoding *enc)
int rb_w32_wrap_io_handle(HANDLE h, int flags)
int rb_w32_ustati64(const char *path, struct stati64 *st)
#define RUBY_CRITICAL(expr)
static uintptr_t flock_winnt(uintptr_t self, int argc, uintptr_t *argv)
static BOOL win32_direct_conv(const WCHAR *file, struct direct *entry, rb_encoding *dummy)
int fcntl(int fd, int cmd,...)
int WSAAPI rb_w32_socket(int af, int type, int protocol)
static int internal_cmd_match(const char *cmdname, int nt)
int st_lookup(st_table *, st_data_t, st_data_t *)
#define wstr_to_utf8(str, plen)
#define MEMZERO(p, type, n)
VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc)
char * rb_w32_getenv(const char *name)
rb_pid_t waitpid(rb_pid_t pid, int *stat_loc, int options)
static int is_pipe(SOCKET sock)
#define END_FOREACH_CHILD
#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
int rb_w32_stati64(const char *path, struct stati64 *st)
long rb_w32_telldir(DIR *dirp)
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_socketpair(int af, int type, int protocol, int *sv)
int rb_w32_uopen(const char *file, int oflag,...)
#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 st_delete(st_table *, st_data_t *, st_data_t *)
int link(const char *from, const char *to)
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)
static int has_redirection(const char *)
int rb_w32_isatty(int fd)
int rb_w32_sleep(unsigned long msec)
int rb_w32_rename(const char *from, const char *to)
#define ALLOCV_N(type, v, n)
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)
int rb_w32_utime(const char *path, const struct utimbuf *times)
static int setup_overlapped(OVERLAPPED *ol, int fd)
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)
void sethostent(int stayopen)
struct servent * getservent(void)
static int check_spawn_mode(int mode)
static cancel_io_t cancel_io
struct constat::@135 vt100
static void init_env(void)
static int join_argv(char *cmd, char *const *argv, BOOL escape)
static int filetime_to_timeval(const FILETIME *ft, struct timeval *tv)
static int is_not_socket(SOCKET sock)
static DWORD constat_attr(int count, const int *seq, DWORD attr, DWORD default_attr)
static int do_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *timeout)
static const char *const szInternalCmds[]
off_t rb_w32_ftello(FILE *stream)
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)
void rb_w32_sysinit(int *argc, char ***argv)
void rb_fatal(const char *fmt,...)
static struct ChildRecord * FindChildSlot(rb_pid_t pid)
int WSAAPI rb_w32_shutdown(int s, int how)
VALUE rb_str_vcatf(VALUE, const char *, va_list)
static int finish_overlapped_socket(BOOL input, SOCKET s, WSAOVERLAPPED *wol, int result, DWORD *len, DWORD size)
static CRITICAL_SECTION select_mutex
struct netent * getnetent(void)
void setprotoent(int stayopen)
int fseeko(FILE *stream, off_t offset, int whence)
char * dln_find_exe_r(const char *, const char *, char *, size_t)
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,...)
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)
int flock(int fd, int oper)
static int options(unsigned char *cp)
static int unixtime_to_filetime(time_t time, FILETIME *ft)
int rb_w32_getc(FILE *stream)
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 rb_w32_unlink(const char *path)
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 chown(const char *path, int owner, int group)
static rb_pid_t child_result(struct ChildRecord *child, int mode)
static struct @133 errmap[]
st_table * st_init_numtable(void)
int rb_w32_fstati64(int fd, struct stati64 *st)
static int internal_match(const void *key, const void *elem)
int rb_w32_putc(int c, FILE *stream)
static UINT get_system_directory(WCHAR *path, UINT len)
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)
int rb_w32_rmdir(const char *path)
int WSAAPI rb_w32_listen(int s, int backlog)
int kill(int pid, int sig)
static void constat_delete(HANDLE h)
#define ECONV_UNDEF_REPLACE
rb_encoding * rb_enc_get(VALUE obj)
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 NtCmdLineElement ** cmdglob(NtCmdLineElement *patt, NtCmdLineElement **tail)
char ** rb_w32_get_environ(void)
static DIR * opendir_internal(WCHAR *wpath, const char *filename)
void rb_w32_closedir(DIR *dirp)
static int wlink(const WCHAR *from, const WCHAR *to)
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 struct constat * constat_handle(HANDLE h)
#define _set_osfhnd(fh, osfh)
#define acp_to_wstr(str, plen)
static int systemtime_to_localtime(TIME_ZONE_INFORMATION *tz, SYSTEMTIME *gst, SYSTEMTIME *lst)
struct hostent *WSAAPI rb_w32_gethostbyname(const char *name)
RUBY_EXTERN char * strerror(int)
static int is_console(SOCKET)
static int is_readable_pipe(SOCKET sock)
static char * wstr_to_mbstr(UINT, const WCHAR *, int, long *)
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
int ruby_brace_glob(const char *str, int flags, ruby_glob_func *func, VALUE arg)
#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)
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)
static int dupfd(HANDLE hDup, char flags, int minfd)
RUBY_EXTERN size_t strlcat(char *, const char *, size_t)
#define COMMON_LVB_UNDERSCORE
static char fbuf[MAXPATHLEN]
static void move_to_next_entry(DIR *dirp)
static void systemtime_to_tm(const SYSTEMTIME *st, struct tm *t)
char * rb_w32_getcwd(char *buffer, int size)
rb_encoding * rb_ascii8bit_encoding(void)
#define yield_until(condition)
static int overlapped_socket_io(BOOL input, int fd, char *buf, int len, int flags, struct sockaddr *addr, int *addrlen)
static void version(void)
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)
VALUE rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts)
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 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
int rb_w32_cmdvector(const char *cmd, char ***vec)
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)
static int is_readable_console(SOCKET sock)
static BOOL get_special_folder(int n, WCHAR *env)
char rb_w32_fd_is_text(int fd)
static int eq(VALUE x, VALUE y)
int st_foreach(st_table *, int(*)(ANYARGS), st_data_t)
static ULONG(STDMETHODCALLTYPE AddRef)(IDispatch __RPC_FAR *This)
int rb_w32_check_interrupt(void *)
int rb_w32_times(struct tms *tmbuf)
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)
rb_encoding * rb_enc_find(const char *name)
static int check_valid_dir(const WCHAR *path)
static st_table * conlist
#define _set_osflags(fh, flags)
static void constat_reset(HANDLE h)
static int wunlink(const WCHAR *path)