* win32/win32.c (get_proc_address): refactoring.
* win32/win32.c (get_wsa_exetinsion_function): refactoring. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29714 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7b5e9245ac
commit
877e90f17a
@ -1,3 +1,9 @@
|
||||
Mon Nov 8 11:02:21 2010 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||
|
||||
* win32/win32.c (get_proc_address): refactoring.
|
||||
|
||||
* win32/win32.c (get_wsa_exetinsion_function): refactoring.
|
||||
|
||||
Mon Nov 8 09:45:35 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* enc/trans/gbk-tbl.rb: Add euro sign. [ruby-core:33094]
|
||||
|
@ -450,18 +450,37 @@ regulate_path(WCHAR *path)
|
||||
}
|
||||
}
|
||||
|
||||
static FARPROC
|
||||
get_proc_address(const char *module, const char *func, HANDLE *mh)
|
||||
{
|
||||
HANDLE h;
|
||||
FARPROC ptr;
|
||||
|
||||
if (mh)
|
||||
h = LoadLibrary(module);
|
||||
else
|
||||
h = GetModuleHandle(module);
|
||||
if (!h)
|
||||
return NULL;
|
||||
|
||||
ptr = GetProcAddress(h, func);
|
||||
if (mh) {
|
||||
if (ptr)
|
||||
*mh = h;
|
||||
else
|
||||
FreeLibrary(h);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static UINT
|
||||
get_system_directory(WCHAR *path, UINT len)
|
||||
{
|
||||
HANDLE hKernel = GetModuleHandle("kernel32.dll");
|
||||
|
||||
if (hKernel) {
|
||||
typedef UINT WINAPI wgetdir_func(WCHAR*, UINT);
|
||||
FARPROC ptr = GetProcAddress(hKernel, "GetSystemWindowsDirectoryW");
|
||||
if (ptr) {
|
||||
return (*(wgetdir_func *)ptr)(path, len);
|
||||
}
|
||||
}
|
||||
typedef UINT WINAPI wgetdir_func(WCHAR*, UINT);
|
||||
FARPROC ptr =
|
||||
get_proc_address("kernel32", "GetSystemWindowsDirectoryW", NULL);
|
||||
if (ptr)
|
||||
return (*(wgetdir_func *)ptr)(path, len);
|
||||
return GetWindowsDirectoryW(path, len);
|
||||
}
|
||||
|
||||
@ -569,8 +588,7 @@ static void
|
||||
init_func(void)
|
||||
{
|
||||
if (!cancel_io)
|
||||
cancel_io = (cancel_io_t)GetProcAddress(GetModuleHandle("kernel32"),
|
||||
"CancelIo");
|
||||
cancel_io = (cancel_io_t)get_proc_address("kernel32", "CancelIo", NULL);
|
||||
}
|
||||
|
||||
static void init_stdhandle(void);
|
||||
@ -2663,6 +2681,19 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
|
||||
return r;
|
||||
}
|
||||
|
||||
static FARPROC
|
||||
get_wsa_exetinsion_function(SOCKET s, GUID *guid)
|
||||
{
|
||||
DWORD dmy;
|
||||
FARPROC ptr = NULL;
|
||||
|
||||
WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, guid, sizeof(*guid),
|
||||
&ptr, sizeof(ptr), &dmy, NULL, NULL);
|
||||
if (!ptr)
|
||||
errno = ENOSYS;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#undef accept
|
||||
|
||||
int WSAAPI
|
||||
@ -3002,13 +3033,9 @@ recvmsg(int fd, struct msghdr *msg, int flags)
|
||||
|
||||
if (!pWSARecvMsg) {
|
||||
static GUID guid = WSAID_WSARECVMSG;
|
||||
DWORD dmy;
|
||||
WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &guid, sizeof(guid),
|
||||
&pWSARecvMsg, sizeof(pWSARecvMsg), &dmy, NULL, NULL);
|
||||
if (!pWSARecvMsg) {
|
||||
errno = ENOSYS;
|
||||
pWSARecvMsg = (WSARecvMsg_t)get_wsa_exetinsion_function(s, &guid);
|
||||
if (!pWSARecvMsg)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
msghdr_to_wsamsg(msg, &wsamsg);
|
||||
@ -3095,13 +3122,9 @@ sendmsg(int fd, const struct msghdr *msg, int flags)
|
||||
|
||||
if (!pWSASendMsg) {
|
||||
static GUID guid = WSAID_WSASENDMSG;
|
||||
DWORD dmy;
|
||||
WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &guid, sizeof(guid),
|
||||
&pWSASendMsg, sizeof(pWSASendMsg), &dmy, NULL, NULL);
|
||||
if (!pWSASendMsg) {
|
||||
errno = ENOSYS;
|
||||
pWSASendMsg = (WSASendMsg_t)get_wsa_exetinsion_function(s, &guid);
|
||||
if (!pWSASendMsg)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
msghdr_to_wsamsg(msg, &wsamsg);
|
||||
@ -3847,16 +3870,9 @@ wlink(const WCHAR *from, const WCHAR *to)
|
||||
if (!pCreateHardLinkW && !myerrno) {
|
||||
HANDLE hKernel;
|
||||
|
||||
hKernel = GetModuleHandle("kernel32.dll");
|
||||
if (hKernel) {
|
||||
pCreateHardLinkW = (BOOL (WINAPI *)(LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES))GetProcAddress(hKernel, "CreateHardLinkW");
|
||||
if (!pCreateHardLinkW) {
|
||||
myerrno = ENOSYS;
|
||||
}
|
||||
}
|
||||
else {
|
||||
myerrno = map_errno(GetLastError());
|
||||
}
|
||||
pCreateHardLinkW = (BOOL (WINAPI *)(LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES))get_proc_address("kernel32", "CreateHardLinkW", NULL);
|
||||
if (!pCreateHardLinkW)
|
||||
myerrno = ENOSYS;
|
||||
}
|
||||
if (!pCreateHardLinkW) {
|
||||
errno = myerrno;
|
||||
@ -4701,12 +4717,8 @@ rb_w32_getppid(void)
|
||||
rb_pid_t ppid = 0;
|
||||
|
||||
if (!IsWin95() && rb_w32_osver() >= 5) {
|
||||
if (!pNtQueryInformationProcess) {
|
||||
HANDLE hNtDll = GetModuleHandle("ntdll.dll");
|
||||
if (hNtDll) {
|
||||
pNtQueryInformationProcess = (long (WINAPI *)(HANDLE, int, void *, ULONG, ULONG *))GetProcAddress(hNtDll, "NtQueryInformationProcess");
|
||||
}
|
||||
}
|
||||
if (!pNtQueryInformationProcess)
|
||||
pNtQueryInformationProcess = (long (WINAPI *)(HANDLE, int, void *, ULONG, ULONG *))get_proc_address("ntdll.dll", "NtQueryInformationProcess", NULL);
|
||||
if (pNtQueryInformationProcess) {
|
||||
struct {
|
||||
long ExitStatus;
|
||||
|
Loading…
x
Reference in New Issue
Block a user