Skip to main content

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/// s language, or US English (see documentation for
46/// [`FormatMessage()`](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-formatmessagew)).
47/// The returned string is in UTF-8.
48///
49/// If a human readable message cannot be found for the given @error, an empty
50/// string is returned.
51/// ## `error`
52/// Win32 error code
53///
54/// # Returns
55///
56/// newly-allocated error message
57#[doc(alias = "g_win32_error_message")]
58pub fn error_message(error: i32) -> glib::GString {
59    unsafe { from_glib_full(ffi::g_win32_error_message(error)) }
60}
61
62#[doc(alias = "g_win32_ftruncate")]
63pub fn ftruncate(f: i32, size: u32) -> i32 {
64    unsafe { ffi::g_win32_ftruncate(f, size) }
65}
66
67/// Gets the command line arguments, on Windows, in the GLib filename
68/// encoding (ie: UTF-8).
69///
70/// Normally, on Windows, the command line arguments are passed to main()
71/// in the system codepage encoding.  This prevents passing filenames as
72/// arguments if the filenames contain characters that fall outside of
73/// this codepage.  If such filenames are passed, then substitutions
74/// will occur (such as replacing some characters with '?').
75///
76/// GLib's policy of using UTF-8 as a filename encoding on Windows was
77/// designed to localise the pain of dealing with filenames outside of
78/// the system codepage to one area: dealing with commandline arguments
79/// in main().
80///
81/// As such, most GLib programs should ignore the value of argv passed to
82/// their main() function and call g_win32_get_command_line() instead.
83/// This will get the "full Unicode" commandline arguments using
84/// GetCommandLineW() and convert it to the GLib filename encoding (which
85/// is UTF-8 on Windows).
86///
87/// The strings returned by this function are suitable for use with
88/// functions such as g_open() and g_file_new_for_commandline_arg() but
89/// are not suitable for use with g_option_context_parse(), which assumes
90/// that its input will be in the system codepage.  The return value is
91/// suitable for use with g_option_context_parse_strv(), however, which
92/// is a better match anyway because it won't leak memory.
93///
94/// Unlike argv, the returned value is a normal strv and can (and should)
95/// be freed with g_strfreev() when no longer needed.
96///
97/// # Returns
98///
99/// the commandline arguments in the GLib
100///   filename encoding (ie: UTF-8)
101#[doc(alias = "g_win32_get_command_line")]
102#[doc(alias = "get_command_line")]
103pub fn command_line() -> Vec<glib::GString> {
104    unsafe { FromGlibPtrContainer::from_glib_full(ffi::g_win32_get_command_line()) }
105}
106
107/// The setlocale() function in the Microsoft C library uses locale
108/// names of the form "English_United States.1252" etc. We want the
109/// UNIXish standard form "en_US", "zh_TW" etc. This function gets the
110/// current thread locale from Windows - without any encoding info -
111/// and returns it as a string of the above form for use in forming
112/// file names etc. The returned string should be deallocated with
113/// g_free().
114///
115/// # Returns
116///
117/// newly-allocated locale name.
118#[doc(alias = "g_win32_getlocale")]
119pub fn getlocale() -> glib::GString {
120    unsafe { from_glib_full(ffi::g_win32_getlocale()) }
121}
122
123/// Converts a filename from UTF-8 to the system codepage.
124///
125/// On NT-based Windows, on NTFS file systems, file names are in
126/// Unicode. It is quite possible that Unicode file names contain
127/// characters not representable in the system codepage. (For instance,
128/// Greek or Cyrillic characters on Western European or US Windows
129/// installations, or various less common CJK characters on CJK Windows
130/// installations.)
131///
132/// In such a case, and if the filename refers to an existing file, and
133/// the file system stores alternate short (8.3) names for directory
134/// entries, the short form of the filename is returned. Note that the
135/// "short" name might in fact be longer than the Unicode name if the
136/// Unicode name has very short pathname components containing
137/// non-ASCII characters. If no system codepage name for the file is
138/// possible, [`None`] is returned.
139///
140/// The return value is dynamically allocated and should be freed with
141/// g_free() when no longer needed.
142/// ## `utf8filename`
143/// a UTF-8 encoded filename.
144///
145/// # Returns
146///
147/// The converted filename, or [`None`] on conversion
148/// failure and lack of short names.
149#[doc(alias = "g_win32_locale_filename_from_utf8")]
150pub fn locale_filename_from_utf8(utf8filename: &str) -> glib::GString {
151    unsafe {
152        from_glib_full(ffi::g_win32_locale_filename_from_utf8(
153            utf8filename.to_glib_none().0,
154        ))
155    }
156}