Skip to content

Commit da8af6a

Browse files
authored
Merge pull request #1372 from sdroege/win32-apis
glib: Re-add and rename manual Win32 API additions
2 parents 7ba5563 + aaf3424 commit da8af6a

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

glib/src/win32.rs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@ use std::path::PathBuf;
44

55
use crate::{translate::*, GString, StrV};
66

7-
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
8-
pub enum OSType {
7+
#[doc(alias = "GWin32OSType")]
8+
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
9+
#[non_exhaustive]
10+
pub enum Win32OSType {
911
#[doc(alias = "G_WIN32_OS_ANY")]
1012
Any,
1113
#[doc(alias = "G_WIN32_OS_WORKSTATION")]
1214
Workstation,
1315
#[doc(alias = "G_WIN32_OS_SERVER")]
1416
Server,
17+
#[doc(hidden)]
18+
__Unknown(i32),
1519
}
1620

1721
#[doc(hidden)]
18-
impl IntoGlib for OSType {
22+
impl IntoGlib for Win32OSType {
1923
type GlibType = ffi::GWin32OSType;
2024

2125
#[inline]
@@ -24,12 +28,31 @@ impl IntoGlib for OSType {
2428
Self::Any => ffi::G_WIN32_OS_ANY,
2529
Self::Workstation => ffi::G_WIN32_OS_WORKSTATION,
2630
Self::Server => ffi::G_WIN32_OS_SERVER,
31+
Self::__Unknown(value) => value,
32+
}
33+
}
34+
}
35+
36+
#[doc(hidden)]
37+
impl FromGlib<ffi::GWin32OSType> for Win32OSType {
38+
#[inline]
39+
unsafe fn from_glib(value: ffi::GWin32OSType) -> Self {
40+
match value {
41+
ffi::G_WIN32_OS_ANY => Self::Any,
42+
ffi::G_WIN32_OS_WORKSTATION => Self::Workstation,
43+
ffi::G_WIN32_OS_SERVER => Self::Server,
44+
value => Self::__Unknown(value),
2745
}
2846
}
2947
}
3048

3149
#[doc(alias = "g_win32_check_windows_version")]
32-
pub fn check_windows_version(major: i32, minor: i32, spver: i32, os_type: OSType) -> bool {
50+
pub fn win32_check_windows_version(
51+
major: i32,
52+
minor: i32,
53+
spver: i32,
54+
os_type: Win32OSType,
55+
) -> bool {
3356
unsafe {
3457
from_glib(ffi::g_win32_check_windows_version(
3558
major,
@@ -42,23 +65,23 @@ pub fn check_windows_version(major: i32, minor: i32, spver: i32, os_type: OSType
4265

4366
#[doc(alias = "g_win32_get_command_line")]
4467
#[doc(alias = "get_command_line")]
45-
pub fn command_line() -> StrV {
68+
pub fn win32_command_line() -> StrV {
4669
unsafe { FromGlibPtrContainer::from_glib_full(ffi::g_win32_get_command_line()) }
4770
}
4871

4972
#[doc(alias = "g_win32_error_message")]
50-
pub fn error_message(error: i32) -> GString {
73+
pub fn win32_error_message(error: i32) -> GString {
5174
unsafe { from_glib_full(ffi::g_win32_error_message(error)) }
5275
}
5376

5477
#[doc(alias = "g_win32_getlocale")]
55-
pub fn getlocale() -> GString {
78+
pub fn win32_getlocale() -> GString {
5679
unsafe { from_glib_full(ffi::g_win32_getlocale()) }
5780
}
5881

5982
#[doc(alias = "g_win32_get_package_installation_directory_of_module")]
6083
#[doc(alias = "get_package_installation_directory_of_module")]
61-
pub fn package_installation_directory_of_module(
84+
pub fn win32_package_installation_directory_of_module(
6285
hmodule: std::os::windows::raw::HANDLE,
6386
) -> Result<PathBuf, std::io::Error> {
6487
// # Safety

glib/sys/src/manual.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub use self::win32::*;
7777

7878
#[cfg(target_family = "windows")]
7979
mod win32 {
80-
use libc::{c_char, c_int};
80+
use libc::{c_char, c_int, c_uint};
8181

8282
pub type GWin32OSType = c_int;
8383
pub const G_WIN32_OS_ANY: GWin32OSType = 0;
@@ -104,5 +104,17 @@ mod win32 {
104104
) -> *mut c_char;
105105

106106
pub fn g_win32_locale_filename_from_utf8(utf8filename: *const c_char) -> *mut c_char;
107+
108+
pub fn g_win32_ftruncate(f: c_int, size: c_uint) -> c_int;
109+
pub fn g_win32_get_package_installation_directory(
110+
package: *const c_char,
111+
dll_name: *const c_char,
112+
) -> *mut c_char;
113+
pub fn g_win32_get_package_installation_subdirectory(
114+
package: *const c_char,
115+
dll_name: *const c_char,
116+
subdir: *const c_char,
117+
) -> *mut c_char;
118+
pub fn g_win32_get_windows_version() -> c_uint;
107119
}
108120
}

0 commit comments

Comments
 (0)