glib_win32/auto/functions.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{OSType, ffi};
6use glib::translate::*;
7
8/// Returns whether the version of the Windows operating system the
9/// code is running on is at least the specified major, minor and
10/// service pack versions. See MSDN documentation for the Operating
11/// System Version. Software that needs even more detailed version and
12/// feature information should use the Win32 API VerifyVersionInfo()
13/// directly.
14///
15/// Successive calls of this function can be used for enabling or
16/// disabling features at run-time for a range of Windows versions,
17/// as per the VerifyVersionInfo() API documentation.
18/// ## `major`
19/// major version of Windows
20/// ## `minor`
21/// minor version of Windows
22/// ## `spver`
23/// Windows Service Pack Level, 0 if none
24/// ## `os_type`
25/// Type of Windows OS
26///
27/// # Returns
28///
29/// [`true`] if the Windows Version is the same or greater than
30/// the specified major, minor and service pack versions, and
31/// whether the running Windows is a workstation or server edition
32/// of Windows, if specifically specified.
33#[doc(alias = "g_win32_check_windows_version")]
34pub fn check_windows_version(major: i32, minor: i32, spver: i32, os_type: OSType) -> bool {
35 unsafe {
36 from_glib(ffi::g_win32_check_windows_version(
37 major,
38 minor,
39 spver,
40 os_type.into_glib(),
41 ))
42 }
43}
44
45/// Translate a Win32 error code into a human readable message.
46///
47/// The error code could be as returned by
48/// [`GetLastError()`](https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror)
49/// or [`WSAGetLastError()`](https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-wsagetlasterror).
50///
51/// The message is either language neutral, or in the thread’s language, or the
52/// user’s language, the system’s language, or US English (see documentation for
53/// [`FormatMessage()`](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-formatmessagew)).
54/// The returned string is in UTF-8.
55///
56/// If a human readable message cannot be found for the given @error, an empty
57/// string is returned.
58/// ## `error`
59/// Win32 error code
60///
61/// # Returns
62///
63/// newly-allocated error message
64#[doc(alias = "g_win32_error_message")]
65pub fn error_message(error: i32) -> glib::GString {
66 unsafe { from_glib_full(ffi::g_win32_error_message(error)) }
67}
68
69#[doc(alias = "g_win32_ftruncate")]
70pub fn ftruncate(f: i32, size: u32) -> i32 {
71 unsafe { ffi::g_win32_ftruncate(f, size) }
72}
73
74/// Gets the command line arguments, on Windows, in the GLib filename
75/// encoding (ie: UTF-8).
76///
77/// Normally, on Windows, the command line arguments are passed to main()
78/// in the system codepage encoding. This prevents passing filenames as
79/// arguments if the filenames contain characters that fall outside of
80/// this codepage. If such filenames are passed, then substitutions
81/// will occur (such as replacing some characters with '?').
82///
83/// GLib's policy of using UTF-8 as a filename encoding on Windows was
84/// designed to localise the pain of dealing with filenames outside of
85/// the system codepage to one area: dealing with commandline arguments
86/// in main().
87///
88/// As such, most GLib programs should ignore the value of argv passed to
89/// their main() function and call g_win32_get_command_line() instead.
90/// This will get the "full Unicode" commandline arguments using
91/// GetCommandLineW() and convert it to the GLib filename encoding (which
92/// is UTF-8 on Windows).
93///
94/// The strings returned by this function are suitable for use with
95/// functions such as g_open() and g_file_new_for_commandline_arg() but
96/// are not suitable for use with g_option_context_parse(), which assumes
97/// that its input will be in the system codepage. The return value is
98/// suitable for use with g_option_context_parse_strv(), however, which
99/// is a better match anyway because it won't leak memory.
100///
101/// Unlike argv, the returned value is a normal strv and can (and should)
102/// be freed with g_strfreev() when no longer needed.
103///
104/// # Returns
105///
106/// the commandline arguments in the GLib
107/// filename encoding (ie: UTF-8)
108#[doc(alias = "g_win32_get_command_line")]
109#[doc(alias = "get_command_line")]
110pub fn command_line() -> Vec<glib::GString> {
111 unsafe { FromGlibPtrContainer::from_glib_full(ffi::g_win32_get_command_line()) }
112}
113
114/// The setlocale() function in the Microsoft C library uses locale
115/// names of the form "English_United States.1252" etc. We want the
116/// UNIXish standard form "en_US", "zh_TW" etc. This function gets the
117/// current thread locale from Windows - without any encoding info -
118/// and returns it as a string of the above form for use in forming
119/// file names etc. The returned string should be deallocated with
120/// g_free().
121///
122/// # Returns
123///
124/// newly-allocated locale name.
125#[doc(alias = "g_win32_getlocale")]
126pub fn getlocale() -> glib::GString {
127 unsafe { from_glib_full(ffi::g_win32_getlocale()) }
128}
129
130/// Converts a filename from UTF-8 to the system codepage.
131///
132/// On NT-based Windows, on NTFS file systems, file names are in
133/// Unicode. It is quite possible that Unicode file names contain
134/// characters not representable in the system codepage. (For instance,
135/// Greek or Cyrillic characters on Western European or US Windows
136/// installations, or various less common CJK characters on CJK Windows
137/// installations.)
138///
139/// In such a case, and if the filename refers to an existing file, and
140/// the file system stores alternate short (8.3) names for directory
141/// entries, the short form of the filename is returned. Note that the
142/// "short" name might in fact be longer than the Unicode name if the
143/// Unicode name has very short pathname components containing
144/// non-ASCII characters. If no system codepage name for the file is
145/// possible, [`None`] is returned.
146///
147/// The return value is dynamically allocated and should be freed with
148/// g_free() when no longer needed.
149/// ## `utf8filename`
150/// a UTF-8 encoded filename.
151///
152/// # Returns
153///
154/// The converted filename, or [`None`] on conversion
155/// failure and lack of short names.
156#[doc(alias = "g_win32_locale_filename_from_utf8")]
157pub fn locale_filename_from_utf8(utf8filename: &str) -> glib::GString {
158 unsafe {
159 from_glib_full(ffi::g_win32_locale_filename_from_utf8(
160 utf8filename.to_glib_none().0,
161 ))
162 }
163}