Skip to content

Commit

Permalink
Move WinAPI functions from libc to std::sys::windows::c
Browse files Browse the repository at this point in the history
Also remove unused WinAPI functions

Signed-off-by: Peter Atashian <retep998@gmail.com>
  • Loading branch information
retep998 committed Jun 5, 2015
1 parent dd81d1e commit e0fe9a6
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 329 deletions.
224 changes: 1 addition & 223 deletions src/liblibc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ pub use funcs::bsd43::*;
#[cfg(unix)] pub use funcs::posix01::unistd::*;
#[cfg(unix)] pub use funcs::posix01::resource::*;


#[cfg(windows)] pub use funcs::extra::kernel32::*;
#[cfg(windows)] pub use funcs::extra::winsock::*;
#[cfg(windows)] pub use funcs::extra::msvcrt::*;

// On NaCl, these libraries are static. Thus it would be a Bad Idea to link them
// in when creating a test crate.
#[cfg(not(any(windows, target_env = "musl", all(target_os = "nacl", test))))]
Expand Down Expand Up @@ -6165,224 +6160,7 @@ pub mod funcs {


#[cfg(target_os = "windows")]
pub mod extra {

pub mod kernel32 {
use types::os::arch::c95::{c_uint};
use types::os::arch::extra::{BOOL, DWORD, SIZE_T, HMODULE,
LPCWSTR, LPWSTR,
LPWCH, LPDWORD, LPVOID,
LPCVOID, LPOVERLAPPED,
LPSECURITY_ATTRIBUTES,
LPSTARTUPINFO,
LPPROCESS_INFORMATION,
LPMEMORY_BASIC_INFORMATION,
LPSYSTEM_INFO, HANDLE, LPHANDLE,
LARGE_INTEGER, PLARGE_INTEGER,
LPFILETIME, LPWIN32_FIND_DATAW};

extern "system" {
pub fn GetEnvironmentVariableW(n: LPCWSTR,
v: LPWSTR,
nsize: DWORD)
-> DWORD;
pub fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR)
-> BOOL;
pub fn GetEnvironmentStringsW() -> LPWCH;
pub fn FreeEnvironmentStringsW(env_ptr: LPWCH) -> BOOL;
pub fn GetModuleFileNameW(hModule: HMODULE,
lpFilename: LPWSTR,
nSize: DWORD)
-> DWORD;
pub fn CreateDirectoryW(lpPathName: LPCWSTR,
lpSecurityAttributes:
LPSECURITY_ATTRIBUTES)
-> BOOL;
pub fn CopyFileW(lpExistingFileName: LPCWSTR,
lpNewFileName: LPCWSTR,
bFailIfExists: BOOL)
-> BOOL;
pub fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
pub fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
pub fn GetCurrentDirectoryW(nBufferLength: DWORD,
lpBuffer: LPWSTR)
-> DWORD;
pub fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
pub fn GetLastError() -> DWORD;
pub fn FindFirstFileW(fileName: LPCWSTR, findFileData: LPWIN32_FIND_DATAW)
-> HANDLE;
pub fn FindNextFileW(findFile: HANDLE, findFileData: LPWIN32_FIND_DATAW)
-> BOOL;
pub fn FindClose(findFile: HANDLE) -> BOOL;
pub fn DuplicateHandle(hSourceProcessHandle: HANDLE,
hSourceHandle: HANDLE,
hTargetProcessHandle: HANDLE,
lpTargetHandle: LPHANDLE,
dwDesiredAccess: DWORD,
bInheritHandle: BOOL,
dwOptions: DWORD)
-> BOOL;
pub fn CloseHandle(hObject: HANDLE) -> BOOL;
pub fn OpenProcess(dwDesiredAccess: DWORD,
bInheritHandle: BOOL,
dwProcessId: DWORD)
-> HANDLE;
pub fn GetCurrentProcess() -> HANDLE;
pub fn CreateProcessW(lpApplicationName: LPCWSTR,
lpCommandLine: LPWSTR,
lpProcessAttributes:
LPSECURITY_ATTRIBUTES,
lpThreadAttributes:
LPSECURITY_ATTRIBUTES,
bInheritHandles: BOOL,
dwCreationFlags: DWORD,
lpEnvironment: LPVOID,
lpCurrentDirectory: LPCWSTR,
lpStartupInfo: LPSTARTUPINFO,
lpProcessInformation:
LPPROCESS_INFORMATION)
-> BOOL;
pub fn WaitForSingleObject(hHandle: HANDLE,
dwMilliseconds: DWORD)
-> DWORD;
pub fn TerminateProcess(hProcess: HANDLE, uExitCode: c_uint)
-> BOOL;
pub fn GetExitCodeProcess(hProcess: HANDLE,
lpExitCode: LPDWORD)
-> BOOL;
pub fn GetSystemInfo(lpSystemInfo: LPSYSTEM_INFO);
pub fn VirtualAlloc(lpAddress: LPVOID,
dwSize: SIZE_T,
flAllocationType: DWORD,
flProtect: DWORD)
-> LPVOID;
pub fn VirtualFree(lpAddress: LPVOID,
dwSize: SIZE_T,
dwFreeType: DWORD)
-> BOOL;
pub fn VirtualLock(lpAddress: LPVOID, dwSize: SIZE_T) -> BOOL;
pub fn VirtualUnlock(lpAddress: LPVOID, dwSize: SIZE_T)
-> BOOL;
pub fn VirtualProtect(lpAddress: LPVOID,
dwSize: SIZE_T,
flNewProtect: DWORD,
lpflOldProtect: LPDWORD)
-> BOOL;
pub fn VirtualQuery(lpAddress: LPCVOID,
lpBuffer: LPMEMORY_BASIC_INFORMATION,
dwLength: SIZE_T)
-> SIZE_T;
pub fn CreateFileMappingW(hFile: HANDLE,
lpAttributes: LPSECURITY_ATTRIBUTES,
flProtect: DWORD,
dwMaximumSizeHigh: DWORD,
dwMaximumSizeLow: DWORD,
lpName: LPCWSTR)
-> HANDLE;
pub fn MapViewOfFile(hFileMappingObject: HANDLE,
dwDesiredAccess: DWORD,
dwFileOffsetHigh: DWORD,
dwFileOffsetLow: DWORD,
dwNumberOfBytesToMap: SIZE_T)
-> LPVOID;
pub fn UnmapViewOfFile(lpBaseAddress: LPCVOID) -> BOOL;
pub fn MoveFileExW(lpExistingFileName: LPCWSTR,
lpNewFileName: LPCWSTR,
dwFlags: DWORD) -> BOOL;
pub fn CreateHardLinkW(lpSymlinkFileName: LPCWSTR,
lpTargetFileName: LPCWSTR,
lpSecurityAttributes: LPSECURITY_ATTRIBUTES)
-> BOOL;
pub fn FlushFileBuffers(hFile: HANDLE) -> BOOL;
pub fn CreateFileW(lpFileName: LPCWSTR,
dwDesiredAccess: DWORD,
dwShareMode: DWORD,
lpSecurityAttributes: LPSECURITY_ATTRIBUTES,
dwCreationDisposition: DWORD,
dwFlagsAndAttributes: DWORD,
hTemplateFile: HANDLE) -> HANDLE;
pub fn ReadFile(hFile: HANDLE,
lpBuffer: LPVOID,
nNumberOfBytesToRead: DWORD,
lpNumberOfBytesRead: LPDWORD,
lpOverlapped: LPOVERLAPPED) -> BOOL;
pub fn WriteFile(hFile: HANDLE,
lpBuffer: LPVOID,
nNumberOfBytesToRead: DWORD,
lpNumberOfBytesRead: LPDWORD,
lpOverlapped: LPOVERLAPPED) -> BOOL;
pub fn SetFilePointerEx(hFile: HANDLE,
liDistanceToMove: LARGE_INTEGER,
lpNewFilePointer: PLARGE_INTEGER,
dwMoveMethod: DWORD) -> BOOL;
pub fn SetEndOfFile(hFile: HANDLE) -> BOOL;

pub fn GetSystemTimeAsFileTime(
lpSystemTimeAsFileTime: LPFILETIME);

pub fn QueryPerformanceFrequency(
lpFrequency: *mut LARGE_INTEGER) -> BOOL;
pub fn QueryPerformanceCounter(
lpPerformanceCount: *mut LARGE_INTEGER) -> BOOL;

pub fn GetCurrentProcessId() -> DWORD;
pub fn CreateNamedPipeW(
lpName: LPCWSTR,
dwOpenMode: DWORD,
dwPipeMode: DWORD,
nMaxInstances: DWORD,
nOutBufferSize: DWORD,
nInBufferSize: DWORD,
nDefaultTimeOut: DWORD,
lpSecurityAttributes: LPSECURITY_ATTRIBUTES
) -> HANDLE;
pub fn ConnectNamedPipe(hNamedPipe: HANDLE,
lpOverlapped: LPOVERLAPPED) -> BOOL;
pub fn WaitNamedPipeW(lpNamedPipeName: LPCWSTR,
nTimeOut: DWORD) -> BOOL;
pub fn SetNamedPipeHandleState(hNamedPipe: HANDLE,
lpMode: LPDWORD,
lpMaxCollectionCount: LPDWORD,
lpCollectDataTimeout: LPDWORD)
-> BOOL;
pub fn CreateEventW(lpEventAttributes: LPSECURITY_ATTRIBUTES,
bManualReset: BOOL,
bInitialState: BOOL,
lpName: LPCWSTR) -> HANDLE;
pub fn GetOverlappedResult(hFile: HANDLE,
lpOverlapped: LPOVERLAPPED,
lpNumberOfBytesTransferred: LPDWORD,
bWait: BOOL) -> BOOL;
pub fn DisconnectNamedPipe(hNamedPipe: HANDLE) -> BOOL;
}
}

pub mod msvcrt {
use types::os::arch::c95::{c_int, c_long};
use types::os::arch::c99::intptr_t;

extern {
#[link_name = "_commit"]
pub fn commit(fd: c_int) -> c_int;

#[link_name = "_get_osfhandle"]
pub fn get_osfhandle(fd: c_int) -> c_long;

#[link_name = "_open_osfhandle"]
pub fn open_osfhandle(osfhandle: intptr_t,
flags: c_int) -> c_int;
}
}

pub mod winsock {
use types::os::arch::c95::{c_int, c_long, c_ulong};
use types::os::common::bsd44::SOCKET;

extern "system" {
pub fn ioctlsocket(s: SOCKET, cmd: c_long, argp: *mut c_ulong) -> c_int;
}
}
}
pub mod extra {}
}

#[doc(hidden)]
Expand Down
Loading

0 comments on commit e0fe9a6

Please sign in to comment.