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)
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 },
232 if (
errmap[i].winerr == winerr) {
237 if (winerr >= WSABASEERR) {
243 #define map_errno rb_w32_map_errno
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;
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);
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)
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++ =
'"';
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
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) {
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;
3648 sock_in4.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
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)) {
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)
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)
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 (!MoveFileW(oldpath, newpath))
4351 switch (GetLastError()) {
4352 case ERROR_ALREADY_EXISTS:
4353 case ERROR_FILE_EXISTS:
4354 if (MoveFileExW(oldpath, newpath, MOVEFILE_REPLACE_EXISTING))
4362 SetFileAttributesW(newpath, oldatts);
4410 if (path[0] == L
'\\' && path[1] == L
'\\') {
4411 const WCHAR *
p = path + 2;
4412 if (p[0] == L
'?' && p[1] == L
'\\') {
4420 for (p++; *
p; p++) {
4424 if (!p[0] || !p[1] || (p[1] == L
'.' && !p[2]))
4431 #define COPY_STAT(src, dest, size_cast) do { \
4432 (dest).st_dev = (src).st_dev; \
4433 (dest).st_ino = (src).st_ino; \
4434 (dest).st_mode = (src).st_mode; \
4435 (dest).st_nlink = (src).st_nlink; \
4436 (dest).st_uid = (src).st_uid; \
4437 (dest).st_gid = (src).st_gid; \
4438 (dest).st_rdev = (src).st_rdev; \
4439 (dest).st_size = size_cast(src).st_size; \
4440 (dest).st_atime = (src).st_atime; \
4441 (dest).st_mtime = (src).st_mtime; \
4442 (dest).st_ctime = (src).st_ctime; \
4452 BY_HANDLE_FILE_INFORMATION
info;
4455 if (ret)
return ret;
4459 if (GetFileInformationByHandle((HANDLE)_get_osfhandle(fd), &info)) {
4461 if (!(info.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
4476 BY_HANDLE_FILE_INFORMATION
info;
4480 if (ret)
return ret;
4485 if (GetFileInformationByHandle((HANDLE)_get_osfhandle(fd), &info)) {
4487 if (!(info.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
4491 st->st_size = ((__int64)info.nFileSizeHigh << 32) | info.nFileSizeLow;
4517 if (attr & FILE_ATTRIBUTE_READONLY) {
4521 mode |= S_IREAD | S_IWRITE |
S_IWUSR;
4524 if (attr & FILE_ATTRIBUTE_DIRECTORY) {
4525 mode |= S_IFDIR | S_IEXEC;
4531 if (path && (mode & S_IFREG)) {
4532 const WCHAR *
end = path + lstrlenW(path);
4533 while (path < end) {
4534 end = CharPrevW(path, end);
4536 if ((_wcsicmp(end, L
".bat") == 0) ||
4537 (_wcsicmp(end, L
".cmd") == 0) ||
4538 (_wcsicmp(end, L
".com") == 0) ||
4539 (_wcsicmp(end, L
".exe") == 0)) {
4547 mode |= (mode & 0700) >> 3;
4548 mode |= (mode & 0700) >> 6;
4557 WIN32_FIND_DATAW fd;
4559 WCHAR full[MAX_PATH];
4565 if (!(p = wcsstr(path, L
"...")))
4567 q = p + wcsspn(p, L
".");
4568 if ((p == path || wcschr(L
":/\\", *(p - 1))) &&
4569 (!*q || wcschr(L
":/\\", *q))) {
4576 if (!GetFullPathNameW(path,
sizeof(full) /
sizeof(WCHAR), full, &dmy)) {
4580 if (full[1] == L
':' && !full[3] && GetDriveTypeW(full) != DRIVE_NO_ROOT_DIR)
4584 if (fh == INVALID_HANDLE_VALUE)
4595 WIN32_FIND_DATAW wfd;
4596 WIN32_FILE_ATTRIBUTE_DATA wfa;
4597 const WCHAR *
p =
path;
4599 memset(st, 0,
sizeof(*st));
4602 if (wcsncmp(p, L
"\\\\?\\", 4) == 0) p += 4;
4603 if (wcspbrk(p, L
"?*")) {
4607 if (GetFileAttributesExW(path, GetFileExInfoStandard, (
void*)&wfa)) {
4608 if (wfa.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
4613 st->st_size = ((__int64)wfa.nFileSizeHigh << 32) | wfa.nFileSizeLow;
4622 int e = GetLastError();
4624 if ((e == ERROR_FILE_NOT_FOUND) || (e == ERROR_INVALID_NAME)
4625 || (e == ERROR_PATH_NOT_FOUND || (e == ERROR_BAD_NETPATH))) {
4631 h = FindFirstFileW(path, &wfd);
4632 if (h != INVALID_HANDLE_VALUE) {
4638 st->st_size = ((__int64)wfd.nFileSizeHigh << 32) | wfd.nFileSizeLow;
4646 st->st_dev = st->st_rdev = (iswalpha(path[0]) && path[1] == L
':') ?
4647 towupper(path[0]) - L
'A' : _getdrive() - 1;
4668 WCHAR *buf1, *
s, *
end;
4677 size = lstrlenW(path) + 2;
4679 for (p = path, s = buf1; *
p; p++, s++) {
4687 if (!len || L
'\"' == *(--s)) {
4691 end = buf1 + len - 1;
4696 else if (*end != L
'\\')
4697 lstrcatW(buf1, L
"\\");
4699 else if (*end == L
'\\' || (buf1 + 1 == end && *end == L
':'))
4700 lstrcatW(buf1, L
".");
4744 struct stati64 stat;
4748 if ((stat.st_mode & mode) != mode) {
4759 struct stati64 stat;
4763 if ((stat.st_mode & mode) != mode) {
4774 long upos, lpos, usize, lsize;
4778 if ((lpos = SetFilePointer(h, 0, (upos = 0, &upos),
SEEK_CUR)) == -1L &&
4779 (e = GetLastError())) {
4783 usize = (long)(size >> 32);
4785 if (SetFilePointer(h, lsize, &usize,
SEEK_SET) == (
DWORD)-1L &&
4786 (e = GetLastError())) {
4789 else if (!SetEndOfFile(h)) {
4795 SetFilePointer(h, lpos, &upos,
SEEK_SET);
4805 h = CreateFile(path, GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
4806 if (h == INVALID_HANDLE_VALUE) {
4821 h = (HANDLE)_get_osfhandle(fd);
4822 if (h == (HANDLE)-1)
return -1;
4829 _filelengthi64(
int fd)
4834 l = GetFileSize((HANDLE)_get_osfhandle(fd), &u);
4835 if (l == (
DWORD)-1L && (e = GetLastError())) {
4839 return ((
off_t)u << 32) | l;
4844 _lseeki64(
int fd,
off_t offset,
int whence)
4848 HANDLE h = (HANDLE)_get_osfhandle(fd);
4854 u = (long)(offset >> 32);
4855 if ((l = SetFilePointer(h, (
long)offset, &u, whence)) == -1L &&
4856 (e = GetLastError())) {
4860 return ((
off_t)u << 32) | l;
4871 if (fgetpos(stream, (fpos_t *)&pos))
4876 if ((pos = _filelengthi64(
fileno(stream))) == (
off_t)-1)
4884 return fsetpos(stream, (fpos_t *)&pos);
4892 if (fgetpos(stream, (fpos_t *)&pos))
return (
off_t)-1;
4900 __int64 qw = ft->dwHighDateTime;
4902 qw |= ft->dwLowDateTime;
4911 FILETIME create, exit, kernel, user;
4913 if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
4928 #define yield_once() Sleep(0)
4929 #define yield_until(condition) do yield_once(); while (!(condition))
4939 #if defined __BORLANDC__
4943 read(
int fd,
void *
buf,
size_t size)
4945 int ret = _read(fd, buf, size);
4946 if ((ret < 0) && (
errno == EPIPE)) {
4956 #define FILE_COUNT _cnt
4957 #define FILE_READPTR _ptr
4966 c = (
unsigned char)*stream->FILE_READPTR++;
4969 c = _filbuf(stream);
4970 #if defined __BORLANDC__
4971 if ((c ==
EOF) && (
errno == EPIPE)) {
4986 c = (
unsigned char)(*stream->FILE_READPTR++ = (
char)
c);
4989 c = _flsbuf(c, stream);
5026 BOOL interrupted =
FALSE;
5047 if (TerminateThread(thr, intrval)) {
5052 GetExitCodeThread(thr, &val);
5057 MEMORY_BASIC_INFORMATION
m;
5059 memset(&m, 0,
sizeof(m));
5060 if (!VirtualQuery(arg.
stackaddr, &m,
sizeof(m))) {
5061 Debug(fprintf(stderr,
"couldn't get stack base:%p:%d\n",
5064 else if (!VirtualFree(m.AllocationBase, 0, MEM_RELEASE)) {
5065 Debug(fprintf(stderr,
"couldn't release stack:%p:%d\n",
5066 m.AllocationBase, GetLastError()));
5077 rb_fatal(
"failed to launch waiter thread:%ld", GetLastError());
5087 WCHAR *envtop, *
env;
5088 char **myenvtop, **myenv;
5101 envtop = GetEnvironmentStringsW();
5102 for (env = envtop, num = 0; *
env; env += lstrlenW(env) + 1)
5103 if (*env !=
'=') num++;
5105 myenvtop = (
char **)
malloc(
sizeof(
char *) * (num + 1));
5106 for (env = envtop, myenv = myenvtop; *
env; env += lstrlenW(env) + 1) {
5115 FreeEnvironmentStringsW(envtop);
5126 while (*t)
free(*t++);
5134 return GetCurrentProcessId();
5142 typedef long (WINAPI query_func)(HANDLE,
int,
void *,
ULONG, ULONG *);
5143 static query_func *pNtQueryInformationProcess =
NULL;
5147 if (!pNtQueryInformationProcess)
5148 pNtQueryInformationProcess = (query_func *)
get_proc_address(
"ntdll.dll",
"NtQueryInformationProcess",
NULL);
5149 if (pNtQueryInformationProcess) {
5152 void* PebBaseAddress;
5159 long ret = pNtQueryInformationProcess(GetCurrentProcess(), 0, &pbi,
sizeof(pbi), &len);
5161 ppid = pbi.ParentProcessId;
5178 va_start(arg, oflag);
5179 pmode = va_arg(arg,
int);
5193 DWORD attr = GetFileAttributesW(wfile);
5194 if (attr == (
DWORD)-1L ||
5195 !(attr & FILE_ATTRIBUTE_DIRECTORY) ||
5226 va_start(arg, oflag);
5227 pmode = va_arg(arg,
int);
5230 if ((oflag & O_TEXT) || !(oflag &
O_BINARY)) {
5231 ret = _open(file, oflag, pmode);
5250 DWORD attr = FILE_ATTRIBUTE_NORMAL;
5251 SECURITY_ATTRIBUTES sec;
5254 if ((oflag & O_TEXT) || !(oflag &
O_BINARY)) {
5257 va_start(arg, oflag);
5258 pmode = va_arg(arg,
int);
5260 fd = _wopen(file, oflag, pmode);
5265 sec.nLength =
sizeof(sec);
5266 sec.lpSecurityDescriptor =
NULL;
5267 if (oflag & O_NOINHERIT) {
5268 sec.bInheritHandle =
FALSE;
5272 sec.bInheritHandle =
TRUE;
5274 oflag &= ~O_NOINHERIT;
5277 oflag &= ~(O_BINARY | O_TEXT);
5279 switch (oflag & (O_RDWR | O_RDONLY | O_WRONLY)) {
5281 access = GENERIC_READ | GENERIC_WRITE;
5284 access = GENERIC_READ;
5287 access = GENERIC_WRITE;
5293 oflag &= ~(O_RDWR | O_RDONLY | O_WRONLY);
5295 switch (oflag & (O_CREAT | O_EXCL | O_TRUNC)) {
5297 create = OPEN_ALWAYS;
5301 create = OPEN_EXISTING;
5303 case O_CREAT | O_EXCL:
5304 case O_CREAT | O_EXCL | O_TRUNC:
5305 create = CREATE_NEW;
5308 case O_TRUNC | O_EXCL:
5309 create = TRUNCATE_EXISTING;
5311 case O_CREAT | O_TRUNC:
5312 create = CREATE_ALWAYS;
5318 if (oflag & O_CREAT) {
5321 va_start(arg, oflag);
5322 pmode = va_arg(arg,
int);
5325 if (!(pmode & S_IWRITE))
5326 attr = FILE_ATTRIBUTE_READONLY;
5328 oflag &= ~(O_CREAT | O_EXCL | O_TRUNC);
5330 if (oflag & O_TEMPORARY) {
5331 attr |= FILE_FLAG_DELETE_ON_CLOSE;
5334 oflag &= ~O_TEMPORARY;
5336 if (oflag & _O_SHORT_LIVED)
5337 attr |= FILE_ATTRIBUTE_TEMPORARY;
5338 oflag &= ~_O_SHORT_LIVED;
5340 switch (oflag & (O_SEQUENTIAL | O_RANDOM)) {
5344 attr |= FILE_FLAG_SEQUENTIAL_SCAN;
5347 attr |= FILE_FLAG_RANDOM_ACCESS;
5353 oflag &= ~(O_SEQUENTIAL | O_RANDOM);
5355 if (oflag & ~O_APPEND) {
5362 h = CreateFile(
"NUL", 0, 0,
NULL, OPEN_ALWAYS, 0,
NULL);
5363 fd = _open_osfhandle((
intptr_t)h, 0);
5375 h = CreateFileW(file, access, FILE_SHARE_READ | FILE_SHARE_WRITE, &sec,
5376 create, attr,
NULL);
5377 if (h == INVALID_HANDLE_VALUE) {
5378 DWORD e = GetLastError();
5386 switch (GetFileType(h)) {
5387 case FILE_TYPE_CHAR:
5390 case FILE_TYPE_PIPE:
5393 case FILE_TYPE_UNKNOWN:
5400 if (!(flags & (
FDEV |
FPIPE)) && (oflag & O_APPEND))
5420 int save_errno =
errno;
5422 if (fflush(fp))
return -1;
5430 if (closesocket(sock) == SOCKET_ERROR) {
5441 static DWORD serial = 0;
5442 char name[] =
"\\\\.\\pipe\\ruby0000000000000000-0000000000000000";
5444 SECURITY_ATTRIBUTES sec;
5445 HANDLE hRead, hWrite, h;
5446 int fdRead, fdWrite;
5451 return _pipe(fds, 65536L, _O_NOINHERIT);
5456 sec.nLength =
sizeof(sec);
5457 sec.lpSecurityDescriptor =
NULL;
5458 sec.bInheritHandle =
FALSE;
5461 hRead = CreateNamedPipe(name, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
5462 0, 2, 65536, 65536, 0, &sec);
5464 if (hRead == INVALID_HANDLE_VALUE) {
5466 if (err == ERROR_PIPE_BUSY)
5474 hWrite = CreateFile(name, GENERIC_READ | GENERIC_WRITE, 0, &sec,
5475 OPEN_EXISTING, FILE_FLAG_OVERLAPPED,
NULL);
5477 if (hWrite == INVALID_HANDLE_VALUE) {
5485 h = CreateFile(
"NUL", 0, 0,
NULL, OPEN_ALWAYS, 0,
NULL);
5486 fdRead = _open_osfhandle((
intptr_t)h, 0);
5490 CloseHandle(hWrite);
5505 h = CreateFile(
"NUL", 0, 0,
NULL, OPEN_ALWAYS, 0,
NULL);
5506 fdWrite = _open_osfhandle((
intptr_t)h, 0);
5508 if (fdWrite == -1) {
5510 CloseHandle(hWrite);
5543 CONSOLE_SCREEN_BUFFER_INFO csbi;
5546 p->
vt100.
attr = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
5548 if (GetConsoleScreenBufferInfo(h, &csbi)) {
5562 if (!conlist)
return;
5572 #define FOREGROUND_MASK (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)
5573 #define BACKGROUND_MASK (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED)
5574 DWORD bold = attr & (FOREGROUND_INTENSITY | BACKGROUND_INTENSITY);
5577 if (!count)
return attr;
5578 while (count-- > 0) {
5581 attr = default_attr;
5586 bold |= rev ? BACKGROUND_INTENSITY : FOREGROUND_INTENSITY;
5589 #ifndef COMMON_LVB_UNDERSCORE
5590 #define COMMON_LVB_UNDERSCORE 0x8000
5599 attr &= ~(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
5603 attr = attr & ~(FOREGROUND_BLUE | FOREGROUND_GREEN) | FOREGROUND_RED;
5607 attr = attr & ~(FOREGROUND_BLUE | FOREGROUND_RED) | FOREGROUND_GREEN;
5611 attr = attr & ~FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
5615 attr = attr & ~(FOREGROUND_GREEN | FOREGROUND_RED) | FOREGROUND_BLUE;
5619 attr = attr & ~FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED;
5623 attr = attr & ~FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN;
5627 attr |= FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
5631 attr &= ~(BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED);
5634 attr = attr & ~(BACKGROUND_BLUE | BACKGROUND_GREEN) | BACKGROUND_RED;
5637 attr = attr & ~(BACKGROUND_BLUE | BACKGROUND_RED) | BACKGROUND_GREEN;
5640 attr = attr & ~BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
5643 attr = attr & ~(BACKGROUND_GREEN | BACKGROUND_RED) | BACKGROUND_BLUE;
5646 attr = attr & ~BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_RED;
5649 attr = attr & ~BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN;
5652 attr |= BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
5668 CONSOLE_SCREEN_BUFFER_INFO csbi;
5675 if (!GetConsoleScreenBufferInfo(handle, &csbi))
return;
5676 if (count > 0 && seq[0] > 0) arg1 = seq[0];
5682 csbi.dwCursorPosition.X = 0;
5684 csbi.dwCursorPosition.Y -= arg1;
5685 if (csbi.dwCursorPosition.Y < 0)
5686 csbi.dwCursorPosition.Y = 0;
5687 SetConsoleCursorPosition(handle, csbi.dwCursorPosition);
5690 csbi.dwCursorPosition.X = 0;
5693 csbi.dwCursorPosition.Y += arg1;
5694 if (csbi.dwCursorPosition.Y >= csbi.dwSize.Y)
5695 csbi.dwCursorPosition.Y = csbi.dwSize.Y;
5696 SetConsoleCursorPosition(handle, csbi.dwCursorPosition);
5699 csbi.dwCursorPosition.X += arg1;
5700 if (csbi.dwCursorPosition.X >= csbi.dwSize.X)
5701 csbi.dwCursorPosition.X = csbi.dwSize.X;
5702 SetConsoleCursorPosition(handle, csbi.dwCursorPosition);
5705 csbi.dwCursorPosition.X -= arg1;
5706 if (csbi.dwCursorPosition.X < 0)
5707 csbi.dwCursorPosition.X = 0;
5708 SetConsoleCursorPosition(handle, csbi.dwCursorPosition);
5712 csbi.dwCursorPosition.X = (arg1 > csbi.dwSize.X ? csbi.dwSize.X : arg1) - 1;
5713 SetConsoleCursorPosition(handle, csbi.dwCursorPosition);
5716 csbi.dwCursorPosition.Y = (arg1 > csbi.dwSize.Y ? csbi.dwSize.Y : arg1) - 1;
5717 SetConsoleCursorPosition(handle, csbi.dwCursorPosition);
5721 pos.Y = (arg1 > csbi.dwSize.Y ? csbi.dwSize.Y : arg1) - 1;
5722 if (count < 2 || (arg1 = seq[1]) <= 0) arg1 = 1;
5723 pos.X = (arg1 > csbi.dwSize.X ? csbi.dwSize.X : arg1) - 1;
5724 SetConsoleCursorPosition(handle, pos);
5729 FillConsoleOutputCharacterW(handle, L
' ',
5730 csbi.dwSize.X * (csbi.dwSize.Y - csbi.dwCursorPosition.Y) - csbi.dwCursorPosition.X,
5731 csbi.dwCursorPosition, &written);
5735 pos.Y = csbi.dwCursorPosition.Y;
5736 FillConsoleOutputCharacterW(handle, L
' ',
5737 csbi.dwSize.X * csbi.dwCursorPosition.Y + csbi.dwCursorPosition.X,
5743 FillConsoleOutputCharacterW(handle, L
' ', csbi.dwSize.X * csbi.dwSize.Y, pos, &written);
5750 FillConsoleOutputCharacterW(handle, L
' ', csbi.dwSize.X - csbi.dwCursorPosition.X, csbi.dwCursorPosition, &written);
5754 pos.Y = csbi.dwCursorPosition.Y;
5755 FillConsoleOutputCharacterW(handle, L
' ', csbi.dwCursorPosition.X, pos, &written);
5759 pos.Y = csbi.dwCursorPosition.Y;
5760 FillConsoleOutputCharacterW(handle, L
' ', csbi.dwSize.X, pos, &written);
5768 SetConsoleCursorPosition(handle, s->
vt100.
saved);
5771 if (count >= 2 && seq[0] == -1 && seq[1] == 25) {
5772 CONSOLE_CURSOR_INFO cci;
5773 GetConsoleCursorInfo(handle, &cci);
5774 cci.bVisible =
TRUE;
5775 SetConsoleCursorInfo(handle, &cci);
5779 if (count >= 2 && seq[0] == -1 && seq[1] == 25) {
5780 CONSOLE_CURSOR_INFO cci;
5781 GetConsoleCursorInfo(handle, &cci);
5782 cci.bVisible =
FALSE;
5783 SetConsoleCursorInfo(handle, &cci);
5793 const WCHAR *
ptr = *ptrp;
5794 long rest,
len = *lenp;
5798 rest = *lenp - len - 1;
5802 rest = *lenp - len - 1;
5803 if (rest > 0) --rest;
5808 if (wc >= L
'0' && wc <= L
'9') {
5811 *seq = (*seq * 10) + (wc - L
'0');
5852 int save_errno =
errno;
5863 if (closesocket(sock) == SOCKET_ERROR) {
5873 memset(ol, 0,
sizeof(*ol));
5877 DWORD low = SetFilePointer((HANDLE)
_osfhnd(fd), 0, &high, method);
5878 #ifndef INVALID_SET_FILE_POINTER
5879 #define INVALID_SET_FILE_POINTER ((DWORD)-1)
5883 if (err != NO_ERROR) {
5889 ol->OffsetHigh = high;
5902 CloseHandle(ol->hEvent);
5905 LONG high = ol->OffsetHigh;
5907 if (low < ol->Offset)
5909 SetFilePointer((HANDLE)
_osfhnd(fd), low, &high, FILE_BEGIN);
5924 OVERLAPPED ol, *pol =
NULL;
5926 BOOL islineinput =
FALSE;
5933 if (_get_osfhandle(fd) == -1) {
5938 return _read(fd, buf, size);
5953 GetConsoleMode((HANDLE)
_osfhnd(fd),&mode);
5954 islineinput = (mode & ENABLE_LINE_INPUT) != 0;
5981 if (!ReadFile((HANDLE)
_osfhnd(fd), buf, len, &read, pol)) {
5982 err = GetLastError();
5983 if (err != ERROR_IO_PENDING) {
5984 if (pol) CloseHandle(ol.hEvent);
5985 if (err == ERROR_ACCESS_DENIED)
5987 else if (err == ERROR_BROKEN_PIPE || err == ERROR_HANDLE_EOF) {
6000 if (wait != WAIT_OBJECT_0) {
6001 if (wait == WAIT_OBJECT_0 + 1)
6005 CloseHandle(ol.hEvent);
6011 if (!GetOverlappedResult((HANDLE)
_osfhnd(fd), &ol, &read,
TRUE) &&
6012 (err = GetLastError()) != ERROR_HANDLE_EOF) {
6014 if (err != ERROR_BROKEN_PIPE) {
6018 CloseHandle(ol.hEvent);
6026 err = GetLastError();
6036 buf = (
char *)buf + read;
6037 if (err != ERROR_OPERATION_ABORTED &&
6038 !(isconsole && len == 1 && (!islineinput || *((
char *)buf - 1) ==
'\n')) && size > 0)
6061 OVERLAPPED ol, *pol =
NULL;
6067 if (_get_osfhandle(fd) == -1) {
6073 return _write(fd, buf, size);
6099 if (!WriteFile((HANDLE)
_osfhnd(fd), buf, len, &written, pol)) {
6100 err = GetLastError();
6101 if (err != ERROR_IO_PENDING) {
6102 if (pol) CloseHandle(ol.hEvent);
6103 if (err == ERROR_ACCESS_DENIED)
6114 if (wait != WAIT_OBJECT_0) {
6115 if (wait == WAIT_OBJECT_0 + 1)
6119 CloseHandle(ol.hEvent);
6125 if (!GetOverlappedResult((HANDLE)
_osfhnd(fd), &ol, &written,
6128 CloseHandle(ol.hEvent);
6141 if (written == len) {
6142 buf = (
const char *)buf + len;
6158 DWORD dwMode, reslen;
6161 const WCHAR *
ptr, *next;
6165 if (disable)
return -1L;
6167 if (!GetConsoleMode(handle, &dwMode) ||
6177 long curlen =
constat_parse(handle, s, (next = ptr, &next), &len);
6179 if (!WriteConsoleW(handle, ptr, curlen, &reslen,
NULL)) {
6180 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
6188 return (
long)reslen;
6197 tmp.QuadPart = ((LONG_LONG)time + (LONG_LONG)((1970-1601)*365.2425) * 24 * 60 * 60) * 10 * 1000 * 1000;
6198 ft->dwLowDateTime = tmp.LowPart;
6199 ft->dwHighDateTime = tmp.HighPart;
6208 FILETIME atime,
mtime;
6209 struct stati64 stat;
6225 GetSystemTimeAsFileTime(&atime);
6230 const DWORD attr = GetFileAttributesW(path);
6231 if (attr != (
DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY))
6232 SetFileAttributesW(path, attr & ~FILE_ATTRIBUTE_READONLY);
6233 hFile = CreateFileW(path, GENERIC_WRITE, 0, 0, OPEN_EXISTING,
6234 FILE_FLAG_BACKUP_SEMANTICS, 0);
6235 if (hFile == INVALID_HANDLE_VALUE) {
6240 if (!SetFileTime(hFile,
NULL, &atime, &mtime)) {
6246 if (attr != (
DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY))
6247 SetFileAttributesW(path, attr);
6262 ret =
wutime(wpath, times);
6276 ret =
wutime(wpath, times);
6290 ret = _wchdir(wpath);
6302 if (CreateDirectoryW(wpath,
NULL) ==
FALSE) {
6306 if (_wchmod(wpath, mode) == -1) {
6307 RemoveDirectoryW(wpath);
6324 ret =
wmkdir(wpath, mode);
6338 ret =
wmkdir(wpath, mode);
6349 const DWORD attr = GetFileAttributesW(wpath);
6350 if (attr != (
DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
6351 SetFileAttributesW(wpath, attr & ~FILE_ATTRIBUTE_READONLY);
6353 if (RemoveDirectoryW(wpath) ==
FALSE) {
6356 if (attr != (
DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
6357 SetFileAttributesW(wpath, attr);
6398 const DWORD attr = GetFileAttributesW(path);
6399 if (attr != (
DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
6400 SetFileAttributesW(path, attr & ~FILE_ATTRIBUTE_READONLY);
6402 if (!DeleteFileW(path)) {
6405 if (attr != (
DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
6406 SetFileAttributesW(path, attr);
6450 ret = _wchmod(wpath, mode);
6455 #if !defined(__BORLANDC__)
6463 if (_get_osfhandle(fd) == -1) {
6466 if (!GetConsoleMode((HANDLE)
_osfhnd(fd), &mode)) {
6481 too_many_files(
void)
6484 for (f = _streams; f < _streams + _nfile; f++) {
6485 if (f->fd < 0)
return 0;
6493 rb_w32_fopen(
const char *
path,
const char *
mode)
6495 FILE *f = (
errno = 0, fopen(path, mode));
6497 if (too_many_files())
6505 rb_w32_fdopen(
int handle,
const char *
type)
6507 FILE *f = (
errno = 0, _fdopen(handle, (
char *)type));
6511 else if (too_many_files())
6519 rb_w32_fsopen(
const char *path,
const char *mode,
int shflags)
6521 FILE *f = (
errno = 0, _fsopen(path, mode, shflags));
6523 if (too_many_files())
6530 #if defined(_MSC_VER) && RUBY_MSVCRT_VERSION <= 60
6531 extern long _ftol(
double);
6541 _ftol2_sse(
double d)
6552 int *
ip = (
int *)(&x + 1) - 1;
6561 typedef char *(WSAAPI inet_ntop_t)(
int,
void *,
char *,
size_t);
6562 inet_ntop_t *pInetNtop;
6565 return pInetNtop(af, (
void *)addr, numaddr, numaddr_len);
6569 memcpy(&in.s_addr, addr,
sizeof(in.s_addr));
6570 snprintf(numaddr, numaddr_len,
"%s", inet_ntoa(in));
6582 #if RUBY_MSVCRT_VERSION < 80 && !defined(__MINGW64__)
6589 if (!FileTimeToSystemTime(&ft, st))
return -1;
6597 int y = st->wYear,
m = st->wMonth,
d = st->wDay;
6598 t->tm_sec = st->wSecond;
6599 t->tm_min = st->wMinute;
6600 t->tm_hour = st->wHour;
6601 t->tm_mday = st->wDay;
6602 t->tm_mon = st->wMonth - 1;
6603 t->tm_year = y - 1900;
6604 t->tm_wday = st->wDayOfWeek;
6612 d += 31 + 28 + (!(y % 4) && ((y % 100) || !(y % 400)));
6613 d += ((
m - 3) * 153 + 2) / 5;
6623 TIME_ZONE_INFORMATION stdtz;
6626 if (!SystemTimeToTzSpecificLocalTime(tz, gst, lst))
return -1;
6628 GetTimeZoneInformation(&stdtz);
6631 if (tz->StandardBias == tz->DaylightBias)
return 0;
6632 if (!tz->StandardDate.wMonth)
return 0;
6633 if (!tz->DaylightDate.wMonth)
return 0;
6634 if (tz != &stdtz) stdtz = *tz;
6636 stdtz.StandardDate.wMonth = stdtz.DaylightDate.wMonth = 0;
6637 if (!SystemTimeToTzSpecificLocalTime(&stdtz, gst, &sst))
return 0;
6638 if (lst->wMinute == sst.wMinute && lst->wHour == sst.wHour)
6645 # ifndef MINGW_HAS_SECURE_API
6646 _CRTIMP errno_t __cdecl _gmtime64_s(
struct tm* tm,
const __time64_t *
time);
6647 _CRTIMP errno_t __cdecl _localtime64_s(
struct tm* tm,
const __time64_t *
time);
6649 # define gmtime_s _gmtime64_s
6650 # define localtime_s _localtime64_s
6663 #if RUBY_MSVCRT_VERSION >= 80 || defined(__MINGW64__)
6664 e = gmtime_s(rp, tp);
6665 if (e != 0)
goto error;
6687 #if RUBY_MSVCRT_VERSION >= 80 || defined(__MINGW64__)
6688 e = localtime_s(rp, tp);
6692 SYSTEMTIME gst, lst;
6707 int r = getsockopt((SOCKET)h, SOL_SOCKET, SO_DEBUG, (
char *)&tmp, &len);
6708 if (r != SOCKET_ERROR || WSAGetLastError() != WSAENOTSOCK) {
6711 flags &= ~O_NONBLOCK;
static const char * NTLoginName
void setnetent(int stayopen)
RUBY_EXTERN int flock(int, int)
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)
static time_t filetime_to_unixtime(const FILETIME *ft)
static WCHAR * mbstr_to_wstr(UINT, const char *, int, long *)
static char * skipspace(char *ptr)
char * rb_w32_ugetenv(const char *)
int gettimeofday(struct timeval *, struct timezone *)
int rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout)
struct constat::@157 vt100
static void init_stdhandle(void)
size_t strlen(const char *)
int rb_w32_wait_events(HANDLE *events, int num, DWORD timeout)
#define CSIDL_LOCAL_APPDATA
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)
rb_pid_t rb_w32_getppid(void)
static int max(int a, int b)
int st_lookup(st_table *, st_data_t, st_data_t *)
static void StartSockets(void)
ssize_t rb_w32_write(int, const void *, size_t)
static FARPROC get_wsa_extension_function(SOCKET s, GUID *guid)
int rb_w32_fstat(int, struct stat *)
#define access(path, mode)
static void init_func(void)
int sendmsg(int, const struct msghdr *, int)
int WSAAPI rb_w32_connect(int, const struct sockaddr *, int)
static ioinfo * _pioinfo(int)
static void catch_interrupt(void)
int WSAAPI rb_w32_bind(int, const struct sockaddr *, int)
static void get_version(void)
int WSAAPI rb_w32_sendto(int, const char *, int, int, const struct sockaddr *, int)
st_table * st_init_numtable(void)
static struct direct * readdir_internal(DIR *dirp, BOOL(*conv)(const WCHAR *, struct direct *, rb_encoding *), rb_encoding *enc)
static int Tcl_Interp * interp
static int compare(const struct timeval *t1, const struct timeval *t2)
SSL_METHOD *(* func)(void)
static rb_pid_t poll_child_status(struct ChildRecord *child, int *stat_loc)
static int NtSocketsInitialized
RUBY_EXTERN int signbit(double x)
RUBY_EXTERN void * memmove(void *, const void *, size_t)
int rb_w32_ustati64(const char *, struct stati64 *)
int rb_w32_wrap_io_handle(HANDLE, int)
VALUE rb_enc_from_encoding(rb_encoding *encoding)
static unsigned fileattr_to_unixmode(DWORD attr, const WCHAR *path)
static void constat_apply(HANDLE handle, struct constat *s, WCHAR w)
SOCKET rb_w32_get_osfhandle(int)
static st_table * socklist
int rb_w32_umkdir(const char *, int)
static int is_batch(const char *cmd)
#define INVALID_SET_FILE_POINTER
ssize_t rb_w32_read(int, void *, size_t)
rb_pid_t rb_w32_aspawn_flags(int, const char *, char *const *, DWORD)
DIR * rb_w32_uopendir(const char *)
static struct tm * localtime_r(const time_t *t, struct tm *tm)
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
int WSAAPI rb_w32_getsockopt(int, int, int, char *, int *)
static int extract_fd(rb_fdset_t *dst, fd_set *src, int(*func)(SOCKET))
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)
int rb_w32_urename(const char *, const char *)
static int check_if_dir(const char *file)
static int is_invalid_handle(SOCKET sock)
static WCHAR * translate_wchar(WCHAR *p, int from, int to)
#define STRNDUPV(ptr, v, src, len)
DIR * rb_w32_opendir(const char *)
int rb_w32_fdisset(int, fd_set *)
static void exit_handler(void)
struct servent *WSAAPI rb_w32_getservbyname(const char *, const char *)
struct _NtCmdLineElement * next
int rb_w32_open(const char *, int,...)
int WSAAPI rb_w32_select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
void rb_w32_free_environ(char **)
int WSAAPI rb_w32_accept(int, struct sockaddr *, int *)
long rb_w32_telldir(DIR *)
struct protoent *WSAAPI rb_w32_getprotobynumber(int)
rb_pid_t rb_w32_getpid(void)
#define msghdr_to_wsamsg(msg, wsamsg)
int rb_w32_uaccess(const char *, int)
int rb_w32_map_errno(DWORD)
struct protoent * getprotoent(void)
static FARPROC get_proc_address(const char *module, const char *func, HANDLE *mh)
int recvmsg(int, struct msghdr *, int)
int rb_econv_has_convpath_p(const char *from_encoding, const char *to_encoding)
static int socklist_insert(SOCKET sock, int flag)
char * rb_w32_conv_from_wstr(const WCHAR *wstr, long *lenp, rb_encoding *enc)
static struct tm * gmtime_r(const time_t *t, struct tm *tm)
#define filecp_to_wstr(str, plen)
void rb_w32_fdclr(int, fd_set *)
static SOCKET open_ifs_socket(int af, int type, int protocol)
int rb_w32_times(struct tms *)
static struct @155 errmap[]
int WSAAPI rb_w32_socket(int, int, int)
int rb_w32_is_socket(int)
RUBY_EXTERN size_t strlcpy(char *, const char *, size_t)
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_cmdvector(const char *, char ***)
int WSAAPI rb_w32_getsockname(int, struct sockaddr *, int *)
#define RUBY_CRITICAL(expr)
static uintptr_t flock_winnt(uintptr_t self, int argc, uintptr_t *argv)
#define MEMZERO(p, type, n)
const char *WSAAPI rb_w32_inet_ntop(int, const void *, char *, size_t)
static BOOL win32_direct_conv(const WCHAR *file, struct direct *entry, rb_encoding *dummy)
int st_delete(st_table *, st_data_t *, st_data_t *)
struct hostent *WSAAPI rb_w32_gethostbyaddr(const char *, int, int)
RUBY_EXTERN size_t strlcat(char *, const char *, size_t)
static int internal_cmd_match(const char *cmdname, int nt)
#define wstr_to_utf8(str, plen)
struct hostent *WSAAPI rb_w32_gethostbyname(const char *)
memset(y->frac+ix+1, 0,(y->Prec-(ix+1))*sizeof(BDIGIT))
VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc)
int rb_w32_wopen(const WCHAR *, int,...)
BOOL(WINAPI * cancel_io_t)(HANDLE)
static int is_pipe(SOCKET sock)
uintptr_t(* asynchronous_func_t)(uintptr_t self, int argc, uintptr_t *argv)
#define END_FOREACH_CHILD
int WSAAPI rb_w32_send(int, const char *, int, int)
#define wstr_to_filecp(str, plen)
rb_pid_t rb_w32_spawn(int, const char *, const char *)
static void Tcl_Interp * ip
off_t rb_w32_ftello(FILE *stream)
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 WSAAPI rb_w32_recvfrom(int, char *, int, int, struct sockaddr *, int *)
#define IOINFO_ARRAY_ELTS
void rb_w32_fd_copy(rb_fdset_t *dst, const fd_set *src, int max)
int chown(const char *, int, int)
struct netent * getnetbyname(const char *name)
int WSAAPI rb_w32_listen(int, int)
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_sleep(unsigned long msec)
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_mkdir(const char *, int)
unsigned char buf[MIME_BUF_SIZE]
struct direct * rb_w32_readdir(DIR *, rb_encoding *)
static int setup_overlapped(OVERLAPPED *ol, int fd)
int rb_w32_uutime(const char *, const struct utimbuf *)
static int socklist_lookup(SOCKET sock, int *flagp)
int rb_w32_rmdir(const char *)
uintptr_t(* func)(uintptr_t self, int argc, uintptr_t *argv)
int link(const char *, const char *)
void sethostent(int stayopen)
struct servent * getservent(void)
static int check_spawn_mode(int mode)
static cancel_io_t cancel_io
int rb_w32_unwrap_io_handle(int)
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)
int st_foreach(st_table *, int(*)(ANYARGS), st_data_t)
static int is_not_socket(SOCKET sock)
int rb_w32_putc(int, FILE *)
int rb_w32_fstati64(int, struct stati64 *)
int rb_w32_time_subtract(struct timeval *rest, const struct timeval *wait)
static DWORD constat_attr(int count, const int *seq, DWORD attr, DWORD default_attr)
int rb_w32_unlink(const char *)
static int do_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *timeout)
static const char *const szInternalCmds[]
VALUE rb_sprintf(const char *format,...)
int rb_w32_truncate(const char *path, off_t length)
void setservent(int stayopen)
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)
static int finish_overlapped_socket(BOOL input, SOCKET s, WSAOVERLAPPED *wol, int result, DWORD *len, DWORD size)
static CRITICAL_SECTION select_mutex
int rb_w32_urmdir(const char *)
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)
char ** rb_w32_get_environ(void)
static int rb_chsize(HANDLE h, off_t size)
static int min(int a, int b)
int rb_w32_uopen(const char *, int,...)
int rb_w32_stati64(const char *, struct stati64 *)
static int unixtime_to_filetime(time_t time, FILETIME *ft)
int rb_w32_uchmod(const char *, int)
char * rb_w32_getenv(const char *)
void rb_w32_closedir(DIR *)
char * strchr(char *, char)
struct protoent *WSAAPI rb_w32_getprotobyname(const char *)
#define utf8_to_wstr(str, plen)
static int insert(const char *path, VALUE vinfo, void *enc)
static int isUNCRoot(const WCHAR *path)
static rb_pid_t child_result(struct ChildRecord *child, int mode)
int WSAAPI rb_w32_setsockopt(int, int, int, const char *, int)
static int internal_match(const void *key, const void *elem)
VALUE rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts)
static UINT get_system_directory(WCHAR *path, UINT len)
static int is_internal_cmd(const char *cmd, int nt)
int rb_w32_access(const char *, int)
RUBY_EXTERN char * strerror(int)
rb_pid_t rb_w32_aspawn(int, const char *, char *const *)
void rb_write_error2(const char *, long)
static void constat_delete(HANDLE h)
VALUE rb_str_cat(VALUE, const char *, long)
#define ECONV_INVALID_REPLACE
rb_encoding * rb_enc_get(VALUE obj)
int rb_w32_uchdir(const char *)
int rb_w32_ulink(const char *, const char *)
static int wstati64(const WCHAR *path, struct stati64 *st)
static struct ChildRecord * FindChildSlotByHandle(HANDLE h)
static NtCmdLineElement ** cmdglob(NtCmdLineElement *patt, NtCmdLineElement **tail)
static DIR * opendir_internal(WCHAR *wpath, const char *filename)
if(RB_TYPE_P(r, T_FLOAT))
static int wlink(const WCHAR *from, const WCHAR *to)
VALUE rb_w32_special_folder(int type)
static int socklist_delete(SOCKET *sockp, int *flagp)
static DWORD WINAPI call_asynchronous(PVOID argp)
static int wrmdir(const WCHAR *wpath)
void rb_w32_rewinddir(DIR *)
static struct constat * constat_handle(HANDLE h)
long rb_w32_write_console(uintptr_t, int)
#define _set_osfhnd(fh, osfh)
#define acp_to_wstr(str, plen)
static int systemtime_to_localtime(TIME_ZONE_INFORMATION *tz, SYSTEMTIME *gst, SYSTEMTIME *lst)
char * rb_w32_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_ioctlsocket(int, long, u_long *)
VALUE rb_str_vcatf(VALUE, const char *, va_list)
rb_encoding * rb_filesystem_encoding(void)
struct _NtCmdLineElement NtCmdLineElement
struct servent *WSAAPI rb_w32_getservbyport(int, const char *)
int WSAAPI rb_w32_gethostname(char *, int)
int ruby_brace_glob(const char *str, int flags, ruby_glob_func *func, VALUE arg)
int st_insert(st_table *, st_data_t, st_data_t)
#define set_env_val(vname)
static int check_if_wdir(const WCHAR *wfile)
int rb_w32_ftruncate(int fd, off_t length)
void rb_w32_fdset(int, fd_set *)
static int setfl(SOCKET sock, int arg)
int WSAAPI rb_w32_shutdown(int, int)
static int wrename(const WCHAR *oldpath, const WCHAR *newpath)
static int dupfd(HANDLE hDup, char flags, int minfd)
#define COMMON_LVB_UNDERSCORE
int WSAAPI rb_w32_getpeername(int, struct sockaddr *, int *)
char * rb_w32_getcwd(char *, int)
static char fbuf[MAXPATHLEN]
static void move_to_next_entry(DIR *dirp)
static void systemtime_to_tm(const SYSTEMTIME *st, struct tm *t)
rb_encoding * rb_ascii8bit_encoding(void)
#define yield_until(condition)
int rb_w32_fclose(FILE *)
static int overlapped_socket_io(BOOL input, int fd, char *buf, int len, int flags, struct sockaddr *addr, int *addrlen)
static void version(void)
void rb_w32_seekdir(DIR *, long)
struct netent * getnetbyaddr(long net, int type)
static struct ChildRecord * CreateChild(const WCHAR *, const WCHAR *, SECURITY_ATTRIBUTES *, HANDLE, HANDLE, HANDLE, DWORD)
expr expr keyword_or expr
char rb_w32_fd_is_text(int)
static int socketpair_internal(int af, int type, int protocol, SOCKET *sv)
static void finish_overlapped(OVERLAPPED *ol, int fd, DWORD size)
static OSVERSIONINFO osver
#define ECONV_UNDEF_REPLACE
int rb_w32_socketpair(int, int, int, int *)
static int rb_w32_open_osfhandle(intptr_t osfhandle, int flags)
static int is_readable_console(SOCKET sock)
int WSAAPI rb_w32_recv(int, char *, int, int)
static BOOL get_special_folder(int n, WCHAR *env)
int rb_w32_io_cancelable_p(int)
static int eq(VALUE x, VALUE y)
static ULONG(STDMETHODCALLTYPE AddRef)(IDispatch __RPC_FAR *This)
uintptr_t rb_w32_asynchronize(asynchronous_func_t func, uintptr_t self, int argc, uintptr_t *argv, uintptr_t intrval)
int rb_w32_check_interrupt(void *)
#define ALLOCV_N(type, v, n)
int select(int num_fds, fd_set *in_fds, fd_set *out_fds, fd_set *ex_fds, struct timeval *timeout)
int rb_w32_uunlink(const char *)
rb_encoding * rb_enc_find(const char *name)
int rb_w32_stat(const char *, struct stat *)
void st_free_table(st_table *)
int rb_w32_utime(const char *, const struct utimbuf *)
rb_pid_t waitpid(rb_pid_t, int *, int)
static int check_valid_dir(const WCHAR *path)
int rb_w32_uchown(const char *, int, int)
static st_table * conlist
int rb_w32_rename(const char *, const char *)
STATIC void unsigned char * cp
#define _set_osflags(fh, flags)
static void constat_reset(HANDLE h)
static int wunlink(const WCHAR *path)