1#[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#[doc(alias = "g_access")]
15pub fn access(filename: impl AsRef<std::path::Path>, mode: i32) -> i32 {
16 unsafe { ffi::g_access(filename.as_ref().to_glib_none().0, mode) }
17}
18
19#[doc(alias = "g_base64_decode")]
20pub fn base64_decode(text: &str) -> Vec<u8> {
21 unsafe {
22 let mut out_len = std::mem::MaybeUninit::uninit();
23 let ret = FromGlibContainer::from_glib_full_num(
24 ffi::g_base64_decode(text.to_glib_none().0, out_len.as_mut_ptr()),
25 out_len.assume_init() as _,
26 );
27 ret
28 }
29}
30
31#[doc(alias = "g_base64_encode")]
42pub fn base64_encode(data: &[u8]) -> crate::GString {
43 let len = data.len() as _;
44 unsafe { from_glib_full(ffi::g_base64_encode(data.to_glib_none().0, len)) }
45}
46
47#[doc(alias = "glib_check_version")]
58pub fn check_version(
59 required_major: u32,
60 required_minor: u32,
61 required_micro: u32,
62) -> Option<crate::GString> {
63 unsafe {
64 from_glib_none(ffi::glib_check_version(
65 required_major,
66 required_minor,
67 required_micro,
68 ))
69 }
70}
71
72#[doc(alias = "g_compute_checksum_for_bytes")]
73pub fn compute_checksum_for_bytes(
74 checksum_type: ChecksumType,
75 data: &Bytes,
76) -> Option<crate::GString> {
77 unsafe {
78 from_glib_full(ffi::g_compute_checksum_for_bytes(
79 checksum_type.into_glib(),
80 data.to_glib_none().0,
81 ))
82 }
83}
84
85#[doc(alias = "g_compute_checksum_for_data")]
86pub fn compute_checksum_for_data(
87 checksum_type: ChecksumType,
88 data: &[u8],
89) -> Option<crate::GString> {
90 let length = data.len() as _;
91 unsafe {
92 from_glib_full(ffi::g_compute_checksum_for_data(
93 checksum_type.into_glib(),
94 data.to_glib_none().0,
95 length,
96 ))
97 }
98}
99
100#[doc(alias = "g_compute_hmac_for_bytes")]
101pub fn compute_hmac_for_bytes(
102 digest_type: ChecksumType,
103 key: &Bytes,
104 data: &Bytes,
105) -> crate::GString {
106 unsafe {
107 from_glib_full(ffi::g_compute_hmac_for_bytes(
108 digest_type.into_glib(),
109 key.to_glib_none().0,
110 data.to_glib_none().0,
111 ))
112 }
113}
114
115#[doc(alias = "g_compute_hmac_for_data")]
116pub fn compute_hmac_for_data(digest_type: ChecksumType, key: &[u8], data: &[u8]) -> crate::GString {
117 let key_len = key.len() as _;
118 let length = data.len() as _;
119 unsafe {
120 from_glib_full(ffi::g_compute_hmac_for_data(
121 digest_type.into_glib(),
122 key.to_glib_none().0,
123 key_len,
124 data.to_glib_none().0,
125 length,
126 ))
127 }
128}
129
130#[doc(alias = "g_dcgettext")]
131pub fn dcgettext(domain: Option<&str>, msgid: &str, category: i32) -> crate::GString {
132 unsafe {
133 from_glib_none(ffi::g_dcgettext(
134 domain.to_glib_none().0,
135 msgid.to_glib_none().0,
136 category,
137 ))
138 }
139}
140
141#[doc(alias = "g_dgettext")]
142pub fn dgettext(domain: Option<&str>, msgid: &str) -> crate::GString {
143 unsafe {
144 from_glib_none(ffi::g_dgettext(
145 domain.to_glib_none().0,
146 msgid.to_glib_none().0,
147 ))
148 }
149}
150
151#[doc(alias = "g_dngettext")]
152pub fn dngettext(
153 domain: Option<&str>,
154 msgid: &str,
155 msgid_plural: &str,
156 n: libc::c_ulong,
157) -> crate::GString {
158 unsafe {
159 from_glib_none(ffi::g_dngettext(
160 domain.to_glib_none().0,
161 msgid.to_glib_none().0,
162 msgid_plural.to_glib_none().0,
163 n,
164 ))
165 }
166}
167
168#[doc(alias = "g_dpgettext")]
169pub fn dpgettext(domain: Option<&str>, msgctxtid: &str, msgidoffset: usize) -> crate::GString {
170 unsafe {
171 from_glib_none(ffi::g_dpgettext(
172 domain.to_glib_none().0,
173 msgctxtid.to_glib_none().0,
174 msgidoffset,
175 ))
176 }
177}
178
179#[doc(alias = "g_dpgettext2")]
180pub fn dpgettext2(domain: Option<&str>, context: &str, msgid: &str) -> crate::GString {
181 unsafe {
182 from_glib_none(ffi::g_dpgettext2(
183 domain.to_glib_none().0,
184 context.to_glib_none().0,
185 msgid.to_glib_none().0,
186 ))
187 }
188}
189
190#[doc(alias = "g_file_set_contents")]
191pub fn file_set_contents(
192 filename: impl AsRef<std::path::Path>,
193 contents: &[u8],
194) -> Result<(), crate::Error> {
195 let length = contents.len() as _;
196 unsafe {
197 let mut error = std::ptr::null_mut();
198 let is_ok = ffi::g_file_set_contents(
199 filename.as_ref().to_glib_none().0,
200 contents.to_glib_none().0,
201 length,
202 &mut error,
203 );
204 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
205 if error.is_null() {
206 Ok(())
207 } else {
208 Err(from_glib_full(error))
209 }
210 }
211}
212
213#[cfg(feature = "v2_66")]
214#[cfg_attr(docsrs, doc(cfg(feature = "v2_66")))]
215#[doc(alias = "g_file_set_contents_full")]
216pub fn file_set_contents_full(
217 filename: impl AsRef<std::path::Path>,
218 contents: &[u8],
219 flags: FileSetContentsFlags,
220 mode: i32,
221) -> Result<(), crate::Error> {
222 let length = contents.len() as _;
223 unsafe {
224 let mut error = std::ptr::null_mut();
225 let is_ok = ffi::g_file_set_contents_full(
226 filename.as_ref().to_glib_none().0,
227 contents.to_glib_none().0,
228 length,
229 flags.into_glib(),
230 mode,
231 &mut error,
232 );
233 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
234 if error.is_null() {
235 Ok(())
236 } else {
237 Err(from_glib_full(error))
238 }
239 }
240}
241
242#[doc(alias = "g_file_test")]
243#[allow(dead_code)]
244pub(crate) fn file_test(filename: impl AsRef<std::path::Path>, test: FileTest) -> bool {
245 unsafe {
246 from_glib(ffi::g_file_test(
247 filename.as_ref().to_glib_none().0,
248 test.into_glib(),
249 ))
250 }
251}
252
253#[doc(alias = "g_filename_display_basename")]
254pub fn filename_display_basename(filename: impl AsRef<std::path::Path>) -> crate::GString {
255 unsafe {
256 from_glib_full(ffi::g_filename_display_basename(
257 filename.as_ref().to_glib_none().0,
258 ))
259 }
260}
261
262#[doc(alias = "g_filename_display_name")]
263pub fn filename_display_name(filename: impl AsRef<std::path::Path>) -> crate::GString {
264 unsafe {
265 from_glib_full(ffi::g_filename_display_name(
266 filename.as_ref().to_glib_none().0,
267 ))
268 }
269}
270
271#[doc(alias = "g_filename_from_uri")]
272pub fn filename_from_uri(
273 uri: &str,
274) -> Result<(std::path::PathBuf, Option<crate::GString>), crate::Error> {
275 unsafe {
276 let mut hostname = std::ptr::null_mut();
277 let mut error = std::ptr::null_mut();
278 let ret = ffi::g_filename_from_uri(uri.to_glib_none().0, &mut hostname, &mut error);
279 if error.is_null() {
280 Ok((from_glib_full(ret), from_glib_full(hostname)))
281 } else {
282 Err(from_glib_full(error))
283 }
284 }
285}
286
287#[doc(alias = "g_filename_to_uri")]
288pub fn filename_to_uri(
289 filename: impl AsRef<std::path::Path>,
290 hostname: Option<&str>,
291) -> Result<crate::GString, crate::Error> {
292 unsafe {
293 let mut error = std::ptr::null_mut();
294 let ret = ffi::g_filename_to_uri(
295 filename.as_ref().to_glib_none().0,
296 hostname.to_glib_none().0,
297 &mut error,
298 );
299 if error.is_null() {
300 Ok(from_glib_full(ret))
301 } else {
302 Err(from_glib_full(error))
303 }
304 }
305}
306
307#[doc(alias = "g_find_program_in_path")]
308pub fn find_program_in_path(program: impl AsRef<std::path::Path>) -> Option<std::path::PathBuf> {
309 unsafe {
310 from_glib_full(ffi::g_find_program_in_path(
311 program.as_ref().to_glib_none().0,
312 ))
313 }
314}
315
316#[doc(alias = "g_format_size")]
317pub fn format_size(size: u64) -> crate::GString {
318 unsafe { from_glib_full(ffi::g_format_size(size)) }
319}
320
321#[doc(alias = "g_format_size_full")]
322pub fn format_size_full(size: u64, flags: FormatSizeFlags) -> crate::GString {
323 unsafe { from_glib_full(ffi::g_format_size_full(size, flags.into_glib())) }
324}
325
326#[doc(alias = "g_get_application_name")]
327#[doc(alias = "get_application_name")]
328pub fn application_name() -> Option<crate::GString> {
329 unsafe { from_glib_none(ffi::g_get_application_name()) }
330}
331
332#[doc(alias = "g_get_codeset")]
333#[doc(alias = "get_codeset")]
334pub fn codeset() -> crate::GString {
335 unsafe { from_glib_full(ffi::g_get_codeset()) }
336}
337
338#[cfg(feature = "v2_62")]
339#[cfg_attr(docsrs, doc(cfg(feature = "v2_62")))]
340#[doc(alias = "g_get_console_charset")]
341#[doc(alias = "get_console_charset")]
342pub fn console_charset() -> Option<crate::GString> {
343 unsafe {
344 let mut charset = std::ptr::null();
345 let ret = from_glib(ffi::g_get_console_charset(&mut charset));
346 if ret {
347 Some(from_glib_none(charset))
348 } else {
349 None
350 }
351 }
352}
353
354#[doc(alias = "g_get_current_dir")]
355#[doc(alias = "get_current_dir")]
356pub fn current_dir() -> std::path::PathBuf {
357 unsafe { from_glib_full(ffi::g_get_current_dir()) }
358}
359
360#[doc(alias = "g_get_environ")]
361#[doc(alias = "get_environ")]
362pub fn environ() -> Vec<std::ffi::OsString> {
363 unsafe { FromGlibPtrContainer::from_glib_full(ffi::g_get_environ()) }
364}
365
366#[doc(alias = "g_get_home_dir")]
367#[doc(alias = "get_home_dir")]
368pub fn home_dir() -> std::path::PathBuf {
369 unsafe { from_glib_none(ffi::g_get_home_dir()) }
370}
371
372#[doc(alias = "g_get_host_name")]
373#[doc(alias = "get_host_name")]
374pub fn host_name() -> crate::GString {
375 unsafe { from_glib_none(ffi::g_get_host_name()) }
376}
377
378#[doc(alias = "g_get_language_names")]
379#[doc(alias = "get_language_names")]
380pub fn language_names() -> Vec<crate::GString> {
381 unsafe { FromGlibPtrContainer::from_glib_none(ffi::g_get_language_names()) }
382}
383
384#[cfg(feature = "v2_58")]
385#[cfg_attr(docsrs, doc(cfg(feature = "v2_58")))]
386#[doc(alias = "g_get_language_names_with_category")]
387#[doc(alias = "get_language_names_with_category")]
388pub fn language_names_with_category(category_name: &str) -> Vec<crate::GString> {
389 unsafe {
390 FromGlibPtrContainer::from_glib_none(ffi::g_get_language_names_with_category(
391 category_name.to_glib_none().0,
392 ))
393 }
394}
395
396#[doc(alias = "g_get_locale_variants")]
397#[doc(alias = "get_locale_variants")]
398pub fn locale_variants(locale: &str) -> Vec<crate::GString> {
399 unsafe {
400 FromGlibPtrContainer::from_glib_full(ffi::g_get_locale_variants(locale.to_glib_none().0))
401 }
402}
403
404#[doc(alias = "g_get_monotonic_time")]
405#[doc(alias = "get_monotonic_time")]
406pub fn monotonic_time() -> i64 {
407 unsafe { ffi::g_get_monotonic_time() }
408}
409
410#[cfg(feature = "v2_88")]
411#[cfg_attr(docsrs, doc(cfg(feature = "v2_88")))]
412#[doc(alias = "g_get_monotonic_time_ns")]
413#[doc(alias = "get_monotonic_time_ns")]
414pub fn monotonic_time_ns() -> u64 {
415 unsafe { ffi::g_get_monotonic_time_ns() }
416}
417
418#[doc(alias = "g_get_num_processors")]
419#[doc(alias = "get_num_processors")]
420pub fn num_processors() -> u32 {
421 unsafe { ffi::g_get_num_processors() }
422}
423
424#[cfg(feature = "v2_64")]
425#[cfg_attr(docsrs, doc(cfg(feature = "v2_64")))]
426#[doc(alias = "g_get_os_info")]
427#[doc(alias = "get_os_info")]
428pub fn os_info(key_name: &str) -> Option<crate::GString> {
429 unsafe { from_glib_full(ffi::g_get_os_info(key_name.to_glib_none().0)) }
430}
431
432#[doc(alias = "g_get_real_name")]
433#[doc(alias = "get_real_name")]
434pub fn real_name() -> std::ffi::OsString {
435 unsafe { from_glib_none(ffi::g_get_real_name()) }
436}
437
438#[doc(alias = "g_get_real_time")]
439#[doc(alias = "get_real_time")]
440pub fn real_time() -> i64 {
441 unsafe { ffi::g_get_real_time() }
442}
443
444#[doc(alias = "g_get_system_config_dirs")]
445#[doc(alias = "get_system_config_dirs")]
446pub fn system_config_dirs() -> Vec<std::path::PathBuf> {
447 unsafe { FromGlibPtrContainer::from_glib_none(ffi::g_get_system_config_dirs()) }
448}
449
450#[doc(alias = "g_get_system_data_dirs")]
451#[doc(alias = "get_system_data_dirs")]
452pub fn system_data_dirs() -> Vec<std::path::PathBuf> {
453 unsafe { FromGlibPtrContainer::from_glib_none(ffi::g_get_system_data_dirs()) }
454}
455
456#[doc(alias = "g_get_tmp_dir")]
457#[doc(alias = "get_tmp_dir")]
458pub fn tmp_dir() -> std::path::PathBuf {
459 unsafe { from_glib_none(ffi::g_get_tmp_dir()) }
460}
461
462#[doc(alias = "g_get_user_cache_dir")]
463#[doc(alias = "get_user_cache_dir")]
464pub fn user_cache_dir() -> std::path::PathBuf {
465 unsafe { from_glib_none(ffi::g_get_user_cache_dir()) }
466}
467
468#[doc(alias = "g_get_user_config_dir")]
469#[doc(alias = "get_user_config_dir")]
470pub fn user_config_dir() -> std::path::PathBuf {
471 unsafe { from_glib_none(ffi::g_get_user_config_dir()) }
472}
473
474#[doc(alias = "g_get_user_data_dir")]
475#[doc(alias = "get_user_data_dir")]
476pub fn user_data_dir() -> std::path::PathBuf {
477 unsafe { from_glib_none(ffi::g_get_user_data_dir()) }
478}
479
480#[doc(alias = "g_get_user_name")]
481#[doc(alias = "get_user_name")]
482pub fn user_name() -> std::ffi::OsString {
483 unsafe { from_glib_none(ffi::g_get_user_name()) }
484}
485
486#[doc(alias = "g_get_user_runtime_dir")]
487#[doc(alias = "get_user_runtime_dir")]
488pub fn user_runtime_dir() -> std::path::PathBuf {
489 unsafe { from_glib_none(ffi::g_get_user_runtime_dir()) }
490}
491
492#[doc(alias = "g_get_user_special_dir")]
493#[doc(alias = "get_user_special_dir")]
494pub fn user_special_dir(directory: UserDirectory) -> Option<std::path::PathBuf> {
495 unsafe { from_glib_none(ffi::g_get_user_special_dir(directory.into_glib())) }
496}
497
498#[cfg(feature = "v2_72")]
499#[cfg_attr(docsrs, doc(cfg(feature = "v2_72")))]
500#[doc(alias = "g_get_user_state_dir")]
501#[doc(alias = "get_user_state_dir")]
502pub fn user_state_dir() -> std::path::PathBuf {
503 unsafe { from_glib_none(ffi::g_get_user_state_dir()) }
504}
505
506#[doc(alias = "g_getenv")]
507pub fn getenv(variable: impl AsRef<std::ffi::OsStr>) -> Option<std::ffi::OsString> {
508 unsafe { from_glib_none(ffi::g_getenv(variable.as_ref().to_glib_none().0)) }
509}
510
511#[doc(alias = "g_hostname_is_ascii_encoded")]
512pub fn hostname_is_ascii_encoded(hostname: &str) -> bool {
513 unsafe { from_glib(ffi::g_hostname_is_ascii_encoded(hostname.to_glib_none().0)) }
514}
515
516#[doc(alias = "g_hostname_is_ip_address")]
517pub fn hostname_is_ip_address(hostname: &str) -> bool {
518 unsafe { from_glib(ffi::g_hostname_is_ip_address(hostname.to_glib_none().0)) }
519}
520
521#[doc(alias = "g_hostname_is_non_ascii")]
522pub fn hostname_is_non_ascii(hostname: &str) -> bool {
523 unsafe { from_glib(ffi::g_hostname_is_non_ascii(hostname.to_glib_none().0)) }
524}
525
526#[doc(alias = "g_hostname_to_ascii")]
527pub fn hostname_to_ascii(hostname: &str) -> Option<crate::GString> {
528 unsafe { from_glib_full(ffi::g_hostname_to_ascii(hostname.to_glib_none().0)) }
529}
530
531#[doc(alias = "g_hostname_to_unicode")]
532pub fn hostname_to_unicode(hostname: &str) -> Option<crate::GString> {
533 unsafe { from_glib_full(ffi::g_hostname_to_unicode(hostname.to_glib_none().0)) }
534}
535
536#[doc(alias = "g_listenv")]
537pub fn listenv() -> Vec<std::ffi::OsString> {
538 unsafe { FromGlibPtrContainer::from_glib_full(ffi::g_listenv()) }
539}
540
541#[doc(alias = "g_main_current_source")]
542pub fn main_current_source() -> Option<Source> {
543 unsafe { from_glib_none(ffi::g_main_current_source()) }
544}
545
546#[doc(alias = "g_main_depth")]
547pub fn main_depth() -> i32 {
548 unsafe { ffi::g_main_depth() }
549}
550
551#[doc(alias = "g_markup_escape_text")]
552pub fn markup_escape_text(text: &str) -> crate::GString {
553 let length = text.len() as _;
554 unsafe { from_glib_full(ffi::g_markup_escape_text(text.to_glib_none().0, length)) }
555}
556
557#[doc(alias = "g_mkdir_with_parents")]
558pub fn mkdir_with_parents(pathname: impl AsRef<std::path::Path>, mode: i32) -> i32 {
559 unsafe { ffi::g_mkdir_with_parents(pathname.as_ref().to_glib_none().0, mode) }
560}
561
562#[doc(alias = "g_on_error_query")]
563pub fn on_error_query(prg_name: &str) {
564 unsafe {
565 ffi::g_on_error_query(prg_name.to_glib_none().0);
566 }
567}
568
569#[doc(alias = "g_on_error_stack_trace")]
570pub fn on_error_stack_trace(prg_name: Option<&str>) {
571 unsafe {
572 ffi::g_on_error_stack_trace(prg_name.to_glib_none().0);
573 }
574}
575
576#[doc(alias = "g_path_get_basename")]
577#[allow(dead_code)]
578pub(crate) fn path_get_basename(file_name: impl AsRef<std::path::Path>) -> std::path::PathBuf {
579 unsafe {
580 from_glib_full(ffi::g_path_get_basename(
581 file_name.as_ref().to_glib_none().0,
582 ))
583 }
584}
585
586#[doc(alias = "g_path_get_dirname")]
587#[allow(dead_code)]
588pub(crate) fn path_get_dirname(file_name: impl AsRef<std::path::Path>) -> std::path::PathBuf {
589 unsafe { from_glib_full(ffi::g_path_get_dirname(file_name.as_ref().to_glib_none().0)) }
590}
591
592#[doc(alias = "g_random_double")]
598pub fn random_double() -> f64 {
599 unsafe { ffi::g_random_double() }
600}
601
602#[doc(alias = "g_random_double_range")]
603pub fn random_double_range(begin: f64, end: f64) -> f64 {
604 unsafe { ffi::g_random_double_range(begin, end) }
605}
606
607#[doc(alias = "g_random_int")]
608pub fn random_int() -> u32 {
609 unsafe { ffi::g_random_int() }
610}
611
612#[doc(alias = "g_random_int_range")]
613pub fn random_int_range(begin: i32, end: i32) -> i32 {
614 unsafe { ffi::g_random_int_range(begin, end) }
615}
616
617#[doc(alias = "g_random_set_seed")]
618pub fn random_set_seed(seed: u32) {
619 unsafe {
620 ffi::g_random_set_seed(seed);
621 }
622}
623
624#[doc(alias = "g_reload_user_special_dirs_cache")]
625pub fn reload_user_special_dirs_cache() {
626 unsafe {
627 ffi::g_reload_user_special_dirs_cache();
628 }
629}
630
631#[doc(alias = "g_set_application_name")]
632pub fn set_application_name(application_name: &str) {
633 unsafe {
634 ffi::g_set_application_name(application_name.to_glib_none().0);
635 }
636}
637
638#[doc(alias = "g_setenv")]
639pub unsafe fn setenv(
640 variable: impl AsRef<std::ffi::OsStr>,
641 value: impl AsRef<std::ffi::OsStr>,
642 overwrite: bool,
643) -> Result<(), crate::error::BoolError> {
644 unsafe {
645 crate::result_from_gboolean!(
646 ffi::g_setenv(
647 variable.as_ref().to_glib_none().0,
648 value.as_ref().to_glib_none().0,
649 overwrite.into_glib()
650 ),
651 "Failed to set environment variable"
652 )
653 }
654}
655
656#[doc(alias = "g_shell_parse_argv")]
657pub fn shell_parse_argv(
658 command_line: impl AsRef<std::ffi::OsStr>,
659) -> Result<Vec<std::ffi::OsString>, crate::Error> {
660 unsafe {
661 let mut argcp = std::mem::MaybeUninit::uninit();
662 let mut argvp = std::ptr::null_mut();
663 let mut error = std::ptr::null_mut();
664 let is_ok = ffi::g_shell_parse_argv(
665 command_line.as_ref().to_glib_none().0,
666 argcp.as_mut_ptr(),
667 &mut argvp,
668 &mut error,
669 );
670 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
671 if error.is_null() {
672 Ok(FromGlibContainer::from_glib_full_num(
673 argvp,
674 argcp.assume_init() as _,
675 ))
676 } else {
677 Err(from_glib_full(error))
678 }
679 }
680}
681
682#[doc(alias = "g_shell_quote")]
683pub fn shell_quote(unquoted_string: impl AsRef<std::ffi::OsStr>) -> std::ffi::OsString {
684 unsafe {
685 from_glib_full(ffi::g_shell_quote(
686 unquoted_string.as_ref().to_glib_none().0,
687 ))
688 }
689}
690
691#[doc(alias = "g_shell_unquote")]
692pub fn shell_unquote(
693 quoted_string: impl AsRef<std::ffi::OsStr>,
694) -> Result<std::ffi::OsString, crate::Error> {
695 unsafe {
696 let mut error = std::ptr::null_mut();
697 let ret = ffi::g_shell_unquote(quoted_string.as_ref().to_glib_none().0, &mut error);
698 if error.is_null() {
699 Ok(from_glib_full(ret))
700 } else {
701 Err(from_glib_full(error))
702 }
703 }
704}
705
706#[doc(alias = "g_spaced_primes_closest")]
714pub fn spaced_primes_closest(num: u32) -> u32 {
715 unsafe { ffi::g_spaced_primes_closest(num) }
716}
717
718#[doc(alias = "g_spawn_async")]
719pub fn spawn_async(
720 working_directory: Option<impl AsRef<std::path::Path>>,
721 argv: &[&std::path::Path],
722 envp: &[&std::path::Path],
723 flags: SpawnFlags,
724 child_setup: Option<Box_<dyn FnOnce() + 'static>>,
725) -> Result<Pid, crate::Error> {
726 let child_setup_data: Box_<Option<Box_<dyn FnOnce() + 'static>>> = Box_::new(child_setup);
727 unsafe extern "C" fn child_setup_func(data: ffi::gpointer) {
728 unsafe {
729 let callback = Box_::from_raw(data as *mut Option<Box_<dyn FnOnce() + 'static>>);
730 let callback = (*callback).expect("cannot get closure...");
731 callback()
732 }
733 }
734 let child_setup = if child_setup_data.is_some() {
735 Some(child_setup_func as _)
736 } else {
737 None
738 };
739 let super_callback0: Box_<Option<Box_<dyn FnOnce() + 'static>>> = child_setup_data;
740 unsafe {
741 let mut child_pid = std::mem::MaybeUninit::uninit();
742 let mut error = std::ptr::null_mut();
743 let is_ok = ffi::g_spawn_async(
744 working_directory
745 .as_ref()
746 .map(|p| p.as_ref())
747 .to_glib_none()
748 .0,
749 argv.to_glib_none().0,
750 envp.to_glib_none().0,
751 flags.into_glib(),
752 child_setup,
753 Box_::into_raw(super_callback0) as *mut _,
754 child_pid.as_mut_ptr(),
755 &mut error,
756 );
757 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
758 if error.is_null() {
759 Ok(from_glib(child_pid.assume_init()))
760 } else {
761 Err(from_glib_full(error))
762 }
763 }
764}
765
766#[cfg_attr(feature = "v2_70", deprecated = "Since 2.70")]
774#[allow(deprecated)]
775#[doc(alias = "g_spawn_check_exit_status")]
776pub fn spawn_check_exit_status(wait_status: i32) -> Result<(), crate::Error> {
777 unsafe {
778 let mut error = std::ptr::null_mut();
779 let is_ok = ffi::g_spawn_check_exit_status(wait_status, &mut error);
780 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
781 if error.is_null() {
782 Ok(())
783 } else {
784 Err(from_glib_full(error))
785 }
786 }
787}
788
789#[cfg(feature = "v2_70")]
790#[cfg_attr(docsrs, doc(cfg(feature = "v2_70")))]
791#[doc(alias = "g_spawn_check_wait_status")]
792pub fn spawn_check_wait_status(wait_status: i32) -> Result<(), crate::Error> {
793 unsafe {
794 let mut error = std::ptr::null_mut();
795 let is_ok = ffi::g_spawn_check_wait_status(wait_status, &mut error);
796 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
797 if error.is_null() {
798 Ok(())
799 } else {
800 Err(from_glib_full(error))
801 }
802 }
803}
804
805#[cfg(unix)]
806#[cfg_attr(docsrs, doc(cfg(unix)))]
807#[doc(alias = "g_spawn_command_line_async")]
808pub fn spawn_command_line_async(
809 command_line: impl AsRef<std::ffi::OsStr>,
810) -> Result<(), crate::Error> {
811 unsafe {
812 let mut error = std::ptr::null_mut();
813 let is_ok =
814 ffi::g_spawn_command_line_async(command_line.as_ref().to_glib_none().0, &mut error);
815 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
816 if error.is_null() {
817 Ok(())
818 } else {
819 Err(from_glib_full(error))
820 }
821 }
822}
823
824#[doc(alias = "g_unlink")]
840pub fn unlink(filename: impl AsRef<std::path::Path>) -> i32 {
841 unsafe { ffi::g_unlink(filename.as_ref().to_glib_none().0) }
842}
843
844#[doc(alias = "g_unsetenv")]
845pub unsafe fn unsetenv(variable: impl AsRef<std::ffi::OsStr>) {
846 unsafe {
847 ffi::g_unsetenv(variable.as_ref().to_glib_none().0);
848 }
849}
850
851#[doc(alias = "g_usleep")]
852pub fn usleep(microseconds: libc::c_ulong) {
853 unsafe {
854 ffi::g_usleep(microseconds);
855 }
856}
857
858#[doc(alias = "g_uuid_string_is_valid")]
859pub fn uuid_string_is_valid(str: &str) -> bool {
860 unsafe { from_glib(ffi::g_uuid_string_is_valid(str.to_glib_none().0)) }
861}
862
863#[doc(alias = "g_uuid_string_random")]
864pub fn uuid_string_random() -> crate::GString {
865 unsafe { from_glib_full(ffi::g_uuid_string_random()) }
866}