Skip to main content

glib/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
5#[cfg(feature = "v2_66")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v2_66")))]
7use crate::FileSetContentsFlags;
8use crate::{
9    Bytes, ChecksumType, Error, FileTest, FormatSizeFlags, Pid, Source, SpawnFlags, UserDirectory,
10    ffi, translate::*,
11};
12use std::boxed::Box as Box_;
13
14/// A wrapper for the POSIX access() function. This function is used to
15/// test a pathname for one or several of read, write or execute
16/// permissions, or just existence.
17///
18/// On Windows, the file protection mechanism is not at all POSIX-like,
19/// and the underlying function in the C library only checks the
20/// FAT-style READONLY attribute, and does not look at the ACL of a
21/// file at all. This function is this in practise almost useless on
22/// Windows. Software that needs to handle file permissions on Windows
23/// more exactly should use the Win32 API.
24///
25/// See your C library manual for more details about access().
26/// ## `filename`
27/// a pathname in the GLib file name encoding
28///     (UTF-8 on Windows)
29/// ## `mode`
30/// as in access()
31///
32/// # Returns
33///
34/// zero if the pathname refers to an existing file system
35///     object that has all the tested permissions, or -1 otherwise
36///     or on error.
37// rustdoc-stripper-ignore-next-stop
38/// A wrapper for the POSIX access() function. This function is used to
39/// test a pathname for one or several of read, write or execute
40/// permissions, or just existence.
41///
42/// On Windows, the file protection mechanism is not at all POSIX-like,
43/// and the underlying function in the C library only checks the
44/// FAT-style READONLY attribute, and does not look at the ACL of a
45/// file at all. This function is this in practise almost useless on
46/// Windows. Software that needs to handle file permissions on Windows
47/// more exactly should use the Win32 API.
48///
49/// See your C library manual for more details about access().
50/// ## `filename`
51/// a pathname in the GLib file name encoding
52///     (UTF-8 on Windows)
53/// ## `mode`
54/// as in access()
55///
56/// # Returns
57///
58/// zero if the pathname refers to an existing file system
59///     object that has all the tested permissions, or -1 otherwise
60///     or on error.
61#[doc(alias = "g_access")]
62pub fn access(filename: impl AsRef<std::path::Path>, mode: i32) -> i32 {
63    unsafe { ffi::g_access(filename.as_ref().to_glib_none().0, mode) }
64}
65
66/// Decode a sequence of Base-64 encoded text into binary data.  Note
67/// that the returned binary data is not necessarily zero-terminated,
68/// so it should not be used as a character string.
69/// ## `text`
70/// zero-terminated string with base64 text to decode
71///
72/// # Returns
73///
74///
75///               newly allocated buffer containing the binary data
76///               that @text represents. The returned buffer must
77///               be freed with g_free().
78// rustdoc-stripper-ignore-next-stop
79/// Decode a sequence of Base-64 encoded text into binary data.  Note
80/// that the returned binary data is not necessarily zero-terminated,
81/// so it should not be used as a character string.
82/// ## `text`
83/// zero-terminated string with base64 text to decode
84///
85/// # Returns
86///
87///
88///               newly allocated buffer containing the binary data
89///               that @text represents. The returned buffer must
90///               be freed with g_free().
91#[doc(alias = "g_base64_decode")]
92pub fn base64_decode(text: &str) -> Vec<u8> {
93    unsafe {
94        let mut out_len = std::mem::MaybeUninit::uninit();
95        let ret = FromGlibContainer::from_glib_full_num(
96            ffi::g_base64_decode(text.to_glib_none().0, out_len.as_mut_ptr()),
97            out_len.assume_init() as _,
98        );
99        ret
100    }
101}
102
103//#[doc(alias = "g_base64_decode_inplace")]
104//pub fn base64_decode_inplace(text: /*Unimplemented*/Vec<u8>) -> u8 {
105//    unsafe { TODO: call ffi:g_base64_decode_inplace() }
106//}
107
108//#[doc(alias = "g_base64_decode_step")]
109//pub fn base64_decode_step(in_: &[&str], out: Vec<u8>, state: &mut i32, save: &mut u32) -> usize {
110//    unsafe { TODO: call ffi:g_base64_decode_step() }
111//}
112
113/// Encode a sequence of binary data into its Base-64 stringified
114/// representation.
115/// ## `data`
116/// the binary data to encode
117///
118/// # Returns
119///
120/// a newly allocated, zero-terminated Base-64
121///               encoded string representing @data. The returned string must
122///               be freed with g_free().
123// rustdoc-stripper-ignore-next-stop
124/// Encode a sequence of binary data into its Base-64 stringified
125/// representation.
126/// ## `data`
127/// the binary data to encode
128///
129/// # Returns
130///
131/// a newly allocated, zero-terminated Base-64
132///               encoded string representing @data. The returned string must
133///               be freed with g_free().
134#[doc(alias = "g_base64_encode")]
135pub fn base64_encode(data: &[u8]) -> crate::GString {
136    let len = data.len() as _;
137    unsafe { from_glib_full(ffi::g_base64_encode(data.to_glib_none().0, len)) }
138}
139
140//#[doc(alias = "g_base64_encode_close")]
141//pub fn base64_encode_close(break_lines: bool, out: Vec<u8>, state: &mut i32, save: &mut i32) -> usize {
142//    unsafe { TODO: call ffi:g_base64_encode_close() }
143//}
144
145//#[doc(alias = "g_base64_encode_step")]
146//pub fn base64_encode_step(in_: &[u8], break_lines: bool, out: Vec<u8>, state: &mut i32, save: &mut i32) -> usize {
147//    unsafe { TODO: call ffi:g_base64_encode_step() }
148//}
149
150/// Checks that the GLib library in use is compatible with the
151/// given version.
152///
153/// Generally you would pass in the constants `GLIB_MAJOR_VERSION`,
154/// `GLIB_MINOR_VERSION`, `GLIB_MICRO_VERSION` as the three arguments
155/// to this function; that produces a check that the library in use
156/// is compatible with the version of GLib the application or module
157/// was compiled against.
158///
159/// Compatibility is defined by two things: first the version
160/// of the running library is newer than the version
161/// `@required_major.required_minor.@required_micro`. Second
162/// the running library must be binary compatible with the
163/// version `@required_major.@required_minor.@required_micro`
164/// (same major version.)
165/// ## `required_major`
166/// the required major version
167/// ## `required_minor`
168/// the required minor version
169/// ## `required_micro`
170/// the required micro version
171///
172/// # Returns
173///
174/// [`None`] if the GLib library is
175///   compatible with the given version, or a string describing the
176///   version mismatch. The returned string is owned by GLib and must
177///   not be modified or freed.
178// rustdoc-stripper-ignore-next-stop
179/// Checks that the GLib library in use is compatible with the
180/// given version.
181///
182/// Generally you would pass in the constants `GLIB_MAJOR_VERSION`,
183/// `GLIB_MINOR_VERSION`, `GLIB_MICRO_VERSION` as the three arguments
184/// to this function; that produces a check that the library in use
185/// is compatible with the version of GLib the application or module
186/// was compiled against.
187///
188/// Compatibility is defined by two things: first the version
189/// of the running library is newer than the version
190/// `@required_major.required_minor.@required_micro`. Second
191/// the running library must be binary compatible with the
192/// version `@required_major.@required_minor.@required_micro`
193/// (same major version.)
194/// ## `required_major`
195/// the required major version
196/// ## `required_minor`
197/// the required minor version
198/// ## `required_micro`
199/// the required micro version
200///
201/// # Returns
202///
203/// [`None`] if the GLib library is
204///   compatible with the given version, or a string describing the
205///   version mismatch. The returned string is owned by GLib and must
206///   not be modified or freed.
207#[doc(alias = "glib_check_version")]
208pub fn check_version(
209    required_major: u32,
210    required_minor: u32,
211    required_micro: u32,
212) -> Option<crate::GString> {
213    unsafe {
214        from_glib_none(ffi::glib_check_version(
215            required_major,
216            required_minor,
217            required_micro,
218        ))
219    }
220}
221
222/// Computes the checksum for a binary @data. This is a
223/// convenience wrapper for g_checksum_new(), g_checksum_get_string()
224/// and g_checksum_free().
225///
226/// The hexadecimal string returned will be in lower case.
227/// ## `checksum_type`
228/// a #GChecksumType
229/// ## `data`
230/// binary blob to compute the digest of
231///
232/// # Returns
233///
234/// the digest of the binary data as a
235///   string in hexadecimal, or [`None`] if g_checksum_new() fails for
236///   @checksum_type. The returned string should be freed with g_free() when
237///   done using it.
238// rustdoc-stripper-ignore-next-stop
239/// Computes the checksum for a binary @data. This is a
240/// convenience wrapper for g_checksum_new(), g_checksum_get_string()
241/// and g_checksum_free().
242///
243/// The hexadecimal string returned will be in lower case.
244/// ## `checksum_type`
245/// a #GChecksumType
246/// ## `data`
247/// binary blob to compute the digest of
248///
249/// # Returns
250///
251/// the digest of the binary data as a
252///   string in hexadecimal, or [`None`] if g_checksum_new() fails for
253///   @checksum_type. The returned string should be freed with g_free() when
254///   done using it.
255#[doc(alias = "g_compute_checksum_for_bytes")]
256pub fn compute_checksum_for_bytes(
257    checksum_type: ChecksumType,
258    data: &Bytes,
259) -> Option<crate::GString> {
260    unsafe {
261        from_glib_full(ffi::g_compute_checksum_for_bytes(
262            checksum_type.into_glib(),
263            data.to_glib_none().0,
264        ))
265    }
266}
267
268/// Computes the checksum for a binary @data of @length. This is a
269/// convenience wrapper for g_checksum_new(), g_checksum_get_string()
270/// and g_checksum_free().
271///
272/// The hexadecimal string returned will be in lower case.
273/// ## `checksum_type`
274/// a #GChecksumType
275/// ## `data`
276/// binary blob to compute the digest of
277///
278/// # Returns
279///
280/// the digest of the binary data as a
281///   string in hexadecimal, or [`None`] if g_checksum_new() fails for
282///   @checksum_type. The returned string should be freed with g_free() when
283///   done using it.
284// rustdoc-stripper-ignore-next-stop
285/// Computes the checksum for a binary @data of @length. This is a
286/// convenience wrapper for g_checksum_new(), g_checksum_get_string()
287/// and g_checksum_free().
288///
289/// The hexadecimal string returned will be in lower case.
290/// ## `checksum_type`
291/// a #GChecksumType
292/// ## `data`
293/// binary blob to compute the digest of
294///
295/// # Returns
296///
297/// the digest of the binary data as a
298///   string in hexadecimal, or [`None`] if g_checksum_new() fails for
299///   @checksum_type. The returned string should be freed with g_free() when
300///   done using it.
301#[doc(alias = "g_compute_checksum_for_data")]
302pub fn compute_checksum_for_data(
303    checksum_type: ChecksumType,
304    data: &[u8],
305) -> Option<crate::GString> {
306    let length = data.len() as _;
307    unsafe {
308        from_glib_full(ffi::g_compute_checksum_for_data(
309            checksum_type.into_glib(),
310            data.to_glib_none().0,
311            length,
312        ))
313    }
314}
315
316/// Computes the HMAC for a binary @data. This is a
317/// convenience wrapper for g_hmac_new(), g_hmac_get_string()
318/// and g_hmac_unref().
319///
320/// The hexadecimal string returned will be in lower case.
321/// ## `digest_type`
322/// a #GChecksumType to use for the HMAC
323/// ## `key`
324/// the key to use in the HMAC
325/// ## `data`
326/// binary blob to compute the HMAC of
327///
328/// # Returns
329///
330/// the HMAC of the binary data as a string in hexadecimal.
331///   The returned string should be freed with g_free() when done using it.
332// rustdoc-stripper-ignore-next-stop
333/// Computes the HMAC for a binary @data. This is a
334/// convenience wrapper for g_hmac_new(), g_hmac_get_string()
335/// and g_hmac_unref().
336///
337/// The hexadecimal string returned will be in lower case.
338/// ## `digest_type`
339/// a #GChecksumType to use for the HMAC
340/// ## `key`
341/// the key to use in the HMAC
342/// ## `data`
343/// binary blob to compute the HMAC of
344///
345/// # Returns
346///
347/// the HMAC of the binary data as a string in hexadecimal.
348///   The returned string should be freed with g_free() when done using it.
349#[doc(alias = "g_compute_hmac_for_bytes")]
350pub fn compute_hmac_for_bytes(
351    digest_type: ChecksumType,
352    key: &Bytes,
353    data: &Bytes,
354) -> crate::GString {
355    unsafe {
356        from_glib_full(ffi::g_compute_hmac_for_bytes(
357            digest_type.into_glib(),
358            key.to_glib_none().0,
359            data.to_glib_none().0,
360        ))
361    }
362}
363
364/// Computes the HMAC for a binary @data of @length. This is a
365/// convenience wrapper for g_hmac_new(), g_hmac_get_string()
366/// and g_hmac_unref().
367///
368/// The hexadecimal string returned will be in lower case.
369/// ## `digest_type`
370/// a #GChecksumType to use for the HMAC
371/// ## `key`
372/// the key to use in the HMAC
373/// ## `data`
374/// binary blob to compute the HMAC of
375///
376/// # Returns
377///
378/// the HMAC of the binary data as a string in hexadecimal.
379///   The returned string should be freed with g_free() when done using it.
380// rustdoc-stripper-ignore-next-stop
381/// Computes the HMAC for a binary @data of @length. This is a
382/// convenience wrapper for g_hmac_new(), g_hmac_get_string()
383/// and g_hmac_unref().
384///
385/// The hexadecimal string returned will be in lower case.
386/// ## `digest_type`
387/// a #GChecksumType to use for the HMAC
388/// ## `key`
389/// the key to use in the HMAC
390/// ## `data`
391/// binary blob to compute the HMAC of
392///
393/// # Returns
394///
395/// the HMAC of the binary data as a string in hexadecimal.
396///   The returned string should be freed with g_free() when done using it.
397#[doc(alias = "g_compute_hmac_for_data")]
398pub fn compute_hmac_for_data(digest_type: ChecksumType, key: &[u8], data: &[u8]) -> crate::GString {
399    let key_len = key.len() as _;
400    let length = data.len() as _;
401    unsafe {
402        from_glib_full(ffi::g_compute_hmac_for_data(
403            digest_type.into_glib(),
404            key.to_glib_none().0,
405            key_len,
406            data.to_glib_none().0,
407            length,
408        ))
409    }
410}
411
412/// This is a variant of g_dgettext() that allows specifying a locale
413/// category instead of always using `LC_MESSAGES`. See g_dgettext() for
414/// more information about how this functions differs from calling
415/// dcgettext() directly.
416/// ## `domain`
417/// the translation domain to use, or [`None`] to use
418///   the domain set with textdomain()
419/// ## `msgid`
420/// message to translate
421/// ## `category`
422/// a locale category
423///
424/// # Returns
425///
426/// the translated string for the given locale category
427// rustdoc-stripper-ignore-next-stop
428/// This is a variant of g_dgettext() that allows specifying a locale
429/// category instead of always using `LC_MESSAGES`. See g_dgettext() for
430/// more information about how this functions differs from calling
431/// dcgettext() directly.
432/// ## `domain`
433/// the translation domain to use, or [`None`] to use
434///   the domain set with textdomain()
435/// ## `msgid`
436/// message to translate
437/// ## `category`
438/// a locale category
439///
440/// # Returns
441///
442/// the translated string for the given locale category
443#[doc(alias = "g_dcgettext")]
444pub fn dcgettext(domain: Option<&str>, msgid: &str, category: i32) -> crate::GString {
445    unsafe {
446        from_glib_none(ffi::g_dcgettext(
447            domain.to_glib_none().0,
448            msgid.to_glib_none().0,
449            category,
450        ))
451    }
452}
453
454/// This function is a wrapper of dgettext() which does not translate
455/// the message if the default domain as set with textdomain() has no
456/// translations for the current locale.
457///
458/// The advantage of using this function over dgettext() proper is that
459/// libraries using this function (like GTK) will not use translations
460/// if the application using the library does not have translations for
461/// the current locale.  This results in a consistent English-only
462/// interface instead of one having partial translations.  For this
463/// feature to work, the call to textdomain() and setlocale() should
464/// precede any g_dgettext() invocations.  For GTK, it means calling
465/// textdomain() before gtk_init or its variants.
466///
467/// This function disables translations if and only if upon its first
468/// call all the following conditions hold:
469///
470/// - @domain is not [`None`]
471///
472/// - textdomain() has been called to set a default text domain
473///
474/// - there is no translations available for the default text domain
475///   and the current locale
476///
477/// - current locale is not "C" or any English locales (those
478///   starting with "en_")
479///
480/// Note that this behavior may not be desired for example if an application
481/// has its untranslated messages in a language other than English. In those
482/// cases the application should call textdomain() after initializing GTK.
483///
484/// Applications should normally not use this function directly,
485/// but use the _() macro for translations.
486/// ## `domain`
487/// the translation domain to use, or [`None`] to use
488///   the domain set with textdomain()
489/// ## `msgid`
490/// message to translate
491///
492/// # Returns
493///
494/// The translated string
495// rustdoc-stripper-ignore-next-stop
496/// This function is a wrapper of dgettext() which does not translate
497/// the message if the default domain as set with textdomain() has no
498/// translations for the current locale.
499///
500/// The advantage of using this function over dgettext() proper is that
501/// libraries using this function (like GTK) will not use translations
502/// if the application using the library does not have translations for
503/// the current locale.  This results in a consistent English-only
504/// interface instead of one having partial translations.  For this
505/// feature to work, the call to textdomain() and setlocale() should
506/// precede any g_dgettext() invocations.  For GTK, it means calling
507/// textdomain() before gtk_init or its variants.
508///
509/// This function disables translations if and only if upon its first
510/// call all the following conditions hold:
511///
512/// - @domain is not [`None`]
513///
514/// - textdomain() has been called to set a default text domain
515///
516/// - there is no translations available for the default text domain
517///   and the current locale
518///
519/// - current locale is not "C" or any English locales (those
520///   starting with "en_")
521///
522/// Note that this behavior may not be desired for example if an application
523/// has its untranslated messages in a language other than English. In those
524/// cases the application should call textdomain() after initializing GTK.
525///
526/// Applications should normally not use this function directly,
527/// but use the _() macro for translations.
528/// ## `domain`
529/// the translation domain to use, or [`None`] to use
530///   the domain set with textdomain()
531/// ## `msgid`
532/// message to translate
533///
534/// # Returns
535///
536/// The translated string
537#[doc(alias = "g_dgettext")]
538pub fn dgettext(domain: Option<&str>, msgid: &str) -> crate::GString {
539    unsafe {
540        from_glib_none(ffi::g_dgettext(
541            domain.to_glib_none().0,
542            msgid.to_glib_none().0,
543        ))
544    }
545}
546
547/// This function is a wrapper of dngettext() which does not translate
548/// the message if the default domain as set with textdomain() has no
549/// translations for the current locale.
550///
551/// See g_dgettext() for details of how this differs from dngettext()
552/// proper.
553/// ## `domain`
554/// the translation domain to use, or [`None`] to use
555///   the domain set with textdomain()
556/// ## `msgid`
557/// message to translate
558/// ## `msgid_plural`
559/// plural form of the message
560/// ## `n`
561/// the quantity for which translation is needed
562///
563/// # Returns
564///
565/// The translated string
566// rustdoc-stripper-ignore-next-stop
567/// This function is a wrapper of dngettext() which does not translate
568/// the message if the default domain as set with textdomain() has no
569/// translations for the current locale.
570///
571/// See g_dgettext() for details of how this differs from dngettext()
572/// proper.
573/// ## `domain`
574/// the translation domain to use, or [`None`] to use
575///   the domain set with textdomain()
576/// ## `msgid`
577/// message to translate
578/// ## `msgid_plural`
579/// plural form of the message
580/// ## `n`
581/// the quantity for which translation is needed
582///
583/// # Returns
584///
585/// The translated string
586#[doc(alias = "g_dngettext")]
587pub fn dngettext(
588    domain: Option<&str>,
589    msgid: &str,
590    msgid_plural: &str,
591    n: libc::c_ulong,
592) -> crate::GString {
593    unsafe {
594        from_glib_none(ffi::g_dngettext(
595            domain.to_glib_none().0,
596            msgid.to_glib_none().0,
597            msgid_plural.to_glib_none().0,
598            n,
599        ))
600    }
601}
602
603/// This function is a variant of g_dgettext() which supports
604/// a disambiguating message context. GNU gettext uses the
605/// '\004' character to separate the message context and
606/// message id in @msgctxtid.
607/// If 0 is passed as @msgidoffset, this function will fall back to
608/// trying to use the deprecated convention of using "|" as a separation
609/// character.
610///
611/// This uses g_dgettext() internally. See that functions for differences
612/// with dgettext() proper.
613///
614/// Applications should normally not use this function directly,
615/// but use the C_() macro for translations with context.
616/// ## `domain`
617/// the translation domain to use, or [`None`] to use
618///   the domain set with textdomain()
619/// ## `msgctxtid`
620/// a combined message context and message id, separated
621///   by a \004 character
622/// ## `msgidoffset`
623/// the offset of the message id in @msgctxid
624///
625/// # Returns
626///
627/// The translated string
628// rustdoc-stripper-ignore-next-stop
629/// This function is a variant of g_dgettext() which supports
630/// a disambiguating message context. GNU gettext uses the
631/// '\004' character to separate the message context and
632/// message id in @msgctxtid.
633/// If 0 is passed as @msgidoffset, this function will fall back to
634/// trying to use the deprecated convention of using "|" as a separation
635/// character.
636///
637/// This uses g_dgettext() internally. See that functions for differences
638/// with dgettext() proper.
639///
640/// Applications should normally not use this function directly,
641/// but use the C_() macro for translations with context.
642/// ## `domain`
643/// the translation domain to use, or [`None`] to use
644///   the domain set with textdomain()
645/// ## `msgctxtid`
646/// a combined message context and message id, separated
647///   by a \004 character
648/// ## `msgidoffset`
649/// the offset of the message id in @msgctxid
650///
651/// # Returns
652///
653/// The translated string
654#[doc(alias = "g_dpgettext")]
655pub fn dpgettext(domain: Option<&str>, msgctxtid: &str, msgidoffset: usize) -> crate::GString {
656    unsafe {
657        from_glib_none(ffi::g_dpgettext(
658            domain.to_glib_none().0,
659            msgctxtid.to_glib_none().0,
660            msgidoffset,
661        ))
662    }
663}
664
665/// This function is a variant of g_dgettext() which supports
666/// a disambiguating message context. GNU gettext uses the
667/// '\004' character to separate the message context and
668/// message id in @msgctxtid.
669///
670/// This uses g_dgettext() internally. See that functions for differences
671/// with dgettext() proper.
672///
673/// This function differs from C_() in that it is not a macro and
674/// thus you may use non-string-literals as context and msgid arguments.
675/// ## `domain`
676/// the translation domain to use, or [`None`] to use
677///   the domain set with textdomain()
678/// ## `context`
679/// the message context
680/// ## `msgid`
681/// the message
682///
683/// # Returns
684///
685/// The translated string
686// rustdoc-stripper-ignore-next-stop
687/// This function is a variant of g_dgettext() which supports
688/// a disambiguating message context. GNU gettext uses the
689/// '\004' character to separate the message context and
690/// message id in @msgctxtid.
691///
692/// This uses g_dgettext() internally. See that functions for differences
693/// with dgettext() proper.
694///
695/// This function differs from C_() in that it is not a macro and
696/// thus you may use non-string-literals as context and msgid arguments.
697/// ## `domain`
698/// the translation domain to use, or [`None`] to use
699///   the domain set with textdomain()
700/// ## `context`
701/// the message context
702/// ## `msgid`
703/// the message
704///
705/// # Returns
706///
707/// The translated string
708#[doc(alias = "g_dpgettext2")]
709pub fn dpgettext2(domain: Option<&str>, context: &str, msgid: &str) -> crate::GString {
710    unsafe {
711        from_glib_none(ffi::g_dpgettext2(
712            domain.to_glib_none().0,
713            context.to_glib_none().0,
714            msgid.to_glib_none().0,
715        ))
716    }
717}
718
719/// Writes all of @contents to a file named @filename. This is a convenience
720/// wrapper around calling g_file_set_contents_full() with `flags` set to
721/// `G_FILE_SET_CONTENTS_CONSISTENT | G_FILE_SET_CONTENTS_ONLY_EXISTING` and
722/// `mode` set to `0666`.
723/// ## `filename`
724/// name of a file to write @contents to, in the GLib file name
725///   encoding
726/// ## `contents`
727/// string to write to the file
728///
729/// # Returns
730///
731/// [`true`] on success, [`false`] if an error occurred
732// rustdoc-stripper-ignore-next-stop
733/// Writes all of @contents to a file named @filename. This is a convenience
734/// wrapper around calling g_file_set_contents_full() with `flags` set to
735/// `G_FILE_SET_CONTENTS_CONSISTENT | G_FILE_SET_CONTENTS_ONLY_EXISTING` and
736/// `mode` set to `0666`.
737/// ## `filename`
738/// name of a file to write @contents to, in the GLib file name
739///   encoding
740/// ## `contents`
741/// string to write to the file
742///
743/// # Returns
744///
745/// [`true`] on success, [`false`] if an error occurred
746#[doc(alias = "g_file_set_contents")]
747pub fn file_set_contents(
748    filename: impl AsRef<std::path::Path>,
749    contents: &[u8],
750) -> Result<(), crate::Error> {
751    let length = contents.len() as _;
752    unsafe {
753        let mut error = std::ptr::null_mut();
754        let is_ok = ffi::g_file_set_contents(
755            filename.as_ref().to_glib_none().0,
756            contents.to_glib_none().0,
757            length,
758            &mut error,
759        );
760        debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
761        if error.is_null() {
762            Ok(())
763        } else {
764            Err(from_glib_full(error))
765        }
766    }
767}
768
769/// Writes all of @contents to a file named @filename, with good error checking.
770/// If a file called @filename already exists it will be overwritten.
771///
772/// @flags control the properties of the write operation: whether it’s atomic,
773/// and what the tradeoff is between returning quickly or being resilient to
774/// system crashes.
775///
776/// As this function performs file I/O, it is recommended to not call it anywhere
777/// where blocking would cause problems, such as in the main loop of a graphical
778/// application. In particular, if @flags has any value other than
779/// [`FileSetContentsFlags::NONE`][crate::FileSetContentsFlags::NONE] then this function may call `fsync()`.
780///
781/// If [`FileSetContentsFlags::CONSISTENT`][crate::FileSetContentsFlags::CONSISTENT] is set in @flags, the operation is atomic
782/// in the sense that it is first written to a temporary file which is then
783/// renamed to the final name.
784///
785/// Notes:
786///
787/// - On UNIX, if @filename already exists hard links to @filename will break.
788///   Also since the file is recreated, existing permissions, access control
789///   lists, metadata etc. may be lost. If @filename is a symbolic link,
790///   the link itself will be replaced, not the linked file.
791///
792/// - On UNIX, if @filename already exists and is non-empty, and if the system
793///   supports it (via a journalling filesystem or equivalent), and if
794///   [`FileSetContentsFlags::CONSISTENT`][crate::FileSetContentsFlags::CONSISTENT] is set in @flags, the `fsync()` call (or
795///   equivalent) will be used to ensure atomic replacement: @filename
796///   will contain either its old contents or @contents, even in the face of
797///   system power loss, the disk being unsafely removed, etc.
798///
799/// - On UNIX, if @filename does not already exist or is empty, there is a
800///   possibility that system power loss etc. after calling this function will
801///   leave @filename empty or full of NUL bytes, depending on the underlying
802///   filesystem, unless [`FileSetContentsFlags::DURABLE`][crate::FileSetContentsFlags::DURABLE] and
803///   [`FileSetContentsFlags::CONSISTENT`][crate::FileSetContentsFlags::CONSISTENT] are set in @flags.
804///
805/// - On Windows renaming a file will not remove an existing file with the
806///   new name, so on Windows there is a race condition between the existing
807///   file being removed and the temporary file being renamed.
808///
809/// - On Windows there is no way to remove a file that is open to some
810///   process, or mapped into memory. Thus, this function will fail if
811///   @filename already exists and is open.
812///
813/// If the call was successful, it returns [`true`]. If the call was not successful,
814/// it returns [`false`] and sets @error. The error domain is `G_FILE_ERROR`.
815/// Possible error codes are those in the #GFileError enumeration.
816///
817/// Note that the name for the temporary file is constructed by appending up
818/// to 7 characters to @filename.
819///
820/// If the file didn’t exist before and is created, it will be given the
821/// permissions from @mode. Otherwise, the permissions of the existing file will
822/// remain unchanged.
823/// ## `filename`
824/// name of a file to write @contents to, in the GLib file name
825///   encoding
826/// ## `contents`
827/// string to write to the file
828/// ## `flags`
829/// flags controlling the safety vs speed of the operation
830/// ## `mode`
831/// file mode, as passed to `open()`; typically this will be `0666`
832///
833/// # Returns
834///
835/// [`true`] on success, [`false`] if an error occurred
836// rustdoc-stripper-ignore-next-stop
837/// Writes all of @contents to a file named @filename, with good error checking.
838/// If a file called @filename already exists it will be overwritten.
839///
840/// @flags control the properties of the write operation: whether it’s atomic,
841/// and what the tradeoff is between returning quickly or being resilient to
842/// system crashes.
843///
844/// As this function performs file I/O, it is recommended to not call it anywhere
845/// where blocking would cause problems, such as in the main loop of a graphical
846/// application. In particular, if @flags has any value other than
847/// [`FileSetContentsFlags::NONE`][crate::FileSetContentsFlags::NONE] then this function may call `fsync()`.
848///
849/// If [`FileSetContentsFlags::CONSISTENT`][crate::FileSetContentsFlags::CONSISTENT] is set in @flags, the operation is atomic
850/// in the sense that it is first written to a temporary file which is then
851/// renamed to the final name.
852///
853/// Notes:
854///
855/// - On UNIX, if @filename already exists hard links to @filename will break.
856///   Also since the file is recreated, existing permissions, access control
857///   lists, metadata etc. may be lost. If @filename is a symbolic link,
858///   the link itself will be replaced, not the linked file.
859///
860/// - On UNIX, if @filename already exists and is non-empty, and if the system
861///   supports it (via a journalling filesystem or equivalent), and if
862///   [`FileSetContentsFlags::CONSISTENT`][crate::FileSetContentsFlags::CONSISTENT] is set in @flags, the `fsync()` call (or
863///   equivalent) will be used to ensure atomic replacement: @filename
864///   will contain either its old contents or @contents, even in the face of
865///   system power loss, the disk being unsafely removed, etc.
866///
867/// - On UNIX, if @filename does not already exist or is empty, there is a
868///   possibility that system power loss etc. after calling this function will
869///   leave @filename empty or full of NUL bytes, depending on the underlying
870///   filesystem, unless [`FileSetContentsFlags::DURABLE`][crate::FileSetContentsFlags::DURABLE] and
871///   [`FileSetContentsFlags::CONSISTENT`][crate::FileSetContentsFlags::CONSISTENT] are set in @flags.
872///
873/// - On Windows renaming a file will not remove an existing file with the
874///   new name, so on Windows there is a race condition between the existing
875///   file being removed and the temporary file being renamed.
876///
877/// - On Windows there is no way to remove a file that is open to some
878///   process, or mapped into memory. Thus, this function will fail if
879///   @filename already exists and is open.
880///
881/// If the call was successful, it returns [`true`]. If the call was not successful,
882/// it returns [`false`] and sets @error. The error domain is `G_FILE_ERROR`.
883/// Possible error codes are those in the #GFileError enumeration.
884///
885/// Note that the name for the temporary file is constructed by appending up
886/// to 7 characters to @filename.
887///
888/// If the file didn’t exist before and is created, it will be given the
889/// permissions from @mode. Otherwise, the permissions of the existing file will
890/// remain unchanged.
891/// ## `filename`
892/// name of a file to write @contents to, in the GLib file name
893///   encoding
894/// ## `contents`
895/// string to write to the file
896/// ## `flags`
897/// flags controlling the safety vs speed of the operation
898/// ## `mode`
899/// file mode, as passed to `open()`; typically this will be `0666`
900///
901/// # Returns
902///
903/// [`true`] on success, [`false`] if an error occurred
904#[cfg(feature = "v2_66")]
905#[cfg_attr(docsrs, doc(cfg(feature = "v2_66")))]
906#[doc(alias = "g_file_set_contents_full")]
907pub fn file_set_contents_full(
908    filename: impl AsRef<std::path::Path>,
909    contents: &[u8],
910    flags: FileSetContentsFlags,
911    mode: i32,
912) -> Result<(), crate::Error> {
913    let length = contents.len() as _;
914    unsafe {
915        let mut error = std::ptr::null_mut();
916        let is_ok = ffi::g_file_set_contents_full(
917            filename.as_ref().to_glib_none().0,
918            contents.to_glib_none().0,
919            length,
920            flags.into_glib(),
921            mode,
922            &mut error,
923        );
924        debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
925        if error.is_null() {
926            Ok(())
927        } else {
928            Err(from_glib_full(error))
929        }
930    }
931}
932
933/// Returns [`true`] if any of the tests in the bitfield @test are
934/// [`true`]. For example, `(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)`
935/// will return [`true`] if the file exists; the check whether it's a
936/// directory doesn't matter since the existence test is [`true`]. With
937/// the current set of available tests, there's no point passing in
938/// more than one test at a time.
939///
940/// Apart from [`FileTest::IS_SYMLINK`][crate::FileTest::IS_SYMLINK] all tests follow symbolic links,
941/// so for a symbolic link to a regular file g_file_test() will return
942/// [`true`] for both [`FileTest::IS_SYMLINK`][crate::FileTest::IS_SYMLINK] and [`FileTest::IS_REGULAR`][crate::FileTest::IS_REGULAR].
943///
944/// Note, that for a dangling symbolic link g_file_test() will return
945/// [`true`] for [`FileTest::IS_SYMLINK`][crate::FileTest::IS_SYMLINK] and [`false`] for all other flags.
946///
947/// You should never use g_file_test() to test whether it is safe
948/// to perform an operation, because there is always the possibility
949/// of the condition changing before you actually perform the operation,
950/// see [TOCTOU](https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use).
951///
952/// For example, you might think you could use [`FileTest::IS_SYMLINK`][crate::FileTest::IS_SYMLINK]
953/// to know whether it is safe to write to a file without being
954/// tricked into writing into a different location. It doesn't work!
955///
956///
957///
958/// **⚠️ The following code is in C ⚠️**
959///
960/// ```C
961///  // DON'T DO THIS
962///  if (!g_file_test (filename, G_FILE_TEST_IS_SYMLINK))
963///    {
964///      fd = g_open (filename, O_WRONLY);
965///      // write to fd
966///    }
967///
968///  // DO THIS INSTEAD
969///  fd = g_open (filename, O_WRONLY | O_NOFOLLOW | O_CLOEXEC);
970///  if (fd == -1)
971///    {
972///      // check error
973///      if (errno == ELOOP)
974///        // file is a symlink and can be ignored
975///      else
976///        // handle errors as before
977///    }
978///  else
979///    {
980///      // write to fd
981///    }
982/// ```
983///
984/// Another thing to note is that [`FileTest::EXISTS`][crate::FileTest::EXISTS] and
985/// [`FileTest::IS_EXECUTABLE`][crate::FileTest::IS_EXECUTABLE] are implemented using the access()
986/// system call. This usually doesn't matter, but if your program
987/// is setuid or setgid it means that these tests will give you
988/// the answer for the real user ID and group ID, rather than the
989/// effective user ID and group ID.
990///
991/// On Windows, there are no symlinks, so testing for
992/// [`FileTest::IS_SYMLINK`][crate::FileTest::IS_SYMLINK] will always return [`false`]. Testing for
993/// [`FileTest::IS_EXECUTABLE`][crate::FileTest::IS_EXECUTABLE] will just check that the file exists and
994/// its name indicates that it is executable, checking for well-known
995/// extensions and those listed in the `PATHEXT` environment variable.
996/// ## `filename`
997/// a filename to test in the
998///     GLib file name encoding
999/// ## `test`
1000/// bitfield of #GFileTest flags
1001///
1002/// # Returns
1003///
1004/// whether a test was [`true`]
1005// rustdoc-stripper-ignore-next-stop
1006/// Returns [`true`] if any of the tests in the bitfield @test are
1007/// [`true`]. For example, `(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)`
1008/// will return [`true`] if the file exists; the check whether it's a
1009/// directory doesn't matter since the existence test is [`true`]. With
1010/// the current set of available tests, there's no point passing in
1011/// more than one test at a time.
1012///
1013/// Apart from [`FileTest::IS_SYMLINK`][crate::FileTest::IS_SYMLINK] all tests follow symbolic links,
1014/// so for a symbolic link to a regular file g_file_test() will return
1015/// [`true`] for both [`FileTest::IS_SYMLINK`][crate::FileTest::IS_SYMLINK] and [`FileTest::IS_REGULAR`][crate::FileTest::IS_REGULAR].
1016///
1017/// Note, that for a dangling symbolic link g_file_test() will return
1018/// [`true`] for [`FileTest::IS_SYMLINK`][crate::FileTest::IS_SYMLINK] and [`false`] for all other flags.
1019///
1020/// You should never use g_file_test() to test whether it is safe
1021/// to perform an operation, because there is always the possibility
1022/// of the condition changing before you actually perform the operation,
1023/// see [TOCTOU](https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use).
1024///
1025/// For example, you might think you could use [`FileTest::IS_SYMLINK`][crate::FileTest::IS_SYMLINK]
1026/// to know whether it is safe to write to a file without being
1027/// tricked into writing into a different location. It doesn't work!
1028///
1029///
1030///
1031/// **⚠️ The following code is in C ⚠️**
1032///
1033/// ```C
1034///  // DON'T DO THIS
1035///  if (!g_file_test (filename, G_FILE_TEST_IS_SYMLINK))
1036///    {
1037///      fd = g_open (filename, O_WRONLY);
1038///      // write to fd
1039///    }
1040///
1041///  // DO THIS INSTEAD
1042///  fd = g_open (filename, O_WRONLY | O_NOFOLLOW | O_CLOEXEC);
1043///  if (fd == -1)
1044///    {
1045///      // check error
1046///      if (errno == ELOOP)
1047///        // file is a symlink and can be ignored
1048///      else
1049///        // handle errors as before
1050///    }
1051///  else
1052///    {
1053///      // write to fd
1054///    }
1055/// ```
1056///
1057/// Another thing to note is that [`FileTest::EXISTS`][crate::FileTest::EXISTS] and
1058/// [`FileTest::IS_EXECUTABLE`][crate::FileTest::IS_EXECUTABLE] are implemented using the access()
1059/// system call. This usually doesn't matter, but if your program
1060/// is setuid or setgid it means that these tests will give you
1061/// the answer for the real user ID and group ID, rather than the
1062/// effective user ID and group ID.
1063///
1064/// On Windows, there are no symlinks, so testing for
1065/// [`FileTest::IS_SYMLINK`][crate::FileTest::IS_SYMLINK] will always return [`false`]. Testing for
1066/// [`FileTest::IS_EXECUTABLE`][crate::FileTest::IS_EXECUTABLE] will just check that the file exists and
1067/// its name indicates that it is executable, checking for well-known
1068/// extensions and those listed in the `PATHEXT` environment variable.
1069/// ## `filename`
1070/// a filename to test in the
1071///     GLib file name encoding
1072/// ## `test`
1073/// bitfield of #GFileTest flags
1074///
1075/// # Returns
1076///
1077/// whether a test was [`true`]
1078#[doc(alias = "g_file_test")]
1079#[allow(dead_code)]
1080pub(crate) fn file_test(filename: impl AsRef<std::path::Path>, test: FileTest) -> bool {
1081    unsafe {
1082        from_glib(ffi::g_file_test(
1083            filename.as_ref().to_glib_none().0,
1084            test.into_glib(),
1085        ))
1086    }
1087}
1088
1089/// Returns the display basename for the particular filename, guaranteed
1090/// to be valid UTF-8. The display name might not be identical to the filename,
1091/// for instance there might be problems converting it to UTF-8, and some files
1092/// can be translated in the display.
1093///
1094/// If GLib cannot make sense of the encoding of @filename, as a last resort it
1095/// replaces unknown characters with U+FFFD, the Unicode replacement character.
1096/// You can search the result for the UTF-8 encoding of this character (which is
1097/// "\357\277\275" in octal notation) to find out if @filename was in an invalid
1098/// encoding.
1099///
1100/// You must pass the whole absolute pathname to this functions so that
1101/// translation of well known locations can be done.
1102///
1103/// This function is preferred over g_filename_display_name() if you know the
1104/// whole path, as it allows translation.
1105/// ## `filename`
1106/// an absolute pathname in the
1107///     GLib file name encoding
1108///
1109/// # Returns
1110///
1111/// a newly allocated string containing
1112///   a rendition of the basename of the filename in valid UTF-8
1113// rustdoc-stripper-ignore-next-stop
1114/// Returns the display basename for the particular filename, guaranteed
1115/// to be valid UTF-8. The display name might not be identical to the filename,
1116/// for instance there might be problems converting it to UTF-8, and some files
1117/// can be translated in the display.
1118///
1119/// If GLib cannot make sense of the encoding of @filename, as a last resort it
1120/// replaces unknown characters with U+FFFD, the Unicode replacement character.
1121/// You can search the result for the UTF-8 encoding of this character (which is
1122/// "\357\277\275" in octal notation) to find out if @filename was in an invalid
1123/// encoding.
1124///
1125/// You must pass the whole absolute pathname to this functions so that
1126/// translation of well known locations can be done.
1127///
1128/// This function is preferred over g_filename_display_name() if you know the
1129/// whole path, as it allows translation.
1130/// ## `filename`
1131/// an absolute pathname in the
1132///     GLib file name encoding
1133///
1134/// # Returns
1135///
1136/// a newly allocated string containing
1137///   a rendition of the basename of the filename in valid UTF-8
1138#[doc(alias = "g_filename_display_basename")]
1139pub fn filename_display_basename(filename: impl AsRef<std::path::Path>) -> crate::GString {
1140    unsafe {
1141        from_glib_full(ffi::g_filename_display_basename(
1142            filename.as_ref().to_glib_none().0,
1143        ))
1144    }
1145}
1146
1147/// Converts a filename into a valid UTF-8 string. The conversion is
1148/// not necessarily reversible, so you should keep the original around
1149/// and use the return value of this function only for display purposes.
1150/// Unlike g_filename_to_utf8(), the result is guaranteed to be non-[`None`]
1151/// even if the filename actually isn't in the GLib file name encoding.
1152///
1153/// If GLib cannot make sense of the encoding of @filename, as a last resort it
1154/// replaces unknown characters with U+FFFD, the Unicode replacement character.
1155/// You can search the result for the UTF-8 encoding of this character (which is
1156/// "\357\277\275" in octal notation) to find out if @filename was in an invalid
1157/// encoding.
1158///
1159/// If you know the whole pathname of the file you should use
1160/// g_filename_display_basename(), since that allows location-based
1161/// translation of filenames.
1162/// ## `filename`
1163/// a pathname hopefully in the
1164///     GLib file name encoding
1165///
1166/// # Returns
1167///
1168/// a newly allocated string containing
1169///   a rendition of the filename in valid UTF-8
1170// rustdoc-stripper-ignore-next-stop
1171/// Converts a filename into a valid UTF-8 string. The conversion is
1172/// not necessarily reversible, so you should keep the original around
1173/// and use the return value of this function only for display purposes.
1174/// Unlike g_filename_to_utf8(), the result is guaranteed to be non-[`None`]
1175/// even if the filename actually isn't in the GLib file name encoding.
1176///
1177/// If GLib cannot make sense of the encoding of @filename, as a last resort it
1178/// replaces unknown characters with U+FFFD, the Unicode replacement character.
1179/// You can search the result for the UTF-8 encoding of this character (which is
1180/// "\357\277\275" in octal notation) to find out if @filename was in an invalid
1181/// encoding.
1182///
1183/// If you know the whole pathname of the file you should use
1184/// g_filename_display_basename(), since that allows location-based
1185/// translation of filenames.
1186/// ## `filename`
1187/// a pathname hopefully in the
1188///     GLib file name encoding
1189///
1190/// # Returns
1191///
1192/// a newly allocated string containing
1193///   a rendition of the filename in valid UTF-8
1194#[doc(alias = "g_filename_display_name")]
1195pub fn filename_display_name(filename: impl AsRef<std::path::Path>) -> crate::GString {
1196    unsafe {
1197        from_glib_full(ffi::g_filename_display_name(
1198            filename.as_ref().to_glib_none().0,
1199        ))
1200    }
1201}
1202
1203/// Converts an escaped ASCII-encoded URI to a local filename in the
1204/// encoding used for filenames.
1205///
1206/// Since GLib 2.78, the query string and fragment can be present in the URI,
1207/// but are not part of the resulting filename.
1208/// We take inspiration from https://url.spec.whatwg.org/#file-state,
1209/// but we don't support the entire standard.
1210/// ## `uri`
1211/// a uri describing a filename (escaped, encoded in ASCII).
1212///
1213/// # Returns
1214///
1215/// a newly-allocated string holding
1216///               the resulting filename, or [`None`] on an error.
1217///
1218/// ## `hostname`
1219/// Location to store hostname for the URI.
1220///            If there is no hostname in the URI, [`None`] will be
1221///            stored in this location.
1222// rustdoc-stripper-ignore-next-stop
1223/// Converts an escaped ASCII-encoded URI to a local filename in the
1224/// encoding used for filenames.
1225///
1226/// Since GLib 2.78, the query string and fragment can be present in the URI,
1227/// but are not part of the resulting filename.
1228/// We take inspiration from https://url.spec.whatwg.org/#file-state,
1229/// but we don't support the entire standard.
1230/// ## `uri`
1231/// a uri describing a filename (escaped, encoded in ASCII).
1232///
1233/// # Returns
1234///
1235/// a newly-allocated string holding
1236///               the resulting filename, or [`None`] on an error.
1237///
1238/// ## `hostname`
1239/// Location to store hostname for the URI.
1240///            If there is no hostname in the URI, [`None`] will be
1241///            stored in this location.
1242#[doc(alias = "g_filename_from_uri")]
1243pub fn filename_from_uri(
1244    uri: &str,
1245) -> Result<(std::path::PathBuf, Option<crate::GString>), crate::Error> {
1246    unsafe {
1247        let mut hostname = std::ptr::null_mut();
1248        let mut error = std::ptr::null_mut();
1249        let ret = ffi::g_filename_from_uri(uri.to_glib_none().0, &mut hostname, &mut error);
1250        if error.is_null() {
1251            Ok((from_glib_full(ret), from_glib_full(hostname)))
1252        } else {
1253            Err(from_glib_full(error))
1254        }
1255    }
1256}
1257
1258/// Converts an absolute filename to an escaped ASCII-encoded URI, with the path
1259/// component following Section 3.3. of RFC 2396.
1260/// ## `filename`
1261/// an absolute filename specified in the GLib file
1262///     name encoding, which is the on-disk file name bytes on Unix, and UTF-8
1263///     on Windows
1264/// ## `hostname`
1265/// A UTF-8 encoded hostname, or [`None`] for none.
1266///
1267/// # Returns
1268///
1269/// a newly-allocated string holding the resulting
1270///               URI, or [`None`] on an error.
1271// rustdoc-stripper-ignore-next-stop
1272/// Converts an absolute filename to an escaped ASCII-encoded URI, with the path
1273/// component following Section 3.3. of RFC 2396.
1274/// ## `filename`
1275/// an absolute filename specified in the GLib file
1276///     name encoding, which is the on-disk file name bytes on Unix, and UTF-8
1277///     on Windows
1278/// ## `hostname`
1279/// A UTF-8 encoded hostname, or [`None`] for none.
1280///
1281/// # Returns
1282///
1283/// a newly-allocated string holding the resulting
1284///               URI, or [`None`] on an error.
1285#[doc(alias = "g_filename_to_uri")]
1286pub fn filename_to_uri(
1287    filename: impl AsRef<std::path::Path>,
1288    hostname: Option<&str>,
1289) -> Result<crate::GString, crate::Error> {
1290    unsafe {
1291        let mut error = std::ptr::null_mut();
1292        let ret = ffi::g_filename_to_uri(
1293            filename.as_ref().to_glib_none().0,
1294            hostname.to_glib_none().0,
1295            &mut error,
1296        );
1297        if error.is_null() {
1298            Ok(from_glib_full(ret))
1299        } else {
1300            Err(from_glib_full(error))
1301        }
1302    }
1303}
1304
1305/// Locates the first executable named @program in the user's path, in the
1306/// same way that execvp() would locate it. Returns an allocated string
1307/// with the absolute path name, or [`None`] if the program is not found in
1308/// the path. If @program is already an absolute path, returns a copy of
1309/// @program if @program exists and is executable, and [`None`] otherwise.
1310///
1311/// On Windows, if @program does not have a file type suffix, tries
1312/// with the suffixes .exe, .cmd, .bat and .com, and the suffixes in
1313/// the `PATHEXT` environment variable.
1314///
1315/// On Windows, it looks for the file in the same way as CreateProcess()
1316/// would. This means first in the directory where the executing
1317/// program was loaded from, then in the current directory, then in the
1318/// Windows 32-bit system directory, then in the Windows directory, and
1319/// finally in the directories in the `PATH` environment variable. If
1320/// the program is found, the return value contains the full name
1321/// including the type suffix.
1322/// ## `program`
1323/// a program name in the GLib file name encoding
1324///
1325/// # Returns
1326///
1327/// a newly-allocated
1328///   string with the absolute path, or [`None`]
1329// rustdoc-stripper-ignore-next-stop
1330/// Locates the first executable named @program in the user's path, in the
1331/// same way that execvp() would locate it. Returns an allocated string
1332/// with the absolute path name, or [`None`] if the program is not found in
1333/// the path. If @program is already an absolute path, returns a copy of
1334/// @program if @program exists and is executable, and [`None`] otherwise.
1335///
1336/// On Windows, if @program does not have a file type suffix, tries
1337/// with the suffixes .exe, .cmd, .bat and .com, and the suffixes in
1338/// the `PATHEXT` environment variable.
1339///
1340/// On Windows, it looks for the file in the same way as CreateProcess()
1341/// would. This means first in the directory where the executing
1342/// program was loaded from, then in the current directory, then in the
1343/// Windows 32-bit system directory, then in the Windows directory, and
1344/// finally in the directories in the `PATH` environment variable. If
1345/// the program is found, the return value contains the full name
1346/// including the type suffix.
1347/// ## `program`
1348/// a program name in the GLib file name encoding
1349///
1350/// # Returns
1351///
1352/// a newly-allocated
1353///   string with the absolute path, or [`None`]
1354#[doc(alias = "g_find_program_in_path")]
1355pub fn find_program_in_path(program: impl AsRef<std::path::Path>) -> Option<std::path::PathBuf> {
1356    unsafe {
1357        from_glib_full(ffi::g_find_program_in_path(
1358            program.as_ref().to_glib_none().0,
1359        ))
1360    }
1361}
1362
1363/// Formats a size (for example the size of a file) into a human readable
1364/// string.  Sizes are rounded to the nearest size prefix (kB, MB, GB)
1365/// and are displayed rounded to the nearest tenth. E.g. the file size
1366/// 3292528 bytes will be converted into the string "3.2 MB". The returned string
1367/// is UTF-8, and may use a non-breaking space to separate the number and units,
1368/// to ensure they aren’t separated when line wrapped.
1369///
1370/// The prefix units base is 1000 (i.e. 1 kB is 1000 bytes).
1371///
1372/// This string should be freed with g_free() when not needed any longer.
1373///
1374/// See g_format_size_full() for more options about how the size might be
1375/// formatted.
1376/// ## `size`
1377/// a size in bytes
1378///
1379/// # Returns
1380///
1381/// a newly-allocated formatted string containing
1382///   a human readable file size
1383// rustdoc-stripper-ignore-next-stop
1384/// Formats a size (for example the size of a file) into a human readable
1385/// string.  Sizes are rounded to the nearest size prefix (kB, MB, GB)
1386/// and are displayed rounded to the nearest tenth. E.g. the file size
1387/// 3292528 bytes will be converted into the string "3.2 MB". The returned string
1388/// is UTF-8, and may use a non-breaking space to separate the number and units,
1389/// to ensure they aren’t separated when line wrapped.
1390///
1391/// The prefix units base is 1000 (i.e. 1 kB is 1000 bytes).
1392///
1393/// This string should be freed with g_free() when not needed any longer.
1394///
1395/// See g_format_size_full() for more options about how the size might be
1396/// formatted.
1397/// ## `size`
1398/// a size in bytes
1399///
1400/// # Returns
1401///
1402/// a newly-allocated formatted string containing
1403///   a human readable file size
1404#[doc(alias = "g_format_size")]
1405pub fn format_size(size: u64) -> crate::GString {
1406    unsafe { from_glib_full(ffi::g_format_size(size)) }
1407}
1408
1409/// Formats a size.
1410///
1411/// This function is similar to g_format_size() but allows for flags
1412/// that modify the output. See #GFormatSizeFlags.
1413/// ## `size`
1414/// a size in bytes
1415/// ## `flags`
1416/// #GFormatSizeFlags to modify the output
1417///
1418/// # Returns
1419///
1420/// a newly-allocated formatted string
1421///   containing a human readable file size
1422// rustdoc-stripper-ignore-next-stop
1423/// Formats a size.
1424///
1425/// This function is similar to g_format_size() but allows for flags
1426/// that modify the output. See #GFormatSizeFlags.
1427/// ## `size`
1428/// a size in bytes
1429/// ## `flags`
1430/// #GFormatSizeFlags to modify the output
1431///
1432/// # Returns
1433///
1434/// a newly-allocated formatted string
1435///   containing a human readable file size
1436#[doc(alias = "g_format_size_full")]
1437pub fn format_size_full(size: u64, flags: FormatSizeFlags) -> crate::GString {
1438    unsafe { from_glib_full(ffi::g_format_size_full(size, flags.into_glib())) }
1439}
1440
1441/// Gets a human-readable name for the application, as set by
1442/// g_set_application_name(). This name should be localized if
1443/// possible, and is intended for display to the user.  Contrast with
1444/// g_get_prgname(), which gets a non-localized name. If
1445/// g_set_application_name() has not been called, returns the result of
1446/// g_get_prgname() (which may be [`None`] if g_set_prgname() has also not
1447/// been called).
1448///
1449/// # Returns
1450///
1451/// human-readable application
1452///   name. May return [`None`]
1453// rustdoc-stripper-ignore-next-stop
1454/// Gets a human-readable name for the application, as set by
1455/// g_set_application_name(). This name should be localized if
1456/// possible, and is intended for display to the user.  Contrast with
1457/// g_get_prgname(), which gets a non-localized name. If
1458/// g_set_application_name() has not been called, returns the result of
1459/// g_get_prgname() (which may be [`None`] if g_set_prgname() has also not
1460/// been called).
1461///
1462/// # Returns
1463///
1464/// human-readable application
1465///   name. May return [`None`]
1466#[doc(alias = "g_get_application_name")]
1467#[doc(alias = "get_application_name")]
1468pub fn application_name() -> Option<crate::GString> {
1469    unsafe { from_glib_none(ffi::g_get_application_name()) }
1470}
1471
1472/// Gets the character set for the current locale.
1473///
1474/// # Returns
1475///
1476/// a newly allocated string containing the name
1477///     of the character set. This string must be freed with g_free().
1478// rustdoc-stripper-ignore-next-stop
1479/// Gets the character set for the current locale.
1480///
1481/// # Returns
1482///
1483/// a newly allocated string containing the name
1484///     of the character set. This string must be freed with g_free().
1485#[doc(alias = "g_get_codeset")]
1486#[doc(alias = "get_codeset")]
1487pub fn codeset() -> crate::GString {
1488    unsafe { from_glib_full(ffi::g_get_codeset()) }
1489}
1490
1491/// Obtains the character set used by the console attached to the process,
1492/// which is suitable for printing output to the terminal.
1493///
1494/// Usually this matches the result returned by g_get_charset(), but in
1495/// environments where the locale's character set does not match the encoding
1496/// of the console this function tries to guess a more suitable value instead.
1497///
1498/// On Windows the character set returned by this function is the
1499/// output code page used by the console associated with the calling process.
1500/// If the codepage can't be determined (for example because there is no
1501/// console attached) UTF-8 is assumed.
1502///
1503/// The return value is [`true`] if the locale's encoding is UTF-8, in that
1504/// case you can perhaps avoid calling g_convert().
1505///
1506/// The string returned in @charset is not allocated, and should not be
1507/// freed.
1508///
1509/// # Returns
1510///
1511/// [`true`] if the returned charset is UTF-8
1512///
1513/// ## `charset`
1514/// return location for character set
1515///   name, or [`None`].
1516// rustdoc-stripper-ignore-next-stop
1517/// Obtains the character set used by the console attached to the process,
1518/// which is suitable for printing output to the terminal.
1519///
1520/// Usually this matches the result returned by g_get_charset(), but in
1521/// environments where the locale's character set does not match the encoding
1522/// of the console this function tries to guess a more suitable value instead.
1523///
1524/// On Windows the character set returned by this function is the
1525/// output code page used by the console associated with the calling process.
1526/// If the codepage can't be determined (for example because there is no
1527/// console attached) UTF-8 is assumed.
1528///
1529/// The return value is [`true`] if the locale's encoding is UTF-8, in that
1530/// case you can perhaps avoid calling g_convert().
1531///
1532/// The string returned in @charset is not allocated, and should not be
1533/// freed.
1534///
1535/// # Returns
1536///
1537/// [`true`] if the returned charset is UTF-8
1538///
1539/// ## `charset`
1540/// return location for character set
1541///   name, or [`None`].
1542#[cfg(feature = "v2_62")]
1543#[cfg_attr(docsrs, doc(cfg(feature = "v2_62")))]
1544#[doc(alias = "g_get_console_charset")]
1545#[doc(alias = "get_console_charset")]
1546pub fn console_charset() -> Option<crate::GString> {
1547    unsafe {
1548        let mut charset = std::ptr::null();
1549        let ret = from_glib(ffi::g_get_console_charset(&mut charset));
1550        if ret {
1551            Some(from_glib_none(charset))
1552        } else {
1553            None
1554        }
1555    }
1556}
1557
1558/// Gets the current directory.
1559///
1560/// The returned string should be freed when no longer needed.
1561/// The encoding of the returned string is system defined.
1562/// On Windows, it is always UTF-8.
1563///
1564/// Since GLib 2.40, this function will return the value of the "PWD"
1565/// environment variable if it is set and it happens to be the same as
1566/// the current directory.  This can make a difference in the case that
1567/// the current directory is the target of a symbolic link.
1568///
1569/// # Returns
1570///
1571/// the current directory
1572// rustdoc-stripper-ignore-next-stop
1573/// Gets the current directory.
1574///
1575/// The returned string should be freed when no longer needed.
1576/// The encoding of the returned string is system defined.
1577/// On Windows, it is always UTF-8.
1578///
1579/// Since GLib 2.40, this function will return the value of the "PWD"
1580/// environment variable if it is set and it happens to be the same as
1581/// the current directory.  This can make a difference in the case that
1582/// the current directory is the target of a symbolic link.
1583///
1584/// # Returns
1585///
1586/// the current directory
1587#[doc(alias = "g_get_current_dir")]
1588#[doc(alias = "get_current_dir")]
1589pub fn current_dir() -> std::path::PathBuf {
1590    unsafe { from_glib_full(ffi::g_get_current_dir()) }
1591}
1592
1593/// Gets the list of environment variables for the current process.
1594///
1595/// The list is [`None`] terminated and each item in the list is of the
1596/// form 'NAME=VALUE'.
1597///
1598/// This is equivalent to direct access to the 'environ' global variable,
1599/// except portable.
1600///
1601/// The return value is freshly allocated and it should be freed with
1602/// g_strfreev() when it is no longer needed.
1603///
1604/// # Returns
1605///
1606///
1607///     the list of environment variables
1608// rustdoc-stripper-ignore-next-stop
1609/// Gets the list of environment variables for the current process.
1610///
1611/// The list is [`None`] terminated and each item in the list is of the
1612/// form 'NAME=VALUE'.
1613///
1614/// This is equivalent to direct access to the 'environ' global variable,
1615/// except portable.
1616///
1617/// The return value is freshly allocated and it should be freed with
1618/// g_strfreev() when it is no longer needed.
1619///
1620/// # Returns
1621///
1622///
1623///     the list of environment variables
1624#[doc(alias = "g_get_environ")]
1625#[doc(alias = "get_environ")]
1626pub fn environ() -> Vec<std::ffi::OsString> {
1627    unsafe { FromGlibPtrContainer::from_glib_full(ffi::g_get_environ()) }
1628}
1629
1630/// Gets the current user's home directory.
1631///
1632/// As with most UNIX tools, this function will return the value of the
1633/// `HOME` environment variable if it is set to an existing absolute path
1634/// name, falling back to the `passwd` file in the case that it is unset.
1635///
1636/// If the path given in `HOME` is non-absolute, does not exist, or is
1637/// not a directory, the result is undefined.
1638///
1639/// Before version 2.36 this function would ignore the `HOME` environment
1640/// variable, taking the value from the `passwd` database instead. This was
1641/// changed to increase the compatibility of GLib with other programs (and
1642/// the XDG basedir specification) and to increase testability of programs
1643/// based on GLib (by making it easier to run them from test frameworks).
1644///
1645/// If your program has a strong requirement for either the new or the
1646/// old behaviour (and if you don't wish to increase your GLib
1647/// dependency to ensure that the new behaviour is in effect) then you
1648/// should either directly check the `HOME` environment variable yourself
1649/// or unset it before calling any functions in GLib.
1650///
1651/// # Returns
1652///
1653/// the current user's home directory
1654// rustdoc-stripper-ignore-next-stop
1655/// Gets the current user's home directory.
1656///
1657/// As with most UNIX tools, this function will return the value of the
1658/// `HOME` environment variable if it is set to an existing absolute path
1659/// name, falling back to the `passwd` file in the case that it is unset.
1660///
1661/// If the path given in `HOME` is non-absolute, does not exist, or is
1662/// not a directory, the result is undefined.
1663///
1664/// Before version 2.36 this function would ignore the `HOME` environment
1665/// variable, taking the value from the `passwd` database instead. This was
1666/// changed to increase the compatibility of GLib with other programs (and
1667/// the XDG basedir specification) and to increase testability of programs
1668/// based on GLib (by making it easier to run them from test frameworks).
1669///
1670/// If your program has a strong requirement for either the new or the
1671/// old behaviour (and if you don't wish to increase your GLib
1672/// dependency to ensure that the new behaviour is in effect) then you
1673/// should either directly check the `HOME` environment variable yourself
1674/// or unset it before calling any functions in GLib.
1675///
1676/// # Returns
1677///
1678/// the current user's home directory
1679#[doc(alias = "g_get_home_dir")]
1680#[doc(alias = "get_home_dir")]
1681pub fn home_dir() -> std::path::PathBuf {
1682    unsafe { from_glib_none(ffi::g_get_home_dir()) }
1683}
1684
1685/// Return a name for the machine.
1686///
1687/// The returned name is not necessarily a fully-qualified domain name,
1688/// or even present in DNS or some other name service at all. It need
1689/// not even be unique on your local network or site, but usually it
1690/// is. Callers should not rely on the return value having any specific
1691/// properties like uniqueness for security purposes. Even if the name
1692/// of the machine is changed while an application is running, the
1693/// return value from this function does not change. The returned
1694/// string is owned by GLib and should not be modified or freed. If no
1695/// name can be determined, a default fixed string "localhost" is
1696/// returned.
1697///
1698/// The encoding of the returned string is UTF-8.
1699///
1700/// # Returns
1701///
1702/// the host name of the machine.
1703// rustdoc-stripper-ignore-next-stop
1704/// Return a name for the machine.
1705///
1706/// The returned name is not necessarily a fully-qualified domain name,
1707/// or even present in DNS or some other name service at all. It need
1708/// not even be unique on your local network or site, but usually it
1709/// is. Callers should not rely on the return value having any specific
1710/// properties like uniqueness for security purposes. Even if the name
1711/// of the machine is changed while an application is running, the
1712/// return value from this function does not change. The returned
1713/// string is owned by GLib and should not be modified or freed. If no
1714/// name can be determined, a default fixed string "localhost" is
1715/// returned.
1716///
1717/// The encoding of the returned string is UTF-8.
1718///
1719/// # Returns
1720///
1721/// the host name of the machine.
1722#[doc(alias = "g_get_host_name")]
1723#[doc(alias = "get_host_name")]
1724pub fn host_name() -> crate::GString {
1725    unsafe { from_glib_none(ffi::g_get_host_name()) }
1726}
1727
1728/// Computes a list of applicable locale names, which can be used to
1729/// e.g. construct locale-dependent filenames or search paths. The returned
1730/// list is sorted from most desirable to least desirable and always contains
1731/// the default locale "C".
1732///
1733/// For example, if LANGUAGE=de:en_US, then the returned list is
1734/// "de", "en_US", "en", "C".
1735///
1736/// This function consults the environment variables `LANGUAGE`, `LC_ALL`,
1737/// `LC_MESSAGES` and `LANG` to find the list of locales specified by the
1738/// user.
1739///
1740/// # Returns
1741///
1742/// a [`None`]-terminated array of strings owned by GLib
1743///    that must not be modified or freed.
1744// rustdoc-stripper-ignore-next-stop
1745/// Computes a list of applicable locale names, which can be used to
1746/// e.g. construct locale-dependent filenames or search paths. The returned
1747/// list is sorted from most desirable to least desirable and always contains
1748/// the default locale "C".
1749///
1750/// For example, if LANGUAGE=de:en_US, then the returned list is
1751/// "de", "en_US", "en", "C".
1752///
1753/// This function consults the environment variables `LANGUAGE`, `LC_ALL`,
1754/// `LC_MESSAGES` and `LANG` to find the list of locales specified by the
1755/// user.
1756///
1757/// # Returns
1758///
1759/// a [`None`]-terminated array of strings owned by GLib
1760///    that must not be modified or freed.
1761#[doc(alias = "g_get_language_names")]
1762#[doc(alias = "get_language_names")]
1763pub fn language_names() -> Vec<crate::GString> {
1764    unsafe { FromGlibPtrContainer::from_glib_none(ffi::g_get_language_names()) }
1765}
1766
1767/// Computes a list of applicable locale names with a locale category name,
1768/// which can be used to construct the fallback locale-dependent filenames
1769/// or search paths. The returned list is sorted from most desirable to
1770/// least desirable and always contains the default locale "C".
1771///
1772/// This function consults the environment variables `LANGUAGE`, `LC_ALL`,
1773/// @category_name, and `LANG` to find the list of locales specified by the
1774/// user.
1775///
1776/// g_get_language_names() returns g_get_language_names_with_category("LC_MESSAGES").
1777/// ## `category_name`
1778/// a locale category name
1779///
1780/// # Returns
1781///
1782/// a [`None`]-terminated array of strings owned by
1783///    the thread g_get_language_names_with_category was called from.
1784///    It must not be modified or freed. It must be copied if planned to be used in another thread.
1785// rustdoc-stripper-ignore-next-stop
1786/// Computes a list of applicable locale names with a locale category name,
1787/// which can be used to construct the fallback locale-dependent filenames
1788/// or search paths. The returned list is sorted from most desirable to
1789/// least desirable and always contains the default locale "C".
1790///
1791/// This function consults the environment variables `LANGUAGE`, `LC_ALL`,
1792/// @category_name, and `LANG` to find the list of locales specified by the
1793/// user.
1794///
1795/// g_get_language_names() returns g_get_language_names_with_category("LC_MESSAGES").
1796/// ## `category_name`
1797/// a locale category name
1798///
1799/// # Returns
1800///
1801/// a [`None`]-terminated array of strings owned by
1802///    the thread g_get_language_names_with_category was called from.
1803///    It must not be modified or freed. It must be copied if planned to be used in another thread.
1804#[cfg(feature = "v2_58")]
1805#[cfg_attr(docsrs, doc(cfg(feature = "v2_58")))]
1806#[doc(alias = "g_get_language_names_with_category")]
1807#[doc(alias = "get_language_names_with_category")]
1808pub fn language_names_with_category(category_name: &str) -> Vec<crate::GString> {
1809    unsafe {
1810        FromGlibPtrContainer::from_glib_none(ffi::g_get_language_names_with_category(
1811            category_name.to_glib_none().0,
1812        ))
1813    }
1814}
1815
1816/// Returns a list of derived variants of @locale, which can be used to
1817/// e.g. construct locale-dependent filenames or search paths. The returned
1818/// list is sorted from most desirable to least desirable.
1819/// This function handles territory, charset and extra locale modifiers. See
1820/// [`setlocale(3)`](man:setlocale) for information about locales and their format.
1821///
1822/// @locale itself is guaranteed to be returned in the output.
1823///
1824/// For example, if @locale is `fr_BE`, then the returned list
1825/// is `fr_BE`, `fr`. If @locale is `en_GB.UTF-8@euro`, then the returned list
1826/// is `en_GB.UTF-8@euro`, `en_GB.UTF-8`, `en_GB@euro`, `en_GB`, `en.UTF-8@euro`,
1827/// `en.UTF-8`, `en@euro`, `en`.
1828///
1829/// If you need the list of variants for the current locale,
1830/// use g_get_language_names().
1831/// ## `locale`
1832/// a locale identifier
1833///
1834/// # Returns
1835///
1836/// a newly
1837///   allocated array of newly allocated strings with the locale variants. Free with
1838///   g_strfreev().
1839// rustdoc-stripper-ignore-next-stop
1840/// Returns a list of derived variants of @locale, which can be used to
1841/// e.g. construct locale-dependent filenames or search paths. The returned
1842/// list is sorted from most desirable to least desirable.
1843/// This function handles territory, charset and extra locale modifiers. See
1844/// [`setlocale(3)`](man:setlocale) for information about locales and their format.
1845///
1846/// @locale itself is guaranteed to be returned in the output.
1847///
1848/// For example, if @locale is `fr_BE`, then the returned list
1849/// is `fr_BE`, `fr`. If @locale is `en_GB.UTF-8@euro`, then the returned list
1850/// is `en_GB.UTF-8@euro`, `en_GB.UTF-8`, `en_GB@euro`, `en_GB`, `en.UTF-8@euro`,
1851/// `en.UTF-8`, `en@euro`, `en`.
1852///
1853/// If you need the list of variants for the current locale,
1854/// use g_get_language_names().
1855/// ## `locale`
1856/// a locale identifier
1857///
1858/// # Returns
1859///
1860/// a newly
1861///   allocated array of newly allocated strings with the locale variants. Free with
1862///   g_strfreev().
1863#[doc(alias = "g_get_locale_variants")]
1864#[doc(alias = "get_locale_variants")]
1865pub fn locale_variants(locale: &str) -> Vec<crate::GString> {
1866    unsafe {
1867        FromGlibPtrContainer::from_glib_full(ffi::g_get_locale_variants(locale.to_glib_none().0))
1868    }
1869}
1870
1871/// Queries the system monotonic time in microseconds.
1872///
1873/// The monotonic clock will always increase and doesn’t suffer
1874/// discontinuities when the user (or NTP) changes the system time.  It
1875/// may or may not continue to tick during times where the machine is
1876/// suspended.
1877///
1878/// We try to use the clock that corresponds as closely as possible to
1879/// the passage of time as measured by system calls such as
1880/// [`poll()`](man:poll(2)) but it
1881/// may not always be possible to do this.
1882///
1883/// A more accurate version of this function exists.
1884/// [`monotonic_time_ns()`][crate::monotonic_time_ns()] returns the time in nanoseconds.
1885///
1886/// # Returns
1887///
1888/// the monotonic time, in microseconds
1889// rustdoc-stripper-ignore-next-stop
1890/// Queries the system monotonic time in microseconds.
1891///
1892/// The monotonic clock will always increase and doesn’t suffer
1893/// discontinuities when the user (or NTP) changes the system time.  It
1894/// may or may not continue to tick during times where the machine is
1895/// suspended.
1896///
1897/// We try to use the clock that corresponds as closely as possible to
1898/// the passage of time as measured by system calls such as
1899/// [`poll()`](man:poll(2)) but it
1900/// may not always be possible to do this.
1901///
1902/// A more accurate version of this function exists.
1903/// [`monotonic_time_ns()`][crate::monotonic_time_ns()] returns the time in nanoseconds.
1904///
1905/// # Returns
1906///
1907/// the monotonic time, in microseconds
1908#[doc(alias = "g_get_monotonic_time")]
1909#[doc(alias = "get_monotonic_time")]
1910pub fn monotonic_time() -> i64 {
1911    unsafe { ffi::g_get_monotonic_time() }
1912}
1913
1914/// Queries the system monotonic time in nanoseconds.
1915///
1916/// The monotonic clock will always increase and doesn’t suffer
1917/// discontinuities when the user (or NTP) changes the system time.  It
1918/// may or may not continue to tick during times where the machine is
1919/// suspended.
1920///
1921/// We try to use the clock that corresponds as closely as possible to
1922/// the passage of time as measured by system calls such as
1923/// [`poll()`](man:poll(2)) but it
1924/// may not always be possible to do this.
1925///
1926/// Another version of this function exists.
1927/// [`monotonic_time()`][crate::monotonic_time()] returns the time in microseconds.
1928/// If you want to support older GLib versions, it is an alternative.
1929///
1930/// # Returns
1931///
1932/// the monotonic time, in nanoseconds
1933// rustdoc-stripper-ignore-next-stop
1934/// Queries the system monotonic time in nanoseconds.
1935///
1936/// The monotonic clock will always increase and doesn’t suffer
1937/// discontinuities when the user (or NTP) changes the system time.  It
1938/// may or may not continue to tick during times where the machine is
1939/// suspended.
1940///
1941/// We try to use the clock that corresponds as closely as possible to
1942/// the passage of time as measured by system calls such as
1943/// [`poll()`](man:poll(2)) but it
1944/// may not always be possible to do this.
1945///
1946/// Another version of this function exists.
1947/// [`monotonic_time()`][crate::monotonic_time()] returns the time in microseconds.
1948/// If you want to support older GLib versions, it is an alternative.
1949///
1950/// # Returns
1951///
1952/// the monotonic time, in nanoseconds
1953#[cfg(feature = "v2_88")]
1954#[cfg_attr(docsrs, doc(cfg(feature = "v2_88")))]
1955#[doc(alias = "g_get_monotonic_time_ns")]
1956#[doc(alias = "get_monotonic_time_ns")]
1957pub fn monotonic_time_ns() -> u64 {
1958    unsafe { ffi::g_get_monotonic_time_ns() }
1959}
1960
1961/// Determine the approximate number of threads that the system will
1962/// schedule simultaneously for this process.  This is intended to be
1963/// used as a parameter to g_thread_pool_new() for CPU bound tasks and
1964/// similar cases.
1965///
1966/// # Returns
1967///
1968/// Number of schedulable threads, always greater than 0
1969// rustdoc-stripper-ignore-next-stop
1970/// Determine the approximate number of threads that the system will
1971/// schedule simultaneously for this process.  This is intended to be
1972/// used as a parameter to g_thread_pool_new() for CPU bound tasks and
1973/// similar cases.
1974///
1975/// # Returns
1976///
1977/// Number of schedulable threads, always greater than 0
1978#[doc(alias = "g_get_num_processors")]
1979#[doc(alias = "get_num_processors")]
1980pub fn num_processors() -> u32 {
1981    unsafe { ffi::g_get_num_processors() }
1982}
1983
1984/// Get information about the operating system.
1985///
1986/// On Linux this comes from the `/etc/os-release` file. On other systems, it may
1987/// come from a variety of sources. You can either use the standard key names
1988/// like `G_OS_INFO_KEY_NAME` or pass any UTF-8 string key name. For example,
1989/// `/etc/os-release` provides a number of other less commonly used values that may
1990/// be useful. No key is guaranteed to be provided, so the caller should always
1991/// check if the result is [`None`].
1992/// ## `key_name`
1993/// a key for the OS info being requested, for example `G_OS_INFO_KEY_NAME`.
1994///
1995/// # Returns
1996///
1997/// The associated value for the requested key or [`None`] if
1998///   this information is not provided.
1999// rustdoc-stripper-ignore-next-stop
2000/// Get information about the operating system.
2001///
2002/// On Linux this comes from the `/etc/os-release` file. On other systems, it may
2003/// come from a variety of sources. You can either use the standard key names
2004/// like `G_OS_INFO_KEY_NAME` or pass any UTF-8 string key name. For example,
2005/// `/etc/os-release` provides a number of other less commonly used values that may
2006/// be useful. No key is guaranteed to be provided, so the caller should always
2007/// check if the result is [`None`].
2008/// ## `key_name`
2009/// a key for the OS info being requested, for example `G_OS_INFO_KEY_NAME`.
2010///
2011/// # Returns
2012///
2013/// The associated value for the requested key or [`None`] if
2014///   this information is not provided.
2015#[cfg(feature = "v2_64")]
2016#[cfg_attr(docsrs, doc(cfg(feature = "v2_64")))]
2017#[doc(alias = "g_get_os_info")]
2018#[doc(alias = "get_os_info")]
2019pub fn os_info(key_name: &str) -> Option<crate::GString> {
2020    unsafe { from_glib_full(ffi::g_get_os_info(key_name.to_glib_none().0)) }
2021}
2022
2023/// Gets the real name of the user. This usually comes from the user's
2024/// entry in the `passwd` file. The encoding of the returned string is
2025/// system-defined. (On Windows, it is, however, always UTF-8.) If the
2026/// real user name cannot be determined, the string "Unknown" is
2027/// returned.
2028///
2029/// # Returns
2030///
2031/// the user's real name.
2032// rustdoc-stripper-ignore-next-stop
2033/// Gets the real name of the user. This usually comes from the user's
2034/// entry in the `passwd` file. The encoding of the returned string is
2035/// system-defined. (On Windows, it is, however, always UTF-8.) If the
2036/// real user name cannot be determined, the string "Unknown" is
2037/// returned.
2038///
2039/// # Returns
2040///
2041/// the user's real name.
2042#[doc(alias = "g_get_real_name")]
2043#[doc(alias = "get_real_name")]
2044pub fn real_name() -> std::ffi::OsString {
2045    unsafe { from_glib_none(ffi::g_get_real_name()) }
2046}
2047
2048/// Queries the system wall-clock time.
2049///
2050/// This is equivalent to the UNIX [`gettimeofday()`](man:gettimeofday(2))
2051/// function, but portable.
2052///
2053/// You should only use this call if you are actually interested in the real
2054/// wall-clock time. [`monotonic_time()`][crate::monotonic_time()] is probably more useful for
2055/// measuring intervals.
2056///
2057/// # Returns
2058///
2059/// the number of microseconds since
2060///   [January 1, 1970 UTC](https://en.wikipedia.org/wiki/Unix_time)
2061// rustdoc-stripper-ignore-next-stop
2062/// Queries the system wall-clock time.
2063///
2064/// This is equivalent to the UNIX [`gettimeofday()`](man:gettimeofday(2))
2065/// function, but portable.
2066///
2067/// You should only use this call if you are actually interested in the real
2068/// wall-clock time. [`monotonic_time()`][crate::monotonic_time()] is probably more useful for
2069/// measuring intervals.
2070///
2071/// # Returns
2072///
2073/// the number of microseconds since
2074///   [January 1, 1970 UTC](https://en.wikipedia.org/wiki/Unix_time)
2075#[doc(alias = "g_get_real_time")]
2076#[doc(alias = "get_real_time")]
2077pub fn real_time() -> i64 {
2078    unsafe { ffi::g_get_real_time() }
2079}
2080
2081/// Returns an ordered list of base directories in which to access
2082/// system-wide configuration information.
2083///
2084/// On UNIX platforms this is determined using the mechanisms described
2085/// in the
2086/// [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
2087/// In this case the list of directories retrieved will be `XDG_CONFIG_DIRS`.
2088///
2089/// On Windows it follows XDG Base Directory Specification if `XDG_CONFIG_DIRS` is defined.
2090/// If `XDG_CONFIG_DIRS` is undefined, the directory that contains application
2091/// data for all users is used instead. A typical path is
2092/// `C:\Documents and Settings\All Users\Application Data`.
2093/// This folder is used for application data
2094/// that is not user specific. For example, an application can store
2095/// a spell-check dictionary, a database of clip art, or a log file in the
2096/// FOLDERID_ProgramData folder. This information will not roam and is available
2097/// to anyone using the computer.
2098///
2099/// The return value is cached and modifying it at runtime is not supported, as
2100/// it’s not thread-safe to modify environment variables at runtime.
2101///
2102/// # Returns
2103///
2104///
2105///     a [`None`]-terminated array of strings owned by GLib that must not be
2106///     modified or freed.
2107// rustdoc-stripper-ignore-next-stop
2108/// Returns an ordered list of base directories in which to access
2109/// system-wide configuration information.
2110///
2111/// On UNIX platforms this is determined using the mechanisms described
2112/// in the
2113/// [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
2114/// In this case the list of directories retrieved will be `XDG_CONFIG_DIRS`.
2115///
2116/// On Windows it follows XDG Base Directory Specification if `XDG_CONFIG_DIRS` is defined.
2117/// If `XDG_CONFIG_DIRS` is undefined, the directory that contains application
2118/// data for all users is used instead. A typical path is
2119/// `C:\Documents and Settings\All Users\Application Data`.
2120/// This folder is used for application data
2121/// that is not user specific. For example, an application can store
2122/// a spell-check dictionary, a database of clip art, or a log file in the
2123/// FOLDERID_ProgramData folder. This information will not roam and is available
2124/// to anyone using the computer.
2125///
2126/// The return value is cached and modifying it at runtime is not supported, as
2127/// it’s not thread-safe to modify environment variables at runtime.
2128///
2129/// # Returns
2130///
2131///
2132///     a [`None`]-terminated array of strings owned by GLib that must not be
2133///     modified or freed.
2134#[doc(alias = "g_get_system_config_dirs")]
2135#[doc(alias = "get_system_config_dirs")]
2136pub fn system_config_dirs() -> Vec<std::path::PathBuf> {
2137    unsafe { FromGlibPtrContainer::from_glib_none(ffi::g_get_system_config_dirs()) }
2138}
2139
2140/// Returns an ordered list of base directories in which to access
2141/// system-wide application data.
2142///
2143/// On UNIX platforms this is determined using the mechanisms described
2144/// in the
2145/// [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec)
2146/// In this case the list of directories retrieved will be `XDG_DATA_DIRS`.
2147///
2148/// On Windows it follows XDG Base Directory Specification if `XDG_DATA_DIRS` is defined.
2149/// If `XDG_DATA_DIRS` is undefined,
2150/// the first elements in the list are the Application Data
2151/// and Documents folders for All Users. (These can be determined only
2152/// on Windows 2000 or later and are not present in the list on other
2153/// Windows versions.) See documentation for FOLDERID_ProgramData and
2154/// FOLDERID_PublicDocuments.
2155///
2156/// Then follows the "share" subfolder in the installation folder for
2157/// the package containing the DLL that calls this function, if it can
2158/// be determined.
2159///
2160/// Finally the list contains the "share" subfolder in the installation
2161/// folder for GLib, and in the installation folder for the package the
2162/// application's .exe file belongs to.
2163///
2164/// The installation folders above are determined by looking up the
2165/// folder where the module (DLL or EXE) in question is located. If the
2166/// folder's name is "bin", its parent is used, otherwise the folder
2167/// itself.
2168///
2169/// Note that on Windows the returned list can vary depending on where
2170/// this function is called.
2171///
2172/// The return value is cached and modifying it at runtime is not supported, as
2173/// it’s not thread-safe to modify environment variables at runtime.
2174///
2175/// # Returns
2176///
2177///
2178///     a [`None`]-terminated array of strings owned by GLib that must not be
2179///     modified or freed.
2180// rustdoc-stripper-ignore-next-stop
2181/// Returns an ordered list of base directories in which to access
2182/// system-wide application data.
2183///
2184/// On UNIX platforms this is determined using the mechanisms described
2185/// in the
2186/// [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec)
2187/// In this case the list of directories retrieved will be `XDG_DATA_DIRS`.
2188///
2189/// On Windows it follows XDG Base Directory Specification if `XDG_DATA_DIRS` is defined.
2190/// If `XDG_DATA_DIRS` is undefined,
2191/// the first elements in the list are the Application Data
2192/// and Documents folders for All Users. (These can be determined only
2193/// on Windows 2000 or later and are not present in the list on other
2194/// Windows versions.) See documentation for FOLDERID_ProgramData and
2195/// FOLDERID_PublicDocuments.
2196///
2197/// Then follows the "share" subfolder in the installation folder for
2198/// the package containing the DLL that calls this function, if it can
2199/// be determined.
2200///
2201/// Finally the list contains the "share" subfolder in the installation
2202/// folder for GLib, and in the installation folder for the package the
2203/// application's .exe file belongs to.
2204///
2205/// The installation folders above are determined by looking up the
2206/// folder where the module (DLL or EXE) in question is located. If the
2207/// folder's name is "bin", its parent is used, otherwise the folder
2208/// itself.
2209///
2210/// Note that on Windows the returned list can vary depending on where
2211/// this function is called.
2212///
2213/// The return value is cached and modifying it at runtime is not supported, as
2214/// it’s not thread-safe to modify environment variables at runtime.
2215///
2216/// # Returns
2217///
2218///
2219///     a [`None`]-terminated array of strings owned by GLib that must not be
2220///     modified or freed.
2221#[doc(alias = "g_get_system_data_dirs")]
2222#[doc(alias = "get_system_data_dirs")]
2223pub fn system_data_dirs() -> Vec<std::path::PathBuf> {
2224    unsafe { FromGlibPtrContainer::from_glib_none(ffi::g_get_system_data_dirs()) }
2225}
2226
2227/// Gets the directory to use for temporary files.
2228///
2229/// On UNIX, this is taken from the `TMPDIR` environment variable.
2230/// If the variable is not set, `P_tmpdir` is
2231/// used, as defined by the system C library. Failing that, a
2232/// hard-coded default of "/tmp" is returned.
2233///
2234/// On Windows, the `TEMP` environment variable is used, with the
2235/// root directory of the Windows installation (eg: "C:\") used
2236/// as a default.
2237///
2238/// The encoding of the returned string is system-defined. On Windows,
2239/// it is always UTF-8. The return value is never [`None`] or the empty
2240/// string.
2241///
2242/// # Returns
2243///
2244/// the directory to use for temporary files.
2245// rustdoc-stripper-ignore-next-stop
2246/// Gets the directory to use for temporary files.
2247///
2248/// On UNIX, this is taken from the `TMPDIR` environment variable.
2249/// If the variable is not set, `P_tmpdir` is
2250/// used, as defined by the system C library. Failing that, a
2251/// hard-coded default of "/tmp" is returned.
2252///
2253/// On Windows, the `TEMP` environment variable is used, with the
2254/// root directory of the Windows installation (eg: "C:\") used
2255/// as a default.
2256///
2257/// The encoding of the returned string is system-defined. On Windows,
2258/// it is always UTF-8. The return value is never [`None`] or the empty
2259/// string.
2260///
2261/// # Returns
2262///
2263/// the directory to use for temporary files.
2264#[doc(alias = "g_get_tmp_dir")]
2265#[doc(alias = "get_tmp_dir")]
2266pub fn tmp_dir() -> std::path::PathBuf {
2267    unsafe { from_glib_none(ffi::g_get_tmp_dir()) }
2268}
2269
2270/// Returns a base directory in which to store non-essential, cached
2271/// data specific to particular user.
2272///
2273/// On UNIX platforms this is determined using the mechanisms described
2274/// in the
2275/// [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
2276/// In this case the directory retrieved will be `XDG_CACHE_HOME`.
2277///
2278/// On Windows it follows XDG Base Directory Specification if `XDG_CACHE_HOME` is defined.
2279/// If `XDG_CACHE_HOME` is undefined, the directory that serves as a common
2280/// repository for temporary Internet files is used instead. A typical path is
2281/// `C:\Documents and Settings\username\Local Settings\Temporary Internet Files`.
2282/// See the [documentation for `FOLDERID_InternetCache`](https://docs.microsoft.com/en-us/windows/win32/shell/knownfolderid).
2283///
2284/// The return value is cached and modifying it at runtime is not supported, as
2285/// it’s not thread-safe to modify environment variables at runtime.
2286///
2287/// # Returns
2288///
2289/// a string owned by GLib that
2290///   must not be modified or freed.
2291// rustdoc-stripper-ignore-next-stop
2292/// Returns a base directory in which to store non-essential, cached
2293/// data specific to particular user.
2294///
2295/// On UNIX platforms this is determined using the mechanisms described
2296/// in the
2297/// [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
2298/// In this case the directory retrieved will be `XDG_CACHE_HOME`.
2299///
2300/// On Windows it follows XDG Base Directory Specification if `XDG_CACHE_HOME` is defined.
2301/// If `XDG_CACHE_HOME` is undefined, the directory that serves as a common
2302/// repository for temporary Internet files is used instead. A typical path is
2303/// `C:\Documents and Settings\username\Local Settings\Temporary Internet Files`.
2304/// See the [documentation for `FOLDERID_InternetCache`](https://docs.microsoft.com/en-us/windows/win32/shell/knownfolderid).
2305///
2306/// The return value is cached and modifying it at runtime is not supported, as
2307/// it’s not thread-safe to modify environment variables at runtime.
2308///
2309/// # Returns
2310///
2311/// a string owned by GLib that
2312///   must not be modified or freed.
2313#[doc(alias = "g_get_user_cache_dir")]
2314#[doc(alias = "get_user_cache_dir")]
2315pub fn user_cache_dir() -> std::path::PathBuf {
2316    unsafe { from_glib_none(ffi::g_get_user_cache_dir()) }
2317}
2318
2319/// Returns a base directory in which to store user-specific application
2320/// configuration information such as user preferences and settings.
2321///
2322/// On UNIX platforms this is determined using the mechanisms described
2323/// in the
2324/// [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
2325/// In this case the directory retrieved will be `XDG_CONFIG_HOME`.
2326///
2327/// On Windows it follows XDG Base Directory Specification if `XDG_CONFIG_HOME` is defined.
2328/// If `XDG_CONFIG_HOME` is undefined, the folder to use for local (as opposed
2329/// to roaming) application data is used instead. See the
2330/// [documentation for `FOLDERID_LocalAppData`](https://docs.microsoft.com/en-us/windows/win32/shell/knownfolderid).
2331/// Note that in this case on Windows it will be  the same
2332/// as what g_get_user_data_dir() returns.
2333///
2334/// The return value is cached and modifying it at runtime is not supported, as
2335/// it’s not thread-safe to modify environment variables at runtime.
2336///
2337/// # Returns
2338///
2339/// a string owned by GLib that
2340///   must not be modified or freed.
2341// rustdoc-stripper-ignore-next-stop
2342/// Returns a base directory in which to store user-specific application
2343/// configuration information such as user preferences and settings.
2344///
2345/// On UNIX platforms this is determined using the mechanisms described
2346/// in the
2347/// [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
2348/// In this case the directory retrieved will be `XDG_CONFIG_HOME`.
2349///
2350/// On Windows it follows XDG Base Directory Specification if `XDG_CONFIG_HOME` is defined.
2351/// If `XDG_CONFIG_HOME` is undefined, the folder to use for local (as opposed
2352/// to roaming) application data is used instead. See the
2353/// [documentation for `FOLDERID_LocalAppData`](https://docs.microsoft.com/en-us/windows/win32/shell/knownfolderid).
2354/// Note that in this case on Windows it will be  the same
2355/// as what g_get_user_data_dir() returns.
2356///
2357/// The return value is cached and modifying it at runtime is not supported, as
2358/// it’s not thread-safe to modify environment variables at runtime.
2359///
2360/// # Returns
2361///
2362/// a string owned by GLib that
2363///   must not be modified or freed.
2364#[doc(alias = "g_get_user_config_dir")]
2365#[doc(alias = "get_user_config_dir")]
2366pub fn user_config_dir() -> std::path::PathBuf {
2367    unsafe { from_glib_none(ffi::g_get_user_config_dir()) }
2368}
2369
2370/// Returns a base directory in which to access application data such
2371/// as icons that is customized for a particular user.
2372///
2373/// On UNIX platforms this is determined using the mechanisms described
2374/// in the
2375/// [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
2376/// In this case the directory retrieved will be `XDG_DATA_HOME`.
2377///
2378/// On Windows it follows XDG Base Directory Specification if `XDG_DATA_HOME`
2379/// is defined. If `XDG_DATA_HOME` is undefined, the folder to use for local (as
2380/// opposed to roaming) application data is used instead. See the
2381/// [documentation for `FOLDERID_LocalAppData`](https://docs.microsoft.com/en-us/windows/win32/shell/knownfolderid).
2382/// Note that in this case on Windows it will be the same
2383/// as what g_get_user_config_dir() returns.
2384///
2385/// The return value is cached and modifying it at runtime is not supported, as
2386/// it’s not thread-safe to modify environment variables at runtime.
2387///
2388/// # Returns
2389///
2390/// a string owned by GLib that must
2391///   not be modified or freed.
2392// rustdoc-stripper-ignore-next-stop
2393/// Returns a base directory in which to access application data such
2394/// as icons that is customized for a particular user.
2395///
2396/// On UNIX platforms this is determined using the mechanisms described
2397/// in the
2398/// [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
2399/// In this case the directory retrieved will be `XDG_DATA_HOME`.
2400///
2401/// On Windows it follows XDG Base Directory Specification if `XDG_DATA_HOME`
2402/// is defined. If `XDG_DATA_HOME` is undefined, the folder to use for local (as
2403/// opposed to roaming) application data is used instead. See the
2404/// [documentation for `FOLDERID_LocalAppData`](https://docs.microsoft.com/en-us/windows/win32/shell/knownfolderid).
2405/// Note that in this case on Windows it will be the same
2406/// as what g_get_user_config_dir() returns.
2407///
2408/// The return value is cached and modifying it at runtime is not supported, as
2409/// it’s not thread-safe to modify environment variables at runtime.
2410///
2411/// # Returns
2412///
2413/// a string owned by GLib that must
2414///   not be modified or freed.
2415#[doc(alias = "g_get_user_data_dir")]
2416#[doc(alias = "get_user_data_dir")]
2417pub fn user_data_dir() -> std::path::PathBuf {
2418    unsafe { from_glib_none(ffi::g_get_user_data_dir()) }
2419}
2420
2421/// Gets the user name of the current user. The encoding of the returned
2422/// string is system-defined. On UNIX, it might be the preferred file name
2423/// encoding, or something else, and there is no guarantee that it is even
2424/// consistent on a machine. On Windows, it is always UTF-8.
2425///
2426/// # Returns
2427///
2428/// the user name of the current user.
2429// rustdoc-stripper-ignore-next-stop
2430/// Gets the user name of the current user. The encoding of the returned
2431/// string is system-defined. On UNIX, it might be the preferred file name
2432/// encoding, or something else, and there is no guarantee that it is even
2433/// consistent on a machine. On Windows, it is always UTF-8.
2434///
2435/// # Returns
2436///
2437/// the user name of the current user.
2438#[doc(alias = "g_get_user_name")]
2439#[doc(alias = "get_user_name")]
2440pub fn user_name() -> std::ffi::OsString {
2441    unsafe { from_glib_none(ffi::g_get_user_name()) }
2442}
2443
2444/// Returns a directory that is unique to the current user on the local
2445/// system.
2446///
2447/// This is determined using the mechanisms described
2448/// in the
2449/// [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
2450/// This is the directory
2451/// specified in the `XDG_RUNTIME_DIR` environment variable.
2452/// In the case that this variable is not set, we return the value of
2453/// g_get_user_cache_dir(), after verifying that it exists.
2454///
2455/// The return value is cached and modifying it at runtime is not supported, as
2456/// it’s not thread-safe to modify environment variables at runtime.
2457///
2458/// # Returns
2459///
2460/// a string owned by GLib that must not be
2461///     modified or freed.
2462// rustdoc-stripper-ignore-next-stop
2463/// Returns a directory that is unique to the current user on the local
2464/// system.
2465///
2466/// This is determined using the mechanisms described
2467/// in the
2468/// [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
2469/// This is the directory
2470/// specified in the `XDG_RUNTIME_DIR` environment variable.
2471/// In the case that this variable is not set, we return the value of
2472/// g_get_user_cache_dir(), after verifying that it exists.
2473///
2474/// The return value is cached and modifying it at runtime is not supported, as
2475/// it’s not thread-safe to modify environment variables at runtime.
2476///
2477/// # Returns
2478///
2479/// a string owned by GLib that must not be
2480///     modified or freed.
2481#[doc(alias = "g_get_user_runtime_dir")]
2482#[doc(alias = "get_user_runtime_dir")]
2483pub fn user_runtime_dir() -> std::path::PathBuf {
2484    unsafe { from_glib_none(ffi::g_get_user_runtime_dir()) }
2485}
2486
2487/// Returns the full path of a special directory using its logical id.
2488///
2489/// On UNIX this is done using the XDG special user directories.
2490/// For compatibility with existing practise, [`UserDirectory::DirectoryDesktop`][crate::UserDirectory::DirectoryDesktop]
2491/// falls back to `$HOME/Desktop` when XDG special user directories have
2492/// not been set up.
2493///
2494/// Depending on the platform, the user might be able to change the path
2495/// of the special directory without requiring the session to restart; GLib
2496/// will not reflect any change once the special directories are loaded.
2497/// ## `directory`
2498/// the logical id of special directory
2499///
2500/// # Returns
2501///
2502/// the path to the specified special
2503///   directory, or [`None`] if the logical id was not found. The returned string is
2504///   owned by GLib and should not be modified or freed.
2505// rustdoc-stripper-ignore-next-stop
2506/// Returns the full path of a special directory using its logical id.
2507///
2508/// On UNIX this is done using the XDG special user directories.
2509/// For compatibility with existing practise, [`UserDirectory::DirectoryDesktop`][crate::UserDirectory::DirectoryDesktop]
2510/// falls back to `$HOME/Desktop` when XDG special user directories have
2511/// not been set up.
2512///
2513/// Depending on the platform, the user might be able to change the path
2514/// of the special directory without requiring the session to restart; GLib
2515/// will not reflect any change once the special directories are loaded.
2516/// ## `directory`
2517/// the logical id of special directory
2518///
2519/// # Returns
2520///
2521/// the path to the specified special
2522///   directory, or [`None`] if the logical id was not found. The returned string is
2523///   owned by GLib and should not be modified or freed.
2524#[doc(alias = "g_get_user_special_dir")]
2525#[doc(alias = "get_user_special_dir")]
2526pub fn user_special_dir(directory: UserDirectory) -> Option<std::path::PathBuf> {
2527    unsafe { from_glib_none(ffi::g_get_user_special_dir(directory.into_glib())) }
2528}
2529
2530/// Returns a base directory in which to store state files specific to
2531/// particular user.
2532///
2533/// On UNIX platforms this is determined using the mechanisms described
2534/// in the
2535/// [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
2536/// In this case the directory retrieved will be `XDG_STATE_HOME`.
2537///
2538/// On Windows it follows XDG Base Directory Specification if `XDG_STATE_HOME` is defined.
2539/// If `XDG_STATE_HOME` is undefined, the folder to use for local (as opposed
2540/// to roaming) application data is used instead. See the
2541/// [documentation for `FOLDERID_LocalAppData`](https://docs.microsoft.com/en-us/windows/win32/shell/knownfolderid).
2542/// Note that in this case on Windows it will be the same
2543/// as what g_get_user_data_dir() returns.
2544///
2545/// The return value is cached and modifying it at runtime is not supported, as
2546/// it’s not thread-safe to modify environment variables at runtime.
2547///
2548/// # Returns
2549///
2550/// a string owned by GLib that
2551///   must not be modified or freed.
2552// rustdoc-stripper-ignore-next-stop
2553/// Returns a base directory in which to store state files specific to
2554/// particular user.
2555///
2556/// On UNIX platforms this is determined using the mechanisms described
2557/// in the
2558/// [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
2559/// In this case the directory retrieved will be `XDG_STATE_HOME`.
2560///
2561/// On Windows it follows XDG Base Directory Specification if `XDG_STATE_HOME` is defined.
2562/// If `XDG_STATE_HOME` is undefined, the folder to use for local (as opposed
2563/// to roaming) application data is used instead. See the
2564/// [documentation for `FOLDERID_LocalAppData`](https://docs.microsoft.com/en-us/windows/win32/shell/knownfolderid).
2565/// Note that in this case on Windows it will be the same
2566/// as what g_get_user_data_dir() returns.
2567///
2568/// The return value is cached and modifying it at runtime is not supported, as
2569/// it’s not thread-safe to modify environment variables at runtime.
2570///
2571/// # Returns
2572///
2573/// a string owned by GLib that
2574///   must not be modified or freed.
2575#[cfg(feature = "v2_72")]
2576#[cfg_attr(docsrs, doc(cfg(feature = "v2_72")))]
2577#[doc(alias = "g_get_user_state_dir")]
2578#[doc(alias = "get_user_state_dir")]
2579pub fn user_state_dir() -> std::path::PathBuf {
2580    unsafe { from_glib_none(ffi::g_get_user_state_dir()) }
2581}
2582
2583/// Returns the value of an environment variable.
2584///
2585/// On UNIX, the name and value are byte strings which might or might not
2586/// be in some consistent character set and encoding. On Windows, they are
2587/// in UTF-8.
2588/// On Windows, in case the environment variable's value contains
2589/// references to other environment variables, they are expanded.
2590/// ## `variable`
2591/// the environment variable to get
2592///
2593/// # Returns
2594///
2595/// the value of the environment variable, or [`None`] if
2596///     the environment variable is not found. The returned string
2597///     may be overwritten by the next call to g_getenv(), g_setenv()
2598///     or g_unsetenv().
2599// rustdoc-stripper-ignore-next-stop
2600/// Returns the value of an environment variable.
2601///
2602/// On UNIX, the name and value are byte strings which might or might not
2603/// be in some consistent character set and encoding. On Windows, they are
2604/// in UTF-8.
2605/// On Windows, in case the environment variable's value contains
2606/// references to other environment variables, they are expanded.
2607/// ## `variable`
2608/// the environment variable to get
2609///
2610/// # Returns
2611///
2612/// the value of the environment variable, or [`None`] if
2613///     the environment variable is not found. The returned string
2614///     may be overwritten by the next call to g_getenv(), g_setenv()
2615///     or g_unsetenv().
2616#[doc(alias = "g_getenv")]
2617pub fn getenv(variable: impl AsRef<std::ffi::OsStr>) -> Option<std::ffi::OsString> {
2618    unsafe { from_glib_none(ffi::g_getenv(variable.as_ref().to_glib_none().0)) }
2619}
2620
2621/// Tests if @hostname contains segments with an ASCII-compatible
2622/// encoding of an Internationalized Domain Name. If this returns
2623/// [`true`], you should decode the hostname with g_hostname_to_unicode()
2624/// before displaying it to the user.
2625///
2626/// Note that a hostname might contain a mix of encoded and unencoded
2627/// segments, and so it is possible for g_hostname_is_non_ascii() and
2628/// g_hostname_is_ascii_encoded() to both return [`true`] for a name.
2629/// ## `hostname`
2630/// a hostname
2631///
2632/// # Returns
2633///
2634/// [`true`] if @hostname contains any ASCII-encoded
2635/// segments.
2636// rustdoc-stripper-ignore-next-stop
2637/// Tests if @hostname contains segments with an ASCII-compatible
2638/// encoding of an Internationalized Domain Name. If this returns
2639/// [`true`], you should decode the hostname with g_hostname_to_unicode()
2640/// before displaying it to the user.
2641///
2642/// Note that a hostname might contain a mix of encoded and unencoded
2643/// segments, and so it is possible for g_hostname_is_non_ascii() and
2644/// g_hostname_is_ascii_encoded() to both return [`true`] for a name.
2645/// ## `hostname`
2646/// a hostname
2647///
2648/// # Returns
2649///
2650/// [`true`] if @hostname contains any ASCII-encoded
2651/// segments.
2652#[doc(alias = "g_hostname_is_ascii_encoded")]
2653pub fn hostname_is_ascii_encoded(hostname: &str) -> bool {
2654    unsafe { from_glib(ffi::g_hostname_is_ascii_encoded(hostname.to_glib_none().0)) }
2655}
2656
2657/// Tests if @hostname is the string form of an IPv4 or IPv6 address.
2658/// (Eg, "192.168.0.1".)
2659///
2660/// Since 2.66, IPv6 addresses with a zone-id are accepted (RFC6874).
2661/// ## `hostname`
2662/// a hostname (or IP address in string form)
2663///
2664/// # Returns
2665///
2666/// [`true`] if @hostname is an IP address
2667// rustdoc-stripper-ignore-next-stop
2668/// Tests if @hostname is the string form of an IPv4 or IPv6 address.
2669/// (Eg, "192.168.0.1".)
2670///
2671/// Since 2.66, IPv6 addresses with a zone-id are accepted (RFC6874).
2672/// ## `hostname`
2673/// a hostname (or IP address in string form)
2674///
2675/// # Returns
2676///
2677/// [`true`] if @hostname is an IP address
2678#[doc(alias = "g_hostname_is_ip_address")]
2679pub fn hostname_is_ip_address(hostname: &str) -> bool {
2680    unsafe { from_glib(ffi::g_hostname_is_ip_address(hostname.to_glib_none().0)) }
2681}
2682
2683/// Tests if @hostname contains Unicode characters. If this returns
2684/// [`true`], you need to encode the hostname with g_hostname_to_ascii()
2685/// before using it in non-IDN-aware contexts.
2686///
2687/// Note that a hostname might contain a mix of encoded and unencoded
2688/// segments, and so it is possible for g_hostname_is_non_ascii() and
2689/// g_hostname_is_ascii_encoded() to both return [`true`] for a name.
2690/// ## `hostname`
2691/// a hostname
2692///
2693/// # Returns
2694///
2695/// [`true`] if @hostname contains any non-ASCII characters
2696// rustdoc-stripper-ignore-next-stop
2697/// Tests if @hostname contains Unicode characters. If this returns
2698/// [`true`], you need to encode the hostname with g_hostname_to_ascii()
2699/// before using it in non-IDN-aware contexts.
2700///
2701/// Note that a hostname might contain a mix of encoded and unencoded
2702/// segments, and so it is possible for g_hostname_is_non_ascii() and
2703/// g_hostname_is_ascii_encoded() to both return [`true`] for a name.
2704/// ## `hostname`
2705/// a hostname
2706///
2707/// # Returns
2708///
2709/// [`true`] if @hostname contains any non-ASCII characters
2710#[doc(alias = "g_hostname_is_non_ascii")]
2711pub fn hostname_is_non_ascii(hostname: &str) -> bool {
2712    unsafe { from_glib(ffi::g_hostname_is_non_ascii(hostname.to_glib_none().0)) }
2713}
2714
2715/// Converts @hostname to its canonical ASCII form; an ASCII-only
2716/// string containing no uppercase letters and not ending with a
2717/// trailing dot.
2718/// ## `hostname`
2719/// a valid UTF-8 or ASCII hostname
2720///
2721/// # Returns
2722///
2723/// an ASCII hostname, which must be freed,
2724///    or [`None`] if @hostname is in some way invalid.
2725// rustdoc-stripper-ignore-next-stop
2726/// Converts @hostname to its canonical ASCII form; an ASCII-only
2727/// string containing no uppercase letters and not ending with a
2728/// trailing dot.
2729/// ## `hostname`
2730/// a valid UTF-8 or ASCII hostname
2731///
2732/// # Returns
2733///
2734/// an ASCII hostname, which must be freed,
2735///    or [`None`] if @hostname is in some way invalid.
2736#[doc(alias = "g_hostname_to_ascii")]
2737pub fn hostname_to_ascii(hostname: &str) -> Option<crate::GString> {
2738    unsafe { from_glib_full(ffi::g_hostname_to_ascii(hostname.to_glib_none().0)) }
2739}
2740
2741/// Converts @hostname to its canonical presentation form; a UTF-8
2742/// string in Unicode normalization form C, containing no uppercase
2743/// letters, no forbidden characters, and no ASCII-encoded segments,
2744/// and not ending with a trailing dot.
2745///
2746/// Of course if @hostname is not an internationalized hostname, then
2747/// the canonical presentation form will be entirely ASCII.
2748/// ## `hostname`
2749/// a valid UTF-8 or ASCII hostname
2750///
2751/// # Returns
2752///
2753/// a UTF-8 hostname, which must be freed,
2754///    or [`None`] if @hostname is in some way invalid.
2755// rustdoc-stripper-ignore-next-stop
2756/// Converts @hostname to its canonical presentation form; a UTF-8
2757/// string in Unicode normalization form C, containing no uppercase
2758/// letters, no forbidden characters, and no ASCII-encoded segments,
2759/// and not ending with a trailing dot.
2760///
2761/// Of course if @hostname is not an internationalized hostname, then
2762/// the canonical presentation form will be entirely ASCII.
2763/// ## `hostname`
2764/// a valid UTF-8 or ASCII hostname
2765///
2766/// # Returns
2767///
2768/// a UTF-8 hostname, which must be freed,
2769///    or [`None`] if @hostname is in some way invalid.
2770#[doc(alias = "g_hostname_to_unicode")]
2771pub fn hostname_to_unicode(hostname: &str) -> Option<crate::GString> {
2772    unsafe { from_glib_full(ffi::g_hostname_to_unicode(hostname.to_glib_none().0)) }
2773}
2774
2775/// Gets the names of all variables set in the environment.
2776///
2777/// Programs that want to be portable to Windows should typically use
2778/// this function and g_getenv() instead of using the environ array
2779/// from the C library directly. On Windows, the strings in the environ
2780/// array are in system codepage encoding, while in most of the typical
2781/// use cases for environment variables in GLib-using programs you want
2782/// the UTF-8 encoding that this function and g_getenv() provide.
2783///
2784/// # Returns
2785///
2786///
2787///     a [`None`]-terminated list of strings which must be freed with
2788///     g_strfreev().
2789// rustdoc-stripper-ignore-next-stop
2790/// Gets the names of all variables set in the environment.
2791///
2792/// Programs that want to be portable to Windows should typically use
2793/// this function and g_getenv() instead of using the environ array
2794/// from the C library directly. On Windows, the strings in the environ
2795/// array are in system codepage encoding, while in most of the typical
2796/// use cases for environment variables in GLib-using programs you want
2797/// the UTF-8 encoding that this function and g_getenv() provide.
2798///
2799/// # Returns
2800///
2801///
2802///     a [`None`]-terminated list of strings which must be freed with
2803///     g_strfreev().
2804#[doc(alias = "g_listenv")]
2805pub fn listenv() -> Vec<std::ffi::OsString> {
2806    unsafe { FromGlibPtrContainer::from_glib_full(ffi::g_listenv()) }
2807}
2808
2809/// Returns the currently firing source for this thread.
2810///
2811/// # Returns
2812///
2813/// the currently firing source, or `NULL`
2814///   if none is firing
2815// rustdoc-stripper-ignore-next-stop
2816/// Returns the currently firing source for this thread.
2817///
2818/// # Returns
2819///
2820/// the currently firing source, or `NULL`
2821///   if none is firing
2822#[doc(alias = "g_main_current_source")]
2823pub fn main_current_source() -> Option<Source> {
2824    unsafe { from_glib_none(ffi::g_main_current_source()) }
2825}
2826
2827/// Returns the depth of the stack of calls to
2828/// [`MainContext::dispatch()`][crate::MainContext::dispatch()] on any #GMainContext in the current thread.
2829///
2830/// That is, when called from the top level, it gives `0`. When
2831/// called from within a callback from [`MainContext::iteration()`][crate::MainContext::iteration()]
2832/// (or [`MainLoop::run()`][crate::MainLoop::run()], etc.) it returns `1`. When called from within
2833/// a callback to a recursive call to [`MainContext::iteration()`][crate::MainContext::iteration()],
2834/// it returns `2`. And so forth.
2835///
2836/// This function is useful in a situation like the following:
2837/// Imagine an extremely simple ‘garbage collected’ system.
2838///
2839/// **⚠️ The following code is in c ⚠️**
2840///
2841/// ```c
2842/// static GList *free_list;
2843///
2844/// gpointer
2845/// allocate_memory (gsize size)
2846/// {
2847///   gpointer result = g_malloc (size);
2848///   free_list = g_list_prepend (free_list, result);
2849///   return result;
2850/// }
2851///
2852/// void
2853/// free_allocated_memory (void)
2854/// {
2855///   GList *l;
2856///   for (l = free_list; l; l = l->next);
2857///     g_free (l->data);
2858///   g_list_free (free_list);
2859///   free_list = NULL;
2860///  }
2861///
2862/// [...]
2863///
2864/// while (TRUE);
2865///  {
2866///    g_main_context_iteration (NULL, TRUE);
2867///    free_allocated_memory();
2868///   }
2869/// ```
2870///
2871/// This works from an application, however, if you want to do the same
2872/// thing from a library, it gets more difficult, since you no longer
2873/// control the main loop. You might think you can simply use an idle
2874/// function to make the call to `free_allocated_memory()`, but that
2875/// doesn’t work, since the idle function could be called from a
2876/// recursive callback. This can be fixed by using [`main_depth()`][crate::main_depth()]
2877///
2878/// **⚠️ The following code is in c ⚠️**
2879///
2880/// ```c
2881/// gpointer
2882/// allocate_memory (gsize size)
2883/// {
2884///   FreeListBlock *block = g_new (FreeListBlock, 1);
2885///   block->mem = g_malloc (size);
2886///   block->depth = g_main_depth ();
2887///   free_list = g_list_prepend (free_list, block);
2888///   return block->mem;
2889/// }
2890///
2891/// void
2892/// free_allocated_memory (void)
2893/// {
2894///   GList *l;
2895///
2896///   int depth = g_main_depth ();
2897///   for (l = free_list; l; );
2898///     {
2899///       GList *next = l->next;
2900///       FreeListBlock *block = l->data;
2901///       if (block->depth > depth)
2902///         {
2903///           g_free (block->mem);
2904///           g_free (block);
2905///           free_list = g_list_delete_link (free_list, l);
2906///         }
2907///
2908///       l = next;
2909///     }
2910///   }
2911/// ```
2912///
2913/// There is a temptation to use [`main_depth()`][crate::main_depth()] to solve
2914/// problems with reentrancy. For instance, while waiting for data
2915/// to be received from the network in response to a menu item,
2916/// the menu item might be selected again. It might seem that
2917/// one could make the menu item’s callback return immediately
2918/// and do nothing if [`main_depth()`][crate::main_depth()] returns a value greater than 1.
2919/// However, this should be avoided since the user then sees selecting
2920/// the menu item do nothing. Furthermore, you’ll find yourself adding
2921/// these checks all over your code, since there are doubtless many,
2922/// many things that the user could do. Instead, you can use the
2923/// following techniques:
2924///
2925/// 1. Use `gtk_widget_set_sensitive()` or modal dialogs to prevent
2926///    the user from interacting with elements while the main
2927///    loop is recursing.
2928///
2929/// 2. Avoid main loop recursion in situations where you can’t handle
2930///    arbitrary  callbacks. Instead, structure your code so that you
2931///    simply return to the main loop and then get called again when
2932///    there is more work to do.
2933///
2934/// # Returns
2935///
2936/// the main loop recursion level in the current thread
2937// rustdoc-stripper-ignore-next-stop
2938/// Returns the depth of the stack of calls to
2939/// [`MainContext::dispatch()`][crate::MainContext::dispatch()] on any #GMainContext in the current thread.
2940///
2941/// That is, when called from the top level, it gives `0`. When
2942/// called from within a callback from [`MainContext::iteration()`][crate::MainContext::iteration()]
2943/// (or [`MainLoop::run()`][crate::MainLoop::run()], etc.) it returns `1`. When called from within
2944/// a callback to a recursive call to [`MainContext::iteration()`][crate::MainContext::iteration()],
2945/// it returns `2`. And so forth.
2946///
2947/// This function is useful in a situation like the following:
2948/// Imagine an extremely simple ‘garbage collected’ system.
2949///
2950/// **⚠️ The following code is in c ⚠️**
2951///
2952/// ```c
2953/// static GList *free_list;
2954///
2955/// gpointer
2956/// allocate_memory (gsize size)
2957/// {
2958///   gpointer result = g_malloc (size);
2959///   free_list = g_list_prepend (free_list, result);
2960///   return result;
2961/// }
2962///
2963/// void
2964/// free_allocated_memory (void)
2965/// {
2966///   GList *l;
2967///   for (l = free_list; l; l = l->next);
2968///     g_free (l->data);
2969///   g_list_free (free_list);
2970///   free_list = NULL;
2971///  }
2972///
2973/// [...]
2974///
2975/// while (TRUE);
2976///  {
2977///    g_main_context_iteration (NULL, TRUE);
2978///    free_allocated_memory();
2979///   }
2980/// ```
2981///
2982/// This works from an application, however, if you want to do the same
2983/// thing from a library, it gets more difficult, since you no longer
2984/// control the main loop. You might think you can simply use an idle
2985/// function to make the call to `free_allocated_memory()`, but that
2986/// doesn’t work, since the idle function could be called from a
2987/// recursive callback. This can be fixed by using [`main_depth()`][crate::main_depth()]
2988///
2989/// **⚠️ The following code is in c ⚠️**
2990///
2991/// ```c
2992/// gpointer
2993/// allocate_memory (gsize size)
2994/// {
2995///   FreeListBlock *block = g_new (FreeListBlock, 1);
2996///   block->mem = g_malloc (size);
2997///   block->depth = g_main_depth ();
2998///   free_list = g_list_prepend (free_list, block);
2999///   return block->mem;
3000/// }
3001///
3002/// void
3003/// free_allocated_memory (void)
3004/// {
3005///   GList *l;
3006///
3007///   int depth = g_main_depth ();
3008///   for (l = free_list; l; );
3009///     {
3010///       GList *next = l->next;
3011///       FreeListBlock *block = l->data;
3012///       if (block->depth > depth)
3013///         {
3014///           g_free (block->mem);
3015///           g_free (block);
3016///           free_list = g_list_delete_link (free_list, l);
3017///         }
3018///
3019///       l = next;
3020///     }
3021///   }
3022/// ```
3023///
3024/// There is a temptation to use [`main_depth()`][crate::main_depth()] to solve
3025/// problems with reentrancy. For instance, while waiting for data
3026/// to be received from the network in response to a menu item,
3027/// the menu item might be selected again. It might seem that
3028/// one could make the menu item’s callback return immediately
3029/// and do nothing if [`main_depth()`][crate::main_depth()] returns a value greater than 1.
3030/// However, this should be avoided since the user then sees selecting
3031/// the menu item do nothing. Furthermore, you’ll find yourself adding
3032/// these checks all over your code, since there are doubtless many,
3033/// many things that the user could do. Instead, you can use the
3034/// following techniques:
3035///
3036/// 1. Use `gtk_widget_set_sensitive()` or modal dialogs to prevent
3037///    the user from interacting with elements while the main
3038///    loop is recursing.
3039///
3040/// 2. Avoid main loop recursion in situations where you can’t handle
3041///    arbitrary  callbacks. Instead, structure your code so that you
3042///    simply return to the main loop and then get called again when
3043///    there is more work to do.
3044///
3045/// # Returns
3046///
3047/// the main loop recursion level in the current thread
3048#[doc(alias = "g_main_depth")]
3049pub fn main_depth() -> i32 {
3050    unsafe { ffi::g_main_depth() }
3051}
3052
3053/// Escapes text so that the markup parser will parse it verbatim.
3054/// Less than, greater than, ampersand, etc. are replaced with the
3055/// corresponding entities. This function would typically be used
3056/// when writing out a file to be parsed with the markup parser.
3057///
3058/// Note that this function doesn't protect whitespace and line endings
3059/// from being processed according to the XML rules for normalization
3060/// of line endings and attribute values.
3061///
3062/// Note also that this function will produce character references in
3063/// the range of &#x1; ... &#x1f; for all control sequences
3064/// except for tabstop, newline and carriage return.  The character
3065/// references in this range are not valid XML 1.0, but they are
3066/// valid XML 1.1 and will be accepted by the GMarkup parser.
3067/// ## `text`
3068/// some valid UTF-8 text
3069/// ## `length`
3070/// length of @text in bytes, or -1 if the text is nul-terminated
3071///
3072/// # Returns
3073///
3074/// a newly allocated string with the escaped text
3075// rustdoc-stripper-ignore-next-stop
3076/// Escapes text so that the markup parser will parse it verbatim.
3077/// Less than, greater than, ampersand, etc. are replaced with the
3078/// corresponding entities. This function would typically be used
3079/// when writing out a file to be parsed with the markup parser.
3080///
3081/// Note that this function doesn't protect whitespace and line endings
3082/// from being processed according to the XML rules for normalization
3083/// of line endings and attribute values.
3084///
3085/// Note also that this function will produce character references in
3086/// the range of &#x1; ... &#x1f; for all control sequences
3087/// except for tabstop, newline and carriage return.  The character
3088/// references in this range are not valid XML 1.0, but they are
3089/// valid XML 1.1 and will be accepted by the GMarkup parser.
3090/// ## `text`
3091/// some valid UTF-8 text
3092/// ## `length`
3093/// length of @text in bytes, or -1 if the text is nul-terminated
3094///
3095/// # Returns
3096///
3097/// a newly allocated string with the escaped text
3098#[doc(alias = "g_markup_escape_text")]
3099pub fn markup_escape_text(text: &str) -> crate::GString {
3100    let length = text.len() as _;
3101    unsafe { from_glib_full(ffi::g_markup_escape_text(text.to_glib_none().0, length)) }
3102}
3103
3104/// Create a directory if it doesn't already exist. Create intermediate
3105/// parent directories as needed, too.
3106/// ## `pathname`
3107/// a pathname in the GLib file name encoding
3108/// ## `mode`
3109/// permissions to use for newly created directories
3110///
3111/// # Returns
3112///
3113/// 0 if the directory already exists, or was successfully
3114/// created. Returns -1 if an error occurred, with errno set.
3115// rustdoc-stripper-ignore-next-stop
3116/// Create a directory if it doesn't already exist. Create intermediate
3117/// parent directories as needed, too.
3118/// ## `pathname`
3119/// a pathname in the GLib file name encoding
3120/// ## `mode`
3121/// permissions to use for newly created directories
3122///
3123/// # Returns
3124///
3125/// 0 if the directory already exists, or was successfully
3126/// created. Returns -1 if an error occurred, with errno set.
3127#[doc(alias = "g_mkdir_with_parents")]
3128pub fn mkdir_with_parents(pathname: impl AsRef<std::path::Path>, mode: i32) -> i32 {
3129    unsafe { ffi::g_mkdir_with_parents(pathname.as_ref().to_glib_none().0, mode) }
3130}
3131
3132/// Prompts the user with
3133/// `[E]xit, [H]alt, show [S]tack trace or [P]roceed`.
3134/// This function is intended to be used for debugging use only.
3135/// The following example shows how it can be used together with
3136/// the g_log() functions.
3137///
3138///
3139///
3140/// **⚠️ The following code is in C ⚠️**
3141///
3142/// ```C
3143/// #include <glib.h>
3144///
3145/// static void
3146/// log_handler (const gchar   *log_domain,
3147///              GLogLevelFlags log_level,
3148///              const gchar   *message,
3149///              gpointer       user_data)
3150/// {
3151///   g_log_default_handler (log_domain, log_level, message, user_data);
3152///
3153///   g_on_error_query (MY_PROGRAM_NAME);
3154/// }
3155///
3156/// int
3157/// main (int argc, char *argv[])
3158/// {
3159///   g_log_set_handler (MY_LOG_DOMAIN,
3160///                      G_LOG_LEVEL_WARNING |
3161///                      G_LOG_LEVEL_ERROR |
3162///                      G_LOG_LEVEL_CRITICAL,
3163///                      log_handler,
3164///                      NULL);
3165///   ...
3166/// ```
3167///
3168/// If "[E]xit" is selected, the application terminates with a call
3169/// to _exit(0).
3170///
3171/// If "[S]tack" trace is selected, g_on_error_stack_trace() is called.
3172/// This invokes gdb, which attaches to the current process and shows
3173/// a stack trace. The prompt is then shown again.
3174///
3175/// If "[P]roceed" is selected, the function returns.
3176///
3177/// This function may cause different actions on non-UNIX platforms.
3178///
3179/// On Windows consider using the `G_DEBUGGER` environment
3180/// variable (see [Running GLib Applications](running.html)) and
3181/// calling g_on_error_stack_trace() instead.
3182/// ## `prg_name`
3183/// the program name, needed by gdb for the "[S]tack trace"
3184///     option. If @prg_name is [`None`], g_get_prgname() is called to get
3185///     the program name (which will work correctly if gdk_init() or
3186///     gtk_init() has been called)
3187// rustdoc-stripper-ignore-next-stop
3188/// Prompts the user with
3189/// `[E]xit, [H]alt, show [S]tack trace or [P]roceed`.
3190/// This function is intended to be used for debugging use only.
3191/// The following example shows how it can be used together with
3192/// the g_log() functions.
3193///
3194///
3195///
3196/// **⚠️ The following code is in C ⚠️**
3197///
3198/// ```C
3199/// #include <glib.h>
3200///
3201/// static void
3202/// log_handler (const gchar   *log_domain,
3203///              GLogLevelFlags log_level,
3204///              const gchar   *message,
3205///              gpointer       user_data)
3206/// {
3207///   g_log_default_handler (log_domain, log_level, message, user_data);
3208///
3209///   g_on_error_query (MY_PROGRAM_NAME);
3210/// }
3211///
3212/// int
3213/// main (int argc, char *argv[])
3214/// {
3215///   g_log_set_handler (MY_LOG_DOMAIN,
3216///                      G_LOG_LEVEL_WARNING |
3217///                      G_LOG_LEVEL_ERROR |
3218///                      G_LOG_LEVEL_CRITICAL,
3219///                      log_handler,
3220///                      NULL);
3221///   ...
3222/// ```
3223///
3224/// If "[E]xit" is selected, the application terminates with a call
3225/// to _exit(0).
3226///
3227/// If "[S]tack" trace is selected, g_on_error_stack_trace() is called.
3228/// This invokes gdb, which attaches to the current process and shows
3229/// a stack trace. The prompt is then shown again.
3230///
3231/// If "[P]roceed" is selected, the function returns.
3232///
3233/// This function may cause different actions on non-UNIX platforms.
3234///
3235/// On Windows consider using the `G_DEBUGGER` environment
3236/// variable (see [Running GLib Applications](running.html)) and
3237/// calling g_on_error_stack_trace() instead.
3238/// ## `prg_name`
3239/// the program name, needed by gdb for the "[S]tack trace"
3240///     option. If @prg_name is [`None`], g_get_prgname() is called to get
3241///     the program name (which will work correctly if gdk_init() or
3242///     gtk_init() has been called)
3243#[doc(alias = "g_on_error_query")]
3244pub fn on_error_query(prg_name: &str) {
3245    unsafe {
3246        ffi::g_on_error_query(prg_name.to_glib_none().0);
3247    }
3248}
3249
3250/// Invokes gdb, which attaches to the current process and shows a
3251/// stack trace. Called by g_on_error_query() when the "[S]tack trace"
3252/// option is selected. You can get the current process's program name
3253/// with g_get_prgname(), assuming that you have called gtk_init() or
3254/// gdk_init().
3255///
3256/// This function may cause different actions on non-UNIX platforms.
3257///
3258/// When running on Windows, this function is *not* called by
3259/// g_on_error_query(). If called directly, it will raise an
3260/// exception, which will crash the program. If the `G_DEBUGGER` environment
3261/// variable is set, a debugger will be invoked to attach and
3262/// handle that exception (see [Running GLib Applications](running.html)).
3263/// ## `prg_name`
3264/// the program name, needed by gdb for the
3265///   "[S]tack trace" option, or `NULL` to use a default string
3266// rustdoc-stripper-ignore-next-stop
3267/// Invokes gdb, which attaches to the current process and shows a
3268/// stack trace. Called by g_on_error_query() when the "[S]tack trace"
3269/// option is selected. You can get the current process's program name
3270/// with g_get_prgname(), assuming that you have called gtk_init() or
3271/// gdk_init().
3272///
3273/// This function may cause different actions on non-UNIX platforms.
3274///
3275/// When running on Windows, this function is *not* called by
3276/// g_on_error_query(). If called directly, it will raise an
3277/// exception, which will crash the program. If the `G_DEBUGGER` environment
3278/// variable is set, a debugger will be invoked to attach and
3279/// handle that exception (see [Running GLib Applications](running.html)).
3280/// ## `prg_name`
3281/// the program name, needed by gdb for the
3282///   "[S]tack trace" option, or `NULL` to use a default string
3283#[doc(alias = "g_on_error_stack_trace")]
3284pub fn on_error_stack_trace(prg_name: Option<&str>) {
3285    unsafe {
3286        ffi::g_on_error_stack_trace(prg_name.to_glib_none().0);
3287    }
3288}
3289
3290/// Gets the last component of the filename.
3291///
3292/// If @file_name ends with a directory separator it gets the component
3293/// before the last slash. If @file_name consists only of directory
3294/// separators (and on Windows, possibly a drive letter), a single
3295/// separator is returned. If @file_name is empty, it gets ".".
3296/// ## `file_name`
3297/// the name of the file
3298///
3299/// # Returns
3300///
3301/// a newly allocated string
3302///   containing the last component of the filename
3303// rustdoc-stripper-ignore-next-stop
3304/// Gets the last component of the filename.
3305///
3306/// If @file_name ends with a directory separator it gets the component
3307/// before the last slash. If @file_name consists only of directory
3308/// separators (and on Windows, possibly a drive letter), a single
3309/// separator is returned. If @file_name is empty, it gets ".".
3310/// ## `file_name`
3311/// the name of the file
3312///
3313/// # Returns
3314///
3315/// a newly allocated string
3316///   containing the last component of the filename
3317#[doc(alias = "g_path_get_basename")]
3318#[allow(dead_code)]
3319pub(crate) fn path_get_basename(file_name: impl AsRef<std::path::Path>) -> std::path::PathBuf {
3320    unsafe {
3321        from_glib_full(ffi::g_path_get_basename(
3322            file_name.as_ref().to_glib_none().0,
3323        ))
3324    }
3325}
3326
3327/// Gets the directory components of a file name. For example, the directory
3328/// component of `/usr/bin/test` is `/usr/bin`. The directory component of `/`
3329/// is `/`.
3330///
3331/// If the file name has no directory components "." is returned.
3332/// The returned string should be freed when no longer needed.
3333/// ## `file_name`
3334/// the name of the file
3335///
3336/// # Returns
3337///
3338/// the directory components of the file
3339// rustdoc-stripper-ignore-next-stop
3340/// Gets the directory components of a file name. For example, the directory
3341/// component of `/usr/bin/test` is `/usr/bin`. The directory component of `/`
3342/// is `/`.
3343///
3344/// If the file name has no directory components "." is returned.
3345/// The returned string should be freed when no longer needed.
3346/// ## `file_name`
3347/// the name of the file
3348///
3349/// # Returns
3350///
3351/// the directory components of the file
3352#[doc(alias = "g_path_get_dirname")]
3353#[allow(dead_code)]
3354pub(crate) fn path_get_dirname(file_name: impl AsRef<std::path::Path>) -> std::path::PathBuf {
3355    unsafe { from_glib_full(ffi::g_path_get_dirname(file_name.as_ref().to_glib_none().0)) }
3356}
3357
3358//#[doc(alias = "g_poll")]
3359//pub fn poll(fds: /*Ignored*/&mut PollFD, nfds: u32, timeout: i32) -> i32 {
3360//    unsafe { TODO: call ffi:g_poll() }
3361//}
3362
3363/// Returns a random #gdouble equally distributed over the range [0..1).
3364///
3365/// # Returns
3366///
3367/// a random number
3368// rustdoc-stripper-ignore-next-stop
3369/// Returns a random #gdouble equally distributed over the range [0..1).
3370///
3371/// # Returns
3372///
3373/// a random number
3374#[doc(alias = "g_random_double")]
3375pub fn random_double() -> f64 {
3376    unsafe { ffi::g_random_double() }
3377}
3378
3379/// Returns a random #gdouble equally distributed over the range
3380/// [@begin..@end).
3381/// ## `begin`
3382/// lower closed bound of the interval
3383/// ## `end`
3384/// upper open bound of the interval
3385///
3386/// # Returns
3387///
3388/// a random number
3389// rustdoc-stripper-ignore-next-stop
3390/// Returns a random #gdouble equally distributed over the range
3391/// [@begin..@end).
3392/// ## `begin`
3393/// lower closed bound of the interval
3394/// ## `end`
3395/// upper open bound of the interval
3396///
3397/// # Returns
3398///
3399/// a random number
3400#[doc(alias = "g_random_double_range")]
3401pub fn random_double_range(begin: f64, end: f64) -> f64 {
3402    unsafe { ffi::g_random_double_range(begin, end) }
3403}
3404
3405/// Return a random #guint32 equally distributed over the range
3406/// [0..2^32-1].
3407///
3408/// # Returns
3409///
3410/// a random number
3411// rustdoc-stripper-ignore-next-stop
3412/// Return a random #guint32 equally distributed over the range
3413/// [0..2^32-1].
3414///
3415/// # Returns
3416///
3417/// a random number
3418#[doc(alias = "g_random_int")]
3419pub fn random_int() -> u32 {
3420    unsafe { ffi::g_random_int() }
3421}
3422
3423/// Returns a random #gint32 equally distributed over the range
3424/// [@begin..@end-1].
3425/// ## `begin`
3426/// lower closed bound of the interval
3427/// ## `end`
3428/// upper open bound of the interval
3429///
3430/// # Returns
3431///
3432/// a random number
3433// rustdoc-stripper-ignore-next-stop
3434/// Returns a random #gint32 equally distributed over the range
3435/// [@begin..@end-1].
3436/// ## `begin`
3437/// lower closed bound of the interval
3438/// ## `end`
3439/// upper open bound of the interval
3440///
3441/// # Returns
3442///
3443/// a random number
3444#[doc(alias = "g_random_int_range")]
3445pub fn random_int_range(begin: i32, end: i32) -> i32 {
3446    unsafe { ffi::g_random_int_range(begin, end) }
3447}
3448
3449/// Sets the seed for the global random number generator, which is used
3450/// by the g_random_* functions, to @seed.
3451/// ## `seed`
3452/// a value to reinitialize the global random number generator
3453// rustdoc-stripper-ignore-next-stop
3454/// Sets the seed for the global random number generator, which is used
3455/// by the g_random_* functions, to @seed.
3456/// ## `seed`
3457/// a value to reinitialize the global random number generator
3458#[doc(alias = "g_random_set_seed")]
3459pub fn random_set_seed(seed: u32) {
3460    unsafe {
3461        ffi::g_random_set_seed(seed);
3462    }
3463}
3464
3465/// Resets the cache used for g_get_user_special_dir(), so
3466/// that the latest on-disk version is used. Call this only
3467/// if you just changed the data on disk yourself.
3468///
3469/// Due to thread safety issues this may cause leaking of strings
3470/// that were previously returned from g_get_user_special_dir()
3471/// that can't be freed. We ensure to only leak the data for
3472/// the directories that actually changed value though.
3473// rustdoc-stripper-ignore-next-stop
3474/// Resets the cache used for g_get_user_special_dir(), so
3475/// that the latest on-disk version is used. Call this only
3476/// if you just changed the data on disk yourself.
3477///
3478/// Due to thread safety issues this may cause leaking of strings
3479/// that were previously returned from g_get_user_special_dir()
3480/// that can't be freed. We ensure to only leak the data for
3481/// the directories that actually changed value though.
3482#[doc(alias = "g_reload_user_special_dirs_cache")]
3483pub fn reload_user_special_dirs_cache() {
3484    unsafe {
3485        ffi::g_reload_user_special_dirs_cache();
3486    }
3487}
3488
3489/// Sets a human-readable name for the application. This name should be
3490/// localized if possible, and is intended for display to the user.
3491/// Contrast with g_set_prgname(), which sets a non-localized name.
3492/// g_set_prgname() will be called automatically by gtk_init(),
3493/// but g_set_application_name() will not.
3494///
3495/// Note that for thread safety reasons, this function can only
3496/// be called once.
3497///
3498/// The application name will be used in contexts such as error messages,
3499/// or when displaying an application's name in the task list.
3500/// ## `application_name`
3501/// localized name of the application
3502// rustdoc-stripper-ignore-next-stop
3503/// Sets a human-readable name for the application. This name should be
3504/// localized if possible, and is intended for display to the user.
3505/// Contrast with g_set_prgname(), which sets a non-localized name.
3506/// g_set_prgname() will be called automatically by gtk_init(),
3507/// but g_set_application_name() will not.
3508///
3509/// Note that for thread safety reasons, this function can only
3510/// be called once.
3511///
3512/// The application name will be used in contexts such as error messages,
3513/// or when displaying an application's name in the task list.
3514/// ## `application_name`
3515/// localized name of the application
3516#[doc(alias = "g_set_application_name")]
3517pub fn set_application_name(application_name: &str) {
3518    unsafe {
3519        ffi::g_set_application_name(application_name.to_glib_none().0);
3520    }
3521}
3522
3523/// Sets an environment variable. On UNIX, both the variable's name and
3524/// value can be arbitrary byte strings, except that the variable's name
3525/// cannot contain '='. On Windows, they should be in UTF-8.
3526///
3527/// Note that on some systems, when variables are overwritten, the memory
3528/// used for the previous variables and its value isn't reclaimed.
3529///
3530/// You should be mindful of the fact that environment variable handling
3531/// in UNIX is not thread-safe, and your program may crash if one thread
3532/// calls g_setenv() while another thread is calling getenv(). (And note
3533/// that many functions, such as gettext(), call getenv() internally.)
3534/// This function is only safe to use at the very start of your program,
3535/// before creating any other threads (or creating objects that create
3536/// worker threads of their own).
3537///
3538/// If you need to set up the environment for a child process, you can
3539/// use g_get_environ() to get an environment array, modify that with
3540/// g_environ_setenv() and g_environ_unsetenv(), and then pass that
3541/// array directly to execvpe(), g_spawn_async(), or the like.
3542/// ## `variable`
3543/// the environment variable to set, must not
3544///     contain '='.
3545/// ## `value`
3546/// the value for to set the variable to.
3547/// ## `overwrite`
3548/// whether to change the variable if it already exists.
3549///
3550/// # Returns
3551///
3552/// [`false`] if the environment variable couldn't be set.
3553// rustdoc-stripper-ignore-next-stop
3554/// Sets an environment variable. On UNIX, both the variable's name and
3555/// value can be arbitrary byte strings, except that the variable's name
3556/// cannot contain '='. On Windows, they should be in UTF-8.
3557///
3558/// Note that on some systems, when variables are overwritten, the memory
3559/// used for the previous variables and its value isn't reclaimed.
3560///
3561/// You should be mindful of the fact that environment variable handling
3562/// in UNIX is not thread-safe, and your program may crash if one thread
3563/// calls g_setenv() while another thread is calling getenv(). (And note
3564/// that many functions, such as gettext(), call getenv() internally.)
3565/// This function is only safe to use at the very start of your program,
3566/// before creating any other threads (or creating objects that create
3567/// worker threads of their own).
3568///
3569/// If you need to set up the environment for a child process, you can
3570/// use g_get_environ() to get an environment array, modify that with
3571/// g_environ_setenv() and g_environ_unsetenv(), and then pass that
3572/// array directly to execvpe(), g_spawn_async(), or the like.
3573/// ## `variable`
3574/// the environment variable to set, must not
3575///     contain '='.
3576/// ## `value`
3577/// the value for to set the variable to.
3578/// ## `overwrite`
3579/// whether to change the variable if it already exists.
3580///
3581/// # Returns
3582///
3583/// [`false`] if the environment variable couldn't be set.
3584#[doc(alias = "g_setenv")]
3585pub unsafe fn setenv(
3586    variable: impl AsRef<std::ffi::OsStr>,
3587    value: impl AsRef<std::ffi::OsStr>,
3588    overwrite: bool,
3589) -> Result<(), crate::error::BoolError> {
3590    unsafe {
3591        crate::result_from_gboolean!(
3592            ffi::g_setenv(
3593                variable.as_ref().to_glib_none().0,
3594                value.as_ref().to_glib_none().0,
3595                overwrite.into_glib()
3596            ),
3597            "Failed to set environment variable"
3598        )
3599    }
3600}
3601
3602/// Parses a command line into an argument vector, in much the same way
3603/// the shell would, but without many of the expansions the shell would
3604/// perform (variable expansion, globs, operators, filename expansion,
3605/// etc. are not supported).
3606///
3607/// The results are defined to be the same as those you would get from
3608/// a UNIX98 `/bin/sh`, as long as the input contains none of the
3609/// unsupported shell expansions. If the input does contain such expansions,
3610/// they are passed through literally.
3611///
3612/// Possible errors are those from the `G_SHELL_ERROR` domain.
3613///
3614/// In particular, if @command_line is an empty string (or a string containing
3615/// only whitespace), `G_SHELL_ERROR_EMPTY_STRING` will be returned. It’s
3616/// guaranteed that @argvp will be a non-empty array if this function returns
3617/// successfully.
3618///
3619/// Free the returned vector with g_strfreev().
3620/// ## `command_line`
3621/// command line to parse
3622///
3623/// # Returns
3624///
3625/// [`true`] on success, [`false`] if error set
3626///
3627/// ## `argvp`
3628///
3629///   return location for array of args
3630// rustdoc-stripper-ignore-next-stop
3631/// Parses a command line into an argument vector, in much the same way
3632/// the shell would, but without many of the expansions the shell would
3633/// perform (variable expansion, globs, operators, filename expansion,
3634/// etc. are not supported).
3635///
3636/// The results are defined to be the same as those you would get from
3637/// a UNIX98 `/bin/sh`, as long as the input contains none of the
3638/// unsupported shell expansions. If the input does contain such expansions,
3639/// they are passed through literally.
3640///
3641/// Possible errors are those from the `G_SHELL_ERROR` domain.
3642///
3643/// In particular, if @command_line is an empty string (or a string containing
3644/// only whitespace), `G_SHELL_ERROR_EMPTY_STRING` will be returned. It’s
3645/// guaranteed that @argvp will be a non-empty array if this function returns
3646/// successfully.
3647///
3648/// Free the returned vector with g_strfreev().
3649/// ## `command_line`
3650/// command line to parse
3651///
3652/// # Returns
3653///
3654/// [`true`] on success, [`false`] if error set
3655///
3656/// ## `argvp`
3657///
3658///   return location for array of args
3659#[doc(alias = "g_shell_parse_argv")]
3660pub fn shell_parse_argv(
3661    command_line: impl AsRef<std::ffi::OsStr>,
3662) -> Result<Vec<std::ffi::OsString>, crate::Error> {
3663    unsafe {
3664        let mut argcp = std::mem::MaybeUninit::uninit();
3665        let mut argvp = std::ptr::null_mut();
3666        let mut error = std::ptr::null_mut();
3667        let is_ok = ffi::g_shell_parse_argv(
3668            command_line.as_ref().to_glib_none().0,
3669            argcp.as_mut_ptr(),
3670            &mut argvp,
3671            &mut error,
3672        );
3673        debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
3674        if error.is_null() {
3675            Ok(FromGlibContainer::from_glib_full_num(
3676                argvp,
3677                argcp.assume_init() as _,
3678            ))
3679        } else {
3680            Err(from_glib_full(error))
3681        }
3682    }
3683}
3684
3685/// Quotes a string so that the shell (/bin/sh) will interpret the
3686/// quoted string to mean @unquoted_string.
3687///
3688/// If you pass a filename to the shell, for example, you should first
3689/// quote it with this function.
3690///
3691/// The return value must be freed with g_free().
3692///
3693/// The quoting style used is undefined (single or double quotes may be
3694/// used).
3695/// ## `unquoted_string`
3696/// a literal string
3697///
3698/// # Returns
3699///
3700/// quoted string
3701// rustdoc-stripper-ignore-next-stop
3702/// Quotes a string so that the shell (/bin/sh) will interpret the
3703/// quoted string to mean @unquoted_string.
3704///
3705/// If you pass a filename to the shell, for example, you should first
3706/// quote it with this function.
3707///
3708/// The return value must be freed with g_free().
3709///
3710/// The quoting style used is undefined (single or double quotes may be
3711/// used).
3712/// ## `unquoted_string`
3713/// a literal string
3714///
3715/// # Returns
3716///
3717/// quoted string
3718#[doc(alias = "g_shell_quote")]
3719pub fn shell_quote(unquoted_string: impl AsRef<std::ffi::OsStr>) -> std::ffi::OsString {
3720    unsafe {
3721        from_glib_full(ffi::g_shell_quote(
3722            unquoted_string.as_ref().to_glib_none().0,
3723        ))
3724    }
3725}
3726
3727/// Unquotes a string as the shell (/bin/sh) would.
3728///
3729/// This function only handles quotes; if a string contains file globs,
3730/// arithmetic operators, variables, backticks, redirections, or other
3731/// special-to-the-shell features, the result will be different from the
3732/// result a real shell would produce (the variables, backticks, etc.
3733/// will be passed through literally instead of being expanded).
3734///
3735/// This function is guaranteed to succeed if applied to the result of
3736/// g_shell_quote(). If it fails, it returns [`None`] and sets the
3737/// error.
3738///
3739/// The @quoted_string need not actually contain quoted or escaped text;
3740/// g_shell_unquote() simply goes through the string and unquotes/unescapes
3741/// anything that the shell would. Both single and double quotes are
3742/// handled, as are escapes including escaped newlines.
3743///
3744/// The return value must be freed with g_free().
3745///
3746/// Possible errors are in the `G_SHELL_ERROR` domain.
3747///
3748/// Shell quoting rules are a bit strange. Single quotes preserve the
3749/// literal string exactly. escape sequences are not allowed; not even
3750/// `\'` - if you want a `'` in the quoted text, you have to do something
3751/// like `'foo'\''bar'`. Double quotes allow `$`, **⚠️ The following code is in , `"`, `\`, and ⚠️**
3752///
3753/// ```, `"`, `\`, and
3754/// newline to be escaped with backslash. Otherwise double quotes
3755/// preserve things literally.
3756/// ## `quoted_string`
3757/// shell-quoted string
3758///
3759/// # Returns
3760///
3761/// an unquoted string
3762// rustdoc-stripper-ignore-next-stop
3763/// Unquotes a string as the shell (/bin/sh) would.
3764///
3765/// This function only handles quotes; if a string contains file globs,
3766/// arithmetic operators, variables, backticks, redirections, or other
3767/// special-to-the-shell features, the result will be different from the
3768/// result a real shell would produce (the variables, backticks, etc.
3769/// will be passed through literally instead of being expanded).
3770///
3771/// This function is guaranteed to succeed if applied to the result of
3772/// g_shell_quote(). If it fails, it returns [`None`] and sets the
3773/// error.
3774///
3775/// The @quoted_string need not actually contain quoted or escaped text;
3776/// g_shell_unquote() simply goes through the string and unquotes/unescapes
3777/// anything that the shell would. Both single and double quotes are
3778/// handled, as are escapes including escaped newlines.
3779///
3780/// The return value must be freed with g_free().
3781///
3782/// Possible errors are in the `G_SHELL_ERROR` domain.
3783///
3784/// Shell quoting rules are a bit strange. Single quotes preserve the
3785/// literal string exactly. escape sequences are not allowed; not even
3786/// `\'` - if you want a `'` in the quoted text, you have to do something
3787/// like `'foo'\''bar'`. Double quotes allow `$`, **⚠️ The following code is in , `"`, `\`, and ⚠️**
3788///
3789/// ```, `"`, `\`, and
3790/// newline to be escaped with backslash. Otherwise double quotes
3791/// preserve things literally.
3792/// ## `quoted_string`
3793/// shell-quoted string
3794///
3795/// # Returns
3796///
3797/// an unquoted string
3798#[doc(alias = "g_shell_unquote")]
3799pub fn shell_unquote(
3800    quoted_string: impl AsRef<std::ffi::OsStr>,
3801) -> Result<std::ffi::OsString, crate::Error> {
3802    unsafe {
3803        let mut error = std::ptr::null_mut();
3804        let ret = ffi::g_shell_unquote(quoted_string.as_ref().to_glib_none().0, &mut error);
3805        if error.is_null() {
3806            Ok(from_glib_full(ret))
3807        } else {
3808            Err(from_glib_full(error))
3809        }
3810    }
3811}
3812
3813//#[cfg(feature = "v2_82")]
3814//#[cfg_attr(docsrs, doc(cfg(feature = "v2_82")))]
3815//#[doc(alias = "g_sort_array")]
3816//pub fn sort_array(array: /*Unimplemented*/&[&Basic: Pointer], element_size: usize, compare_func: /*Unimplemented*/FnMut(/*Unimplemented*/Option<Basic: Pointer>, /*Unimplemented*/Option<Basic: Pointer>) -> i32, user_data: /*Unimplemented*/Option<Basic: Pointer>) {
3817//    unsafe { TODO: call ffi:g_sort_array() }
3818//}
3819
3820/// Gets the smallest prime number from a built-in array of primes which
3821/// is larger than @num. This is used within GLib to calculate the optimum
3822/// size of a #GHashTable.
3823///
3824/// The built-in array of primes ranges from 11 to 13845163 such that
3825/// each prime is approximately 1.5-2 times the previous prime.
3826/// ## `num`
3827/// a #guint
3828///
3829/// # Returns
3830///
3831/// the smallest prime number from a built-in array of primes
3832///     which is larger than @num
3833// rustdoc-stripper-ignore-next-stop
3834/// Gets the smallest prime number from a built-in array of primes which
3835/// is larger than @num. This is used within GLib to calculate the optimum
3836/// size of a #GHashTable.
3837///
3838/// The built-in array of primes ranges from 11 to 13845163 such that
3839/// each prime is approximately 1.5-2 times the previous prime.
3840/// ## `num`
3841/// a #guint
3842///
3843/// # Returns
3844///
3845/// the smallest prime number from a built-in array of primes
3846///     which is larger than @num
3847#[doc(alias = "g_spaced_primes_closest")]
3848pub fn spaced_primes_closest(num: u32) -> u32 {
3849    unsafe { ffi::g_spaced_primes_closest(num) }
3850}
3851
3852/// Executes a child program asynchronously.
3853///
3854/// See g_spawn_async_with_pipes_and_fds() for a full description; this function
3855/// simply calls the g_spawn_async_with_pipes() without any pipes, which in turn
3856/// calls g_spawn_async_with_pipes_and_fds().
3857///
3858/// You should call g_spawn_close_pid() on the returned child process
3859/// reference when you don't need it any more.
3860///
3861/// If you are writing a GTK application, and the program you are spawning is a
3862/// graphical application too, then to ensure that the spawned program opens its
3863/// windows on the right screen, you may want to use #GdkAppLaunchContext,
3864/// #GAppLaunchContext, or set the `DISPLAY` environment variable.
3865///
3866/// Note that the returned @child_pid on Windows is a handle to the child
3867/// process and not its identifier. Process handles and process identifiers
3868/// are different concepts on Windows.
3869/// ## `working_directory`
3870/// child's current working
3871///     directory, or [`None`] to inherit parent's
3872/// ## `argv`
3873///
3874///     child's argument vector
3875/// ## `envp`
3876///
3877///     child's environment, or [`None`] to inherit parent's
3878/// ## `flags`
3879/// flags from #GSpawnFlags
3880/// ## `child_setup`
3881/// function to run
3882///     in the child just before `exec()`
3883///
3884/// # Returns
3885///
3886/// [`true`] on success, [`false`] if error is set
3887///
3888/// ## `child_pid`
3889/// return location for child process reference, or [`None`]
3890// rustdoc-stripper-ignore-next-stop
3891/// Executes a child program asynchronously.
3892///
3893/// See g_spawn_async_with_pipes_and_fds() for a full description; this function
3894/// simply calls the g_spawn_async_with_pipes() without any pipes, which in turn
3895/// calls g_spawn_async_with_pipes_and_fds().
3896///
3897/// You should call g_spawn_close_pid() on the returned child process
3898/// reference when you don't need it any more.
3899///
3900/// If you are writing a GTK application, and the program you are spawning is a
3901/// graphical application too, then to ensure that the spawned program opens its
3902/// windows on the right screen, you may want to use #GdkAppLaunchContext,
3903/// #GAppLaunchContext, or set the `DISPLAY` environment variable.
3904///
3905/// Note that the returned @child_pid on Windows is a handle to the child
3906/// process and not its identifier. Process handles and process identifiers
3907/// are different concepts on Windows.
3908/// ## `working_directory`
3909/// child's current working
3910///     directory, or [`None`] to inherit parent's
3911/// ## `argv`
3912///
3913///     child's argument vector
3914/// ## `envp`
3915///
3916///     child's environment, or [`None`] to inherit parent's
3917/// ## `flags`
3918/// flags from #GSpawnFlags
3919/// ## `child_setup`
3920/// function to run
3921///     in the child just before `exec()`
3922///
3923/// # Returns
3924///
3925/// [`true`] on success, [`false`] if error is set
3926///
3927/// ## `child_pid`
3928/// return location for child process reference, or [`None`]
3929#[doc(alias = "g_spawn_async")]
3930pub fn spawn_async(
3931    working_directory: Option<impl AsRef<std::path::Path>>,
3932    argv: &[&std::path::Path],
3933    envp: &[&std::path::Path],
3934    flags: SpawnFlags,
3935    child_setup: Option<Box_<dyn FnOnce() + 'static>>,
3936) -> Result<Pid, crate::Error> {
3937    let child_setup_data: Box_<Option<Box_<dyn FnOnce() + 'static>>> = Box_::new(child_setup);
3938    unsafe extern "C" fn child_setup_func(data: ffi::gpointer) {
3939        unsafe {
3940            let callback = Box_::from_raw(data as *mut Option<Box_<dyn FnOnce() + 'static>>);
3941            let callback = (*callback).expect("cannot get closure...");
3942            callback()
3943        }
3944    }
3945    let child_setup = if child_setup_data.is_some() {
3946        Some(child_setup_func as _)
3947    } else {
3948        None
3949    };
3950    let super_callback0: Box_<Option<Box_<dyn FnOnce() + 'static>>> = child_setup_data;
3951    unsafe {
3952        let mut child_pid = std::mem::MaybeUninit::uninit();
3953        let mut error = std::ptr::null_mut();
3954        let is_ok = ffi::g_spawn_async(
3955            working_directory
3956                .as_ref()
3957                .map(|p| p.as_ref())
3958                .to_glib_none()
3959                .0,
3960            argv.to_glib_none().0,
3961            envp.to_glib_none().0,
3962            flags.into_glib(),
3963            child_setup,
3964            Box_::into_raw(super_callback0) as *mut _,
3965            child_pid.as_mut_ptr(),
3966            &mut error,
3967        );
3968        debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
3969        if error.is_null() {
3970            Ok(from_glib(child_pid.assume_init()))
3971        } else {
3972            Err(from_glib_full(error))
3973        }
3974    }
3975}
3976
3977//#[cfg(feature = "v2_68")]
3978//#[cfg_attr(docsrs, doc(cfg(feature = "v2_68")))]
3979//#[doc(alias = "g_spawn_async_with_pipes_and_fds")]
3980//pub fn spawn_async_with_pipes_and_fds(working_directory: Option<impl AsRef<std::path::Path>>, argv: &[&std::path::Path], envp: &[&std::path::Path], flags: SpawnFlags, child_setup: Option<Box_<dyn FnOnce() + 'static>>, stdin_fd: i32, stdout_fd: i32, stderr_fd: i32, source_fds: &[i32], target_fds: &[i32], n_fds: usize) -> Result<(Pid, i32, i32, i32), crate::Error> {
3981//    unsafe { TODO: call ffi:g_spawn_async_with_pipes_and_fds() }
3982//}
3983
3984/// An old name for g_spawn_check_wait_status(), deprecated because its
3985/// name is misleading.
3986///
3987/// Despite the name of the function, @wait_status must be the wait status
3988/// as returned by g_spawn_sync(), g_subprocess_get_status(), `waitpid()`,
3989/// etc. On Unix platforms, it is incorrect for it to be the exit status
3990/// as passed to `exit()` or returned by g_subprocess_get_exit_status() or
3991/// `WEXITSTATUS()`.
3992///
3993/// # Deprecated since 2.70
3994///
3995/// Use g_spawn_check_wait_status() instead, and check whether your code is conflating wait and exit statuses.
3996/// ## `wait_status`
3997/// A status as returned from g_spawn_sync()
3998///
3999/// # Returns
4000///
4001/// [`true`] if child exited successfully, [`false`] otherwise (and
4002///     @error will be set)
4003// rustdoc-stripper-ignore-next-stop
4004/// An old name for g_spawn_check_wait_status(), deprecated because its
4005/// name is misleading.
4006///
4007/// Despite the name of the function, @wait_status must be the wait status
4008/// as returned by g_spawn_sync(), g_subprocess_get_status(), `waitpid()`,
4009/// etc. On Unix platforms, it is incorrect for it to be the exit status
4010/// as passed to `exit()` or returned by g_subprocess_get_exit_status() or
4011/// `WEXITSTATUS()`.
4012///
4013/// # Deprecated since 2.70
4014///
4015/// Use g_spawn_check_wait_status() instead, and check whether your code is conflating wait and exit statuses.
4016/// ## `wait_status`
4017/// A status as returned from g_spawn_sync()
4018///
4019/// # Returns
4020///
4021/// [`true`] if child exited successfully, [`false`] otherwise (and
4022///     @error will be set)
4023#[cfg_attr(feature = "v2_70", deprecated = "Since 2.70")]
4024#[allow(deprecated)]
4025#[doc(alias = "g_spawn_check_exit_status")]
4026pub fn spawn_check_exit_status(wait_status: i32) -> Result<(), crate::Error> {
4027    unsafe {
4028        let mut error = std::ptr::null_mut();
4029        let is_ok = ffi::g_spawn_check_exit_status(wait_status, &mut error);
4030        debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
4031        if error.is_null() {
4032            Ok(())
4033        } else {
4034            Err(from_glib_full(error))
4035        }
4036    }
4037}
4038
4039/// Set @error if @wait_status indicates the child exited abnormally
4040/// (e.g. with a nonzero exit code, or via a fatal signal).
4041///
4042/// The g_spawn_sync() and g_child_watch_add() family of APIs return the
4043/// status of subprocesses encoded in a platform-specific way.
4044/// On Unix, this is guaranteed to be in the same format waitpid() returns,
4045/// and on Windows it is guaranteed to be the result of GetExitCodeProcess().
4046///
4047/// Prior to the introduction of this function in GLib 2.34, interpreting
4048/// @wait_status required use of platform-specific APIs, which is problematic
4049/// for software using GLib as a cross-platform layer.
4050///
4051/// Additionally, many programs simply want to determine whether or not
4052/// the child exited successfully, and either propagate a #GError or
4053/// print a message to standard error. In that common case, this function
4054/// can be used. Note that the error message in @error will contain
4055/// human-readable information about the wait status.
4056///
4057/// The @domain and @code of @error have special semantics in the case
4058/// where the process has an "exit code", as opposed to being killed by
4059/// a signal. On Unix, this happens if WIFEXITED() would be true of
4060/// @wait_status. On Windows, it is always the case.
4061///
4062/// The special semantics are that the actual exit code will be the
4063/// code set in @error, and the domain will be `G_SPAWN_EXIT_ERROR`.
4064/// This allows you to differentiate between different exit codes.
4065///
4066/// If the process was terminated by some means other than an exit
4067/// status (for example if it was killed by a signal), the domain will be
4068/// `G_SPAWN_ERROR` and the code will be `G_SPAWN_ERROR_FAILED`.
4069///
4070/// This function just offers convenience; you can of course also check
4071/// the available platform via a macro such as `G_OS_UNIX`, and use
4072/// WIFEXITED() and WEXITSTATUS() on @wait_status directly. Do not attempt
4073/// to scan or parse the error message string; it may be translated and/or
4074/// change in future versions of GLib.
4075///
4076/// Prior to version 2.70, g_spawn_check_exit_status() provides the same
4077/// functionality, although under a misleading name.
4078/// ## `wait_status`
4079/// A platform-specific wait status as returned from g_spawn_sync()
4080///
4081/// # Returns
4082///
4083/// [`true`] if child exited successfully, [`false`] otherwise (and
4084///   @error will be set)
4085// rustdoc-stripper-ignore-next-stop
4086/// Set @error if @wait_status indicates the child exited abnormally
4087/// (e.g. with a nonzero exit code, or via a fatal signal).
4088///
4089/// The g_spawn_sync() and g_child_watch_add() family of APIs return the
4090/// status of subprocesses encoded in a platform-specific way.
4091/// On Unix, this is guaranteed to be in the same format waitpid() returns,
4092/// and on Windows it is guaranteed to be the result of GetExitCodeProcess().
4093///
4094/// Prior to the introduction of this function in GLib 2.34, interpreting
4095/// @wait_status required use of platform-specific APIs, which is problematic
4096/// for software using GLib as a cross-platform layer.
4097///
4098/// Additionally, many programs simply want to determine whether or not
4099/// the child exited successfully, and either propagate a #GError or
4100/// print a message to standard error. In that common case, this function
4101/// can be used. Note that the error message in @error will contain
4102/// human-readable information about the wait status.
4103///
4104/// The @domain and @code of @error have special semantics in the case
4105/// where the process has an "exit code", as opposed to being killed by
4106/// a signal. On Unix, this happens if WIFEXITED() would be true of
4107/// @wait_status. On Windows, it is always the case.
4108///
4109/// The special semantics are that the actual exit code will be the
4110/// code set in @error, and the domain will be `G_SPAWN_EXIT_ERROR`.
4111/// This allows you to differentiate between different exit codes.
4112///
4113/// If the process was terminated by some means other than an exit
4114/// status (for example if it was killed by a signal), the domain will be
4115/// `G_SPAWN_ERROR` and the code will be `G_SPAWN_ERROR_FAILED`.
4116///
4117/// This function just offers convenience; you can of course also check
4118/// the available platform via a macro such as `G_OS_UNIX`, and use
4119/// WIFEXITED() and WEXITSTATUS() on @wait_status directly. Do not attempt
4120/// to scan or parse the error message string; it may be translated and/or
4121/// change in future versions of GLib.
4122///
4123/// Prior to version 2.70, g_spawn_check_exit_status() provides the same
4124/// functionality, although under a misleading name.
4125/// ## `wait_status`
4126/// A platform-specific wait status as returned from g_spawn_sync()
4127///
4128/// # Returns
4129///
4130/// [`true`] if child exited successfully, [`false`] otherwise (and
4131///   @error will be set)
4132#[cfg(feature = "v2_70")]
4133#[cfg_attr(docsrs, doc(cfg(feature = "v2_70")))]
4134#[doc(alias = "g_spawn_check_wait_status")]
4135pub fn spawn_check_wait_status(wait_status: i32) -> Result<(), crate::Error> {
4136    unsafe {
4137        let mut error = std::ptr::null_mut();
4138        let is_ok = ffi::g_spawn_check_wait_status(wait_status, &mut error);
4139        debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
4140        if error.is_null() {
4141            Ok(())
4142        } else {
4143            Err(from_glib_full(error))
4144        }
4145    }
4146}
4147
4148/// A simple version of g_spawn_async() that parses a command line with
4149/// g_shell_parse_argv() and passes it to g_spawn_async().
4150///
4151/// Runs a command line in the background. Unlike g_spawn_async(), the
4152/// [`SpawnFlags::SEARCH_PATH`][crate::SpawnFlags::SEARCH_PATH] flag is enabled, other flags are not. Note
4153/// that [`SpawnFlags::SEARCH_PATH`][crate::SpawnFlags::SEARCH_PATH] can have security implications, so
4154/// consider using g_spawn_async() directly if appropriate. Possible
4155/// errors are those from g_shell_parse_argv() and g_spawn_async().
4156///
4157/// The same concerns on Windows apply as for g_spawn_command_line_sync().
4158/// ## `command_line`
4159/// a command line
4160///
4161/// # Returns
4162///
4163/// [`true`] on success, [`false`] if error is set
4164// rustdoc-stripper-ignore-next-stop
4165/// A simple version of g_spawn_async() that parses a command line with
4166/// g_shell_parse_argv() and passes it to g_spawn_async().
4167///
4168/// Runs a command line in the background. Unlike g_spawn_async(), the
4169/// [`SpawnFlags::SEARCH_PATH`][crate::SpawnFlags::SEARCH_PATH] flag is enabled, other flags are not. Note
4170/// that [`SpawnFlags::SEARCH_PATH`][crate::SpawnFlags::SEARCH_PATH] can have security implications, so
4171/// consider using g_spawn_async() directly if appropriate. Possible
4172/// errors are those from g_shell_parse_argv() and g_spawn_async().
4173///
4174/// The same concerns on Windows apply as for g_spawn_command_line_sync().
4175/// ## `command_line`
4176/// a command line
4177///
4178/// # Returns
4179///
4180/// [`true`] on success, [`false`] if error is set
4181#[cfg(unix)]
4182#[cfg_attr(docsrs, doc(cfg(unix)))]
4183#[doc(alias = "g_spawn_command_line_async")]
4184pub fn spawn_command_line_async(
4185    command_line: impl AsRef<std::ffi::OsStr>,
4186) -> Result<(), crate::Error> {
4187    unsafe {
4188        let mut error = std::ptr::null_mut();
4189        let is_ok =
4190            ffi::g_spawn_command_line_async(command_line.as_ref().to_glib_none().0, &mut error);
4191        debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
4192        if error.is_null() {
4193            Ok(())
4194        } else {
4195            Err(from_glib_full(error))
4196        }
4197    }
4198}
4199
4200//#[doc(alias = "g_spawn_command_line_sync")]
4201//pub fn spawn_command_line_sync(command_line: impl AsRef<std::path::Path>, standard_output: Vec<u8>, standard_error: Vec<u8>) -> Result<i32, crate::Error> {
4202//    unsafe { TODO: call ffi:g_spawn_command_line_sync() }
4203//}
4204
4205//#[doc(alias = "g_spawn_sync")]
4206//pub fn spawn_sync(working_directory: Option<impl AsRef<std::path::Path>>, argv: &[&std::path::Path], envp: &[&std::path::Path], flags: SpawnFlags, child_setup: Option<&mut dyn FnMut()>, standard_output: Vec<u8>, standard_error: Vec<u8>) -> Result<i32, crate::Error> {
4207//    unsafe { TODO: call ffi:g_spawn_sync() }
4208//}
4209
4210//#[doc(alias = "g_stat")]
4211//pub fn stat(filename: impl AsRef<std::path::Path>, buf: /*Ignored*/&mut StatBuf) -> i32 {
4212//    unsafe { TODO: call ffi:g_stat() }
4213//}
4214
4215/// A wrapper for the POSIX unlink() function. The unlink() function
4216/// deletes a name from the filesystem. If this was the last link to the
4217/// file and no processes have it opened, the diskspace occupied by the
4218/// file is freed.
4219///
4220/// See your C library manual for more details about unlink(). Note
4221/// that on Windows, it is in general not possible to delete files that
4222/// are open to some process, or mapped into memory.
4223/// ## `filename`
4224/// a pathname in the GLib file name encoding
4225///     (UTF-8 on Windows)
4226///
4227/// # Returns
4228///
4229/// 0 if the name was successfully deleted, -1 if an error
4230///    occurred
4231// rustdoc-stripper-ignore-next-stop
4232/// A wrapper for the POSIX unlink() function. The unlink() function
4233/// deletes a name from the filesystem. If this was the last link to the
4234/// file and no processes have it opened, the diskspace occupied by the
4235/// file is freed.
4236///
4237/// See your C library manual for more details about unlink(). Note
4238/// that on Windows, it is in general not possible to delete files that
4239/// are open to some process, or mapped into memory.
4240/// ## `filename`
4241/// a pathname in the GLib file name encoding
4242///     (UTF-8 on Windows)
4243///
4244/// # Returns
4245///
4246/// 0 if the name was successfully deleted, -1 if an error
4247///    occurred
4248#[doc(alias = "g_unlink")]
4249pub fn unlink(filename: impl AsRef<std::path::Path>) -> i32 {
4250    unsafe { ffi::g_unlink(filename.as_ref().to_glib_none().0) }
4251}
4252
4253/// Removes an environment variable from the environment.
4254///
4255/// Note that on some systems, when variables are overwritten, the
4256/// memory used for the previous variables and its value isn't reclaimed.
4257///
4258/// You should be mindful of the fact that environment variable handling
4259/// in UNIX is not thread-safe, and your program may crash if one thread
4260/// calls g_unsetenv() while another thread is calling getenv(). (And note
4261/// that many functions, such as gettext(), call getenv() internally.) This
4262/// function is only safe to use at the very start of your program, before
4263/// creating any other threads (or creating objects that create worker
4264/// threads of their own).
4265///
4266/// If you need to set up the environment for a child process, you can
4267/// use g_get_environ() to get an environment array, modify that with
4268/// g_environ_setenv() and g_environ_unsetenv(), and then pass that
4269/// array directly to execvpe(), g_spawn_async(), or the like.
4270/// ## `variable`
4271/// the environment variable to remove, must
4272///     not contain '='
4273// rustdoc-stripper-ignore-next-stop
4274/// Removes an environment variable from the environment.
4275///
4276/// Note that on some systems, when variables are overwritten, the
4277/// memory used for the previous variables and its value isn't reclaimed.
4278///
4279/// You should be mindful of the fact that environment variable handling
4280/// in UNIX is not thread-safe, and your program may crash if one thread
4281/// calls g_unsetenv() while another thread is calling getenv(). (And note
4282/// that many functions, such as gettext(), call getenv() internally.) This
4283/// function is only safe to use at the very start of your program, before
4284/// creating any other threads (or creating objects that create worker
4285/// threads of their own).
4286///
4287/// If you need to set up the environment for a child process, you can
4288/// use g_get_environ() to get an environment array, modify that with
4289/// g_environ_setenv() and g_environ_unsetenv(), and then pass that
4290/// array directly to execvpe(), g_spawn_async(), or the like.
4291/// ## `variable`
4292/// the environment variable to remove, must
4293///     not contain '='
4294#[doc(alias = "g_unsetenv")]
4295pub unsafe fn unsetenv(variable: impl AsRef<std::ffi::OsStr>) {
4296    unsafe {
4297        ffi::g_unsetenv(variable.as_ref().to_glib_none().0);
4298    }
4299}
4300
4301/// Pauses the current thread for the given number of microseconds.
4302///
4303/// There are 1 million microseconds per second (represented by the
4304/// `G_USEC_PER_SEC` macro). g_usleep() may have limited precision,
4305/// depending on hardware and operating system; don't rely on the exact
4306/// length of the sleep.
4307/// ## `microseconds`
4308/// number of microseconds to pause
4309// rustdoc-stripper-ignore-next-stop
4310/// Pauses the current thread for the given number of microseconds.
4311///
4312/// There are 1 million microseconds per second (represented by the
4313/// `G_USEC_PER_SEC` macro). g_usleep() may have limited precision,
4314/// depending on hardware and operating system; don't rely on the exact
4315/// length of the sleep.
4316/// ## `microseconds`
4317/// number of microseconds to pause
4318#[doc(alias = "g_usleep")]
4319pub fn usleep(microseconds: libc::c_ulong) {
4320    unsafe {
4321        ffi::g_usleep(microseconds);
4322    }
4323}
4324
4325/// Parses the string @str and verify if it is a UUID.
4326///
4327/// The function accepts the following syntax:
4328///
4329/// - simple forms (e.g. `f81d4fae-7dec-11d0-a765-00a0c91e6bf6`)
4330///
4331/// Note that hyphens are required within the UUID string itself,
4332/// as per the aforementioned RFC.
4333/// ## `str`
4334/// a string representing a UUID
4335///
4336/// # Returns
4337///
4338/// [`true`] if @str is a valid UUID, [`false`] otherwise.
4339// rustdoc-stripper-ignore-next-stop
4340/// Parses the string @str and verify if it is a UUID.
4341///
4342/// The function accepts the following syntax:
4343///
4344/// - simple forms (e.g. `f81d4fae-7dec-11d0-a765-00a0c91e6bf6`)
4345///
4346/// Note that hyphens are required within the UUID string itself,
4347/// as per the aforementioned RFC.
4348/// ## `str`
4349/// a string representing a UUID
4350///
4351/// # Returns
4352///
4353/// [`true`] if @str is a valid UUID, [`false`] otherwise.
4354#[doc(alias = "g_uuid_string_is_valid")]
4355pub fn uuid_string_is_valid(str: &str) -> bool {
4356    unsafe { from_glib(ffi::g_uuid_string_is_valid(str.to_glib_none().0)) }
4357}
4358
4359/// Generates a random UUID (RFC 4122 version 4) as a string. It has the same
4360/// randomness guarantees as #GRand, so must not be used for cryptographic
4361/// purposes such as key generation, nonces, salts or one-time pads.
4362///
4363/// # Returns
4364///
4365/// A string that should be freed with g_free().
4366// rustdoc-stripper-ignore-next-stop
4367/// Generates a random UUID (RFC 4122 version 4) as a string. It has the same
4368/// randomness guarantees as #GRand, so must not be used for cryptographic
4369/// purposes such as key generation, nonces, salts or one-time pads.
4370///
4371/// # Returns
4372///
4373/// A string that should be freed with g_free().
4374#[doc(alias = "g_uuid_string_random")]
4375pub fn uuid_string_random() -> crate::GString {
4376    unsafe { from_glib_full(ffi::g_uuid_string_random()) }
4377}