Skip to content

Commit e1091fd

Browse files
committed
std::libc: Simplify win32/win64 type definitions
1 parent 8d990c3 commit e1091fd

File tree

1 file changed

+30
-164
lines changed

1 file changed

+30
-164
lines changed

src/libstd/libc.rs

Lines changed: 30 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,6 @@ pub mod types {
663663
}
664664
}
665665

666-
#[cfg(target_arch = "x86")]
667666
pub mod arch {
668667
pub mod c95 {
669668
pub type c_char = i8;
@@ -677,27 +676,53 @@ pub mod types {
677676
pub type c_ulong = u32;
678677
pub type c_float = f32;
679678
pub type c_double = f64;
679+
680+
#[cfg(target_arch = "x86")]
680681
pub type size_t = u32;
682+
#[cfg(target_arch = "x86_64")]
683+
pub type size_t = u64;
684+
685+
#[cfg(target_arch = "x86")]
681686
pub type ptrdiff_t = i32;
687+
#[cfg(target_arch = "x86_64")]
688+
pub type ptrdiff_t = i64;
689+
682690
pub type clock_t = i32;
691+
692+
#[cfg(target_arch = "x86")]
683693
pub type time_t = i32;
694+
#[cfg(target_arch = "x86_64")]
695+
pub type time_t = i64;
696+
684697
pub type wchar_t = u16;
685698
}
699+
686700
pub mod c99 {
687701
pub type c_longlong = i64;
688702
pub type c_ulonglong = u64;
689703
pub type intptr_t = int;
690704
pub type uintptr_t = uint;
691705
}
706+
692707
pub mod posix88 {
693708
pub type off_t = i32;
694709
pub type dev_t = u32;
695710
pub type ino_t = i16;
711+
712+
#[cfg(target_arch = "x86")]
696713
pub type pid_t = i32;
714+
#[cfg(target_arch = "x86_64")]
715+
pub type pid_t = i64;
716+
697717
pub type useconds_t = u32;
698718
pub type mode_t = u16;
719+
720+
#[cfg(target_arch = "x86")]
699721
pub type ssize_t = i32;
722+
#[cfg(target_arch = "x86_64")]
723+
pub type ssize_t = i64;
700724
}
725+
701726
pub mod posix01 {
702727
}
703728
pub mod posix08 {
@@ -725,7 +750,11 @@ pub mod types {
725750

726751
pub type LONG = c_long;
727752
pub type PLONG = *mut c_long;
753+
754+
#[cfg(target_arch = "x86")]
728755
pub type LONG_PTR = c_long;
756+
#[cfg(target_arch = "x86_64")]
757+
pub type LONG_PTR = i64;
729758

730759
pub type LARGE_INTEGER = c_longlong;
731760
pub type PLARGE_INTEGER = *mut c_longlong;
@@ -843,169 +872,6 @@ pub mod types {
843872
pub type LPOVERLAPPED = *mut OVERLAPPED;
844873
}
845874
}
846-
847-
#[cfg(target_arch = "x86_64")]
848-
pub mod arch {
849-
pub mod c95 {
850-
pub type c_char = i8;
851-
pub type c_schar = i8;
852-
pub type c_uchar = u8;
853-
pub type c_short = i16;
854-
pub type c_ushort = u16;
855-
pub type c_int = i32;
856-
pub type c_uint = u32;
857-
pub type c_long = i32;
858-
pub type c_ulong = u32;
859-
pub type c_float = f32;
860-
pub type c_double = f64;
861-
pub type size_t = u64;
862-
pub type ptrdiff_t = i64;
863-
pub type clock_t = i32;
864-
pub type time_t = i64;
865-
pub type wchar_t = u16;
866-
}
867-
pub mod c99 {
868-
pub type c_longlong = i64;
869-
pub type c_ulonglong = u64;
870-
pub type intptr_t = int;
871-
pub type uintptr_t = uint;
872-
}
873-
pub mod posix88 {
874-
pub type off_t = i32; // XXX unless _FILE_OFFSET_BITS == 64
875-
pub type dev_t = u32;
876-
pub type ino_t = i16;
877-
pub type pid_t = i64;
878-
pub type useconds_t = u32;
879-
pub type mode_t = u16;
880-
pub type ssize_t = i64;
881-
}
882-
pub mod posix01 {
883-
}
884-
pub mod posix08 {
885-
}
886-
pub mod bsd44 {
887-
}
888-
pub mod extra {
889-
use ptr;
890-
use libc::types::common::c95::c_void;
891-
use libc::types::os::arch::c95::{c_char, c_int, c_uint, size_t};
892-
use libc::types::os::arch::c95::{c_ulong};
893-
use libc::types::os::arch::c95::{wchar_t};
894-
use libc::types::os::arch::c99::{c_ulonglong};
895-
896-
pub type BOOL = c_int;
897-
pub type BYTE = u8;
898-
pub type CCHAR = c_char;
899-
pub type CHAR = c_char;
900-
901-
pub type DWORD = c_ulong;
902-
pub type DWORDLONG = c_ulonglong;
903-
904-
pub type HANDLE = LPVOID;
905-
pub type HMODULE = c_uint;
906-
907-
pub type LONG_PTR = i64; // changed
908-
909-
pub type LPCWSTR = *WCHAR;
910-
pub type LPCSTR = *CHAR;
911-
912-
pub type LPWSTR = *mut WCHAR;
913-
pub type LPSTR = *mut CHAR;
914-
915-
// Not really, but opaque to us.
916-
pub type LPSECURITY_ATTRIBUTES = LPVOID;
917-
918-
pub type LPVOID = *mut c_void;
919-
pub type LPCVOID = *c_void;
920-
pub type LPBYTE = *mut BYTE;
921-
pub type LPWORD = *mut WORD;
922-
pub type LPDWORD = *mut DWORD;
923-
pub type LPHANDLE = *mut HANDLE;
924-
925-
pub type LRESULT = LONG_PTR;
926-
pub type PBOOL = *mut BOOL;
927-
pub type WCHAR = wchar_t;
928-
pub type WORD = u16;
929-
pub type SIZE_T = size_t;
930-
931-
pub type time64_t = i64;
932-
pub type int64 = i64;
933-
934-
pub struct STARTUPINFO {
935-
cb: DWORD,
936-
lpReserved: LPWSTR,
937-
lpDesktop: LPWSTR,
938-
lpTitle: LPWSTR,
939-
dwX: DWORD,
940-
dwY: DWORD,
941-
dwXSize: DWORD,
942-
dwYSize: DWORD,
943-
dwXCountChars: DWORD,
944-
dwYCountCharts: DWORD,
945-
dwFillAttribute: DWORD,
946-
dwFlags: DWORD,
947-
wShowWindow: WORD,
948-
cbReserved2: WORD,
949-
lpReserved2: LPBYTE,
950-
hStdInput: HANDLE,
951-
hStdOutput: HANDLE,
952-
hStdError: HANDLE
953-
}
954-
pub type LPSTARTUPINFO = *mut STARTUPINFO;
955-
956-
pub struct PROCESS_INFORMATION {
957-
hProcess: HANDLE,
958-
hThread: HANDLE,
959-
dwProcessId: DWORD,
960-
dwThreadId: DWORD
961-
}
962-
pub type LPPROCESS_INFORMATION = *mut PROCESS_INFORMATION;
963-
964-
pub struct SYSTEM_INFO {
965-
wProcessorArchitecture: WORD,
966-
wReserved: WORD,
967-
dwPageSize: DWORD,
968-
lpMinimumApplicationAddress: LPVOID,
969-
lpMaximumApplicationAddress: LPVOID,
970-
dwActiveProcessorMask: DWORD,
971-
dwNumberOfProcessors: DWORD,
972-
dwProcessorType: DWORD,
973-
dwAllocationGranularity: DWORD,
974-
wProcessorLevel: WORD,
975-
wProcessorRevision: WORD
976-
}
977-
pub type LPSYSTEM_INFO = *mut SYSTEM_INFO;
978-
979-
impl SYSTEM_INFO {
980-
pub fn new() -> SYSTEM_INFO {
981-
SYSTEM_INFO {
982-
wProcessorArchitecture: 0,
983-
wReserved: 0,
984-
dwPageSize: 0,
985-
lpMinimumApplicationAddress: ptr::mut_null(),
986-
lpMaximumApplicationAddress: ptr::mut_null(),
987-
dwActiveProcessorMask: 0,
988-
dwNumberOfProcessors: 0,
989-
dwProcessorType: 0,
990-
dwAllocationGranularity: 0,
991-
wProcessorLevel: 0,
992-
wProcessorRevision: 0
993-
}
994-
}
995-
}
996-
997-
pub struct MEMORY_BASIC_INFORMATION {
998-
BaseAddress: LPVOID,
999-
AllocationBase: LPVOID,
1000-
AllocationProtect: DWORD,
1001-
RegionSize: SIZE_T,
1002-
State: DWORD,
1003-
Protect: DWORD,
1004-
Type: DWORD
1005-
}
1006-
pub type LPMEMORY_BASIC_INFORMATION = *mut MEMORY_BASIC_INFORMATION;
1007-
}
1008-
}
1009875
}
1010876

1011877
#[cfg(target_os = "macos")]

0 commit comments

Comments
 (0)