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 translate::*, Bytes, ChecksumType, Error, FileTest, FormatSizeFlags, Pid, Source, SpawnFlags,
10 UnicodeScript, UserDirectory,
11};
12use std::{boxed::Box as Box_, mem, ptr};
13
14#[doc(alias = "g_access")]
15pub fn access(filename: impl AsRef<std::path::Path>, mode: i32) -> i32 {
16 unsafe { ffi::g_access(filename: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: MaybeUninit = mem::MaybeUninit::uninit();
23 let ret: Vec = FromGlibContainer::from_glib_full_num(
24 ptr:ffi::g_base64_decode(text.to_glib_none().0, out_len.as_mut_ptr()),
25 num:out_len.assume_init() as _,
26 );
27 ret
28 }
29}
30
31//#[doc(alias = "g_base64_decode_inplace")]
32//pub fn base64_decode_inplace(text: /*Unimplemented*/Vec<u8>) -> u8 {
33// unsafe { TODO: call ffi:g_base64_decode_inplace() }
34//}
35
36//#[doc(alias = "g_base64_decode_step")]
37//pub fn base64_decode_step(in_: &[u8], out: Vec<u8>, state: &mut i32, save: &mut u32) -> usize {
38// unsafe { TODO: call ffi:g_base64_decode_step() }
39//}
40
41#[doc(alias = "g_base64_encode")]
42pub fn base64_encode(data: &[u8]) -> crate::GString {
43 let len: usize = data.len() as _;
44 unsafe { from_glib_full(ptr:ffi::g_base64_encode(data:data.to_glib_none().0, len)) }
45}
46
47//#[doc(alias = "g_base64_encode_close")]
48//pub fn base64_encode_close(break_lines: bool, out: Vec<u8>, state: &mut i32, save: &mut i32) -> usize {
49// unsafe { TODO: call ffi:g_base64_encode_close() }
50//}
51
52//#[doc(alias = "g_base64_encode_step")]
53//pub fn base64_encode_step(in_: &[u8], break_lines: bool, out: Vec<u8>, state: &mut i32, save: &mut i32) -> usize {
54// unsafe { TODO: call ffi:g_base64_encode_step() }
55//}
56
57#[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(ptr: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(ptr:ffi::g_compute_checksum_for_bytes(
79 checksum_type:checksum_type.into_glib(),
80 data: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: usize = data.len() as _;
91 unsafe {
92 from_glib_full(ptr:ffi::g_compute_checksum_for_data(
93 checksum_type:checksum_type.into_glib(),
94 data: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(ptr:ffi::g_compute_hmac_for_bytes(
108 digest_type:digest_type.into_glib(),
109 key:key.to_glib_none().0,
110 data: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: usize = key.len() as _;
118 let length: usize = data.len() as _;
119 unsafe {
120 from_glib_full(ptr:ffi::g_compute_hmac_for_data(
121 digest_type:digest_type.into_glib(),
122 key:key.to_glib_none().0,
123 key_len,
124 data: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(ptr:ffi::g_dcgettext(
134 domain:domain.to_glib_none().0,
135 msgid: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(ptr:ffi::g_dgettext(
145 domain:domain.to_glib_none().0,
146 msgid: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(ptr:ffi::g_dngettext(
160 domain:domain.to_glib_none().0,
161 msgid:msgid.to_glib_none().0,
162 msgid_plural: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(ptr:ffi::g_dpgettext(
172 domain:domain.to_glib_none().0,
173 msgctxtid: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(ptr:ffi::g_dpgettext2(
183 domain:domain.to_glib_none().0,
184 context:context.to_glib_none().0,
185 msgid: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: isize = contents.len() as _;
196 unsafe {
197 let mut error: *mut GError = ptr::null_mut();
198 let is_ok: i32 = ffi::g_file_set_contents(
199 filename:filename.as_ref().to_glib_none().0,
200 contents: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(ptr: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 = 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(val:ffi::g_file_test(
247 filename:filename.as_ref().to_glib_none().0,
248 test: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(ptr:ffi::g_filename_display_basename(
257 filename: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(ptr:ffi::g_filename_display_name(
266 filename: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: *mut i8 = ptr::null_mut();
277 let mut error: *mut GError = ptr::null_mut();
278 let ret: *mut i8 = ffi::g_filename_from_uri(uri:uri.to_glib_none().0, &mut hostname, &mut error);
279 if error.is_null() {
280 Ok((from_glib_full(ptr:ret), from_glib_full(ptr:hostname)))
281 } else {
282 Err(from_glib_full(ptr: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: *mut GError = ptr::null_mut();
294 let ret: *mut i8 = ffi::g_filename_to_uri(
295 filename:filename.as_ref().to_glib_none().0,
296 hostname:hostname.to_glib_none().0,
297 &mut error,
298 );
299 if error.is_null() {
300 Ok(from_glib_full(ptr:ret))
301 } else {
302 Err(from_glib_full(ptr: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(ptr:ffi::g_find_program_in_path(
311 program: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(ptr: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(ptr:ffi::g_format_size_full(size, flags: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(ptr: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(ptr: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 = 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(ptr: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(ptr: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(ptr: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(ptr: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(ptr: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(ptr:ffi::g_get_locale_variants(locale: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#[doc(alias = "g_get_num_processors")]
411#[doc(alias = "get_num_processors")]
412pub fn num_processors() -> u32 {
413 unsafe { ffi::g_get_num_processors() }
414}
415
416#[cfg(feature = "v2_64")]
417#[cfg_attr(docsrs, doc(cfg(feature = "v2_64")))]
418#[doc(alias = "g_get_os_info")]
419#[doc(alias = "get_os_info")]
420pub fn os_info(key_name: &str) -> Option<crate::GString> {
421 unsafe { from_glib_full(ffi::g_get_os_info(key_name.to_glib_none().0)) }
422}
423
424#[doc(alias = "g_get_real_name")]
425#[doc(alias = "get_real_name")]
426pub fn real_name() -> std::ffi::OsString {
427 unsafe { from_glib_none(ptr:ffi::g_get_real_name()) }
428}
429
430#[doc(alias = "g_get_real_time")]
431#[doc(alias = "get_real_time")]
432pub fn real_time() -> i64 {
433 unsafe { ffi::g_get_real_time() }
434}
435
436#[doc(alias = "g_get_system_config_dirs")]
437#[doc(alias = "get_system_config_dirs")]
438pub fn system_config_dirs() -> Vec<std::path::PathBuf> {
439 unsafe { FromGlibPtrContainer::from_glib_none(ptr:ffi::g_get_system_config_dirs()) }
440}
441
442#[doc(alias = "g_get_system_data_dirs")]
443#[doc(alias = "get_system_data_dirs")]
444pub fn system_data_dirs() -> Vec<std::path::PathBuf> {
445 unsafe { FromGlibPtrContainer::from_glib_none(ptr:ffi::g_get_system_data_dirs()) }
446}
447
448#[doc(alias = "g_get_tmp_dir")]
449#[doc(alias = "get_tmp_dir")]
450pub fn tmp_dir() -> std::path::PathBuf {
451 unsafe { from_glib_none(ptr:ffi::g_get_tmp_dir()) }
452}
453
454#[doc(alias = "g_get_user_cache_dir")]
455#[doc(alias = "get_user_cache_dir")]
456pub fn user_cache_dir() -> std::path::PathBuf {
457 unsafe { from_glib_none(ptr:ffi::g_get_user_cache_dir()) }
458}
459
460#[doc(alias = "g_get_user_config_dir")]
461#[doc(alias = "get_user_config_dir")]
462pub fn user_config_dir() -> std::path::PathBuf {
463 unsafe { from_glib_none(ptr:ffi::g_get_user_config_dir()) }
464}
465
466#[doc(alias = "g_get_user_data_dir")]
467#[doc(alias = "get_user_data_dir")]
468pub fn user_data_dir() -> std::path::PathBuf {
469 unsafe { from_glib_none(ptr:ffi::g_get_user_data_dir()) }
470}
471
472#[doc(alias = "g_get_user_name")]
473#[doc(alias = "get_user_name")]
474pub fn user_name() -> std::ffi::OsString {
475 unsafe { from_glib_none(ptr:ffi::g_get_user_name()) }
476}
477
478#[doc(alias = "g_get_user_runtime_dir")]
479#[doc(alias = "get_user_runtime_dir")]
480pub fn user_runtime_dir() -> std::path::PathBuf {
481 unsafe { from_glib_none(ptr:ffi::g_get_user_runtime_dir()) }
482}
483
484#[doc(alias = "g_get_user_special_dir")]
485#[doc(alias = "get_user_special_dir")]
486pub fn user_special_dir(directory: UserDirectory) -> Option<std::path::PathBuf> {
487 unsafe { from_glib_none(ptr:ffi::g_get_user_special_dir(directory:directory.into_glib())) }
488}
489
490#[cfg(feature = "v2_72")]
491#[cfg_attr(docsrs, doc(cfg(feature = "v2_72")))]
492#[doc(alias = "g_get_user_state_dir")]
493#[doc(alias = "get_user_state_dir")]
494pub fn user_state_dir() -> std::path::PathBuf {
495 unsafe { from_glib_none(ffi::g_get_user_state_dir()) }
496}
497
498#[doc(alias = "g_getenv")]
499pub fn getenv(variable: impl AsRef<std::ffi::OsStr>) -> Option<std::ffi::OsString> {
500 unsafe { from_glib_none(ptr:ffi::g_getenv(variable:variable.as_ref().to_glib_none().0)) }
501}
502
503#[doc(alias = "g_hostname_is_ascii_encoded")]
504pub fn hostname_is_ascii_encoded(hostname: &str) -> bool {
505 unsafe { from_glib(val:ffi::g_hostname_is_ascii_encoded(hostname:hostname.to_glib_none().0)) }
506}
507
508#[doc(alias = "g_hostname_is_ip_address")]
509pub fn hostname_is_ip_address(hostname: &str) -> bool {
510 unsafe { from_glib(val:ffi::g_hostname_is_ip_address(hostname:hostname.to_glib_none().0)) }
511}
512
513#[doc(alias = "g_hostname_is_non_ascii")]
514pub fn hostname_is_non_ascii(hostname: &str) -> bool {
515 unsafe { from_glib(val:ffi::g_hostname_is_non_ascii(hostname:hostname.to_glib_none().0)) }
516}
517
518#[doc(alias = "g_hostname_to_ascii")]
519pub fn hostname_to_ascii(hostname: &str) -> Option<crate::GString> {
520 unsafe { from_glib_full(ptr:ffi::g_hostname_to_ascii(hostname:hostname.to_glib_none().0)) }
521}
522
523#[doc(alias = "g_hostname_to_unicode")]
524pub fn hostname_to_unicode(hostname: &str) -> Option<crate::GString> {
525 unsafe { from_glib_full(ptr:ffi::g_hostname_to_unicode(hostname:hostname.to_glib_none().0)) }
526}
527
528#[doc(alias = "g_listenv")]
529pub fn listenv() -> Vec<std::ffi::OsString> {
530 unsafe { FromGlibPtrContainer::from_glib_full(ptr:ffi::g_listenv()) }
531}
532
533#[doc(alias = "g_main_current_source")]
534pub fn main_current_source() -> Option<Source> {
535 unsafe { from_glib_none(ptr:ffi::g_main_current_source()) }
536}
537
538#[doc(alias = "g_main_depth")]
539pub fn main_depth() -> i32 {
540 unsafe { ffi::g_main_depth() }
541}
542
543#[doc(alias = "g_markup_escape_text")]
544pub fn markup_escape_text(text: &str) -> crate::GString {
545 let length: isize = text.len() as _;
546 unsafe { from_glib_full(ptr:ffi::g_markup_escape_text(text:text.to_glib_none().0, length)) }
547}
548
549#[doc(alias = "g_mkdir_with_parents")]
550pub fn mkdir_with_parents(pathname: impl AsRef<std::path::Path>, mode: i32) -> i32 {
551 unsafe { ffi::g_mkdir_with_parents(pathname:pathname.as_ref().to_glib_none().0, mode) }
552}
553
554#[doc(alias = "g_on_error_query")]
555pub fn on_error_query(prg_name: &str) {
556 unsafe {
557 ffi::g_on_error_query(prg_name:prg_name.to_glib_none().0);
558 }
559}
560
561#[doc(alias = "g_on_error_stack_trace")]
562pub fn on_error_stack_trace(prg_name: &str) {
563 unsafe {
564 ffi::g_on_error_stack_trace(prg_name:prg_name.to_glib_none().0);
565 }
566}
567
568#[doc(alias = "g_path_get_basename")]
569#[allow(dead_code)]
570pub(crate) fn path_get_basename(file_name: impl AsRef<std::path::Path>) -> std::path::PathBuf {
571 unsafe {
572 from_glib_full(ptr:ffi::g_path_get_basename(
573 file_name:file_name.as_ref().to_glib_none().0,
574 ))
575 }
576}
577
578#[doc(alias = "g_path_get_dirname")]
579#[allow(dead_code)]
580pub(crate) fn path_get_dirname(file_name: impl AsRef<std::path::Path>) -> std::path::PathBuf {
581 unsafe { from_glib_full(ptr:ffi::g_path_get_dirname(file_name:file_name.as_ref().to_glib_none().0)) }
582}
583
584//#[doc(alias = "g_poll")]
585//pub fn poll(fds: /*Ignored*/&mut PollFD, nfds: u32, timeout: i32) -> i32 {
586// unsafe { TODO: call ffi:g_poll() }
587//}
588
589#[doc(alias = "g_random_double")]
590pub fn random_double() -> f64 {
591 unsafe { ffi::g_random_double() }
592}
593
594#[doc(alias = "g_random_double_range")]
595pub fn random_double_range(begin: f64, end: f64) -> f64 {
596 unsafe { ffi::g_random_double_range(begin, end) }
597}
598
599#[doc(alias = "g_random_int")]
600pub fn random_int() -> u32 {
601 unsafe { ffi::g_random_int() }
602}
603
604#[doc(alias = "g_random_int_range")]
605pub fn random_int_range(begin: i32, end: i32) -> i32 {
606 unsafe { ffi::g_random_int_range(begin, end) }
607}
608
609#[doc(alias = "g_random_set_seed")]
610pub fn random_set_seed(seed: u32) {
611 unsafe {
612 ffi::g_random_set_seed(seed);
613 }
614}
615
616#[doc(alias = "g_reload_user_special_dirs_cache")]
617pub fn reload_user_special_dirs_cache() {
618 unsafe {
619 ffi::g_reload_user_special_dirs_cache();
620 }
621}
622
623#[doc(alias = "g_set_application_name")]
624pub fn set_application_name(application_name: &str) {
625 unsafe {
626 ffi::g_set_application_name(application_name.to_glib_none().0);
627 }
628}
629
630#[doc(alias = "g_setenv")]
631pub fn setenv(
632 variable: impl AsRef<std::ffi::OsStr>,
633 value: impl AsRef<std::ffi::OsStr>,
634 overwrite: bool,
635) -> Result<(), crate::error::BoolError> {
636 unsafe {
637 crate::result_from_gboolean!(
638 ffi::g_setenv(
639 variable.as_ref().to_glib_none().0,
640 value.as_ref().to_glib_none().0,
641 overwrite.into_glib()
642 ),
643 "Failed to set environment variable"
644 )
645 }
646}
647
648#[doc(alias = "g_shell_parse_argv")]
649pub fn shell_parse_argv(
650 command_line: impl AsRef<std::ffi::OsStr>,
651) -> Result<Vec<std::ffi::OsString>, crate::Error> {
652 unsafe {
653 let mut argcp: MaybeUninit = mem::MaybeUninit::uninit();
654 let mut argvp: *mut *mut i8 = ptr::null_mut();
655 let mut error: *mut GError = ptr::null_mut();
656 let is_ok: i32 = ffi::g_shell_parse_argv(
657 command_line:command_line.as_ref().to_glib_none().0,
658 argcp:argcp.as_mut_ptr(),
659 &mut argvp,
660 &mut error,
661 );
662 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
663 if error.is_null() {
664 Ok(FromGlibContainer::from_glib_full_num(
665 ptr:argvp,
666 num:argcp.assume_init() as _,
667 ))
668 } else {
669 Err(from_glib_full(ptr:error))
670 }
671 }
672}
673
674#[doc(alias = "g_shell_quote")]
675pub fn shell_quote(unquoted_string: impl AsRef<std::ffi::OsStr>) -> std::ffi::OsString {
676 unsafe {
677 from_glib_full(ptr:ffi::g_shell_quote(
678 unquoted_string:unquoted_string.as_ref().to_glib_none().0,
679 ))
680 }
681}
682
683#[doc(alias = "g_shell_unquote")]
684pub fn shell_unquote(
685 quoted_string: impl AsRef<std::ffi::OsStr>,
686) -> Result<std::ffi::OsString, crate::Error> {
687 unsafe {
688 let mut error: *mut GError = ptr::null_mut();
689 let ret: *mut i8 = ffi::g_shell_unquote(quoted_string:quoted_string.as_ref().to_glib_none().0, &mut error);
690 if error.is_null() {
691 Ok(from_glib_full(ptr:ret))
692 } else {
693 Err(from_glib_full(ptr:error))
694 }
695 }
696}
697
698#[doc(alias = "g_spaced_primes_closest")]
699pub fn spaced_primes_closest(num: u32) -> u32 {
700 unsafe { ffi::g_spaced_primes_closest(num) }
701}
702
703#[doc(alias = "g_spawn_async")]
704pub fn spawn_async(
705 working_directory: Option<impl AsRef<std::path::Path>>,
706 argv: &[&std::path::Path],
707 envp: &[&std::path::Path],
708 flags: SpawnFlags,
709 child_setup: Option<Box_<dyn FnOnce() + 'static>>,
710) -> Result<Pid, crate::Error> {
711 let child_setup_data: Box_<Option<Box_<dyn FnOnce() + 'static>>> = Box_::new(child_setup);
712 unsafe extern "C" fn child_setup_func(data: ffi::gpointer) {
713 let callback: Box_<Option<Box_<dyn FnOnce() + 'static>>> = Box_::from_raw(data as *mut _);
714 let callback = (*callback).expect("cannot get closure...");
715 callback()
716 }
717 let child_setup = if child_setup_data.is_some() {
718 Some(child_setup_func as _)
719 } else {
720 None
721 };
722 let super_callback0: Box_<Option<Box_<dyn FnOnce() + 'static>>> = child_setup_data;
723 unsafe {
724 let mut child_pid = mem::MaybeUninit::uninit();
725 let mut error = ptr::null_mut();
726 let is_ok = ffi::g_spawn_async(
727 working_directory
728 .as_ref()
729 .map(|p| p.as_ref())
730 .to_glib_none()
731 .0,
732 argv.to_glib_none().0,
733 envp.to_glib_none().0,
734 flags.into_glib(),
735 child_setup,
736 Box_::into_raw(super_callback0) as *mut _,
737 child_pid.as_mut_ptr(),
738 &mut error,
739 );
740 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
741 if error.is_null() {
742 Ok(from_glib(child_pid.assume_init()))
743 } else {
744 Err(from_glib_full(error))
745 }
746 }
747}
748
749//#[cfg(feature = "v2_68")]
750//#[cfg_attr(docsrs, doc(cfg(feature = "v2_68")))]
751//#[doc(alias = "g_spawn_async_with_pipes_and_fds")]
752//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> {
753// unsafe { TODO: call ffi:g_spawn_async_with_pipes_and_fds() }
754//}
755
756#[cfg_attr(feature = "v2_70", deprecated = "Since 2.70")]
757#[allow(deprecated)]
758#[doc(alias = "g_spawn_check_exit_status")]
759pub fn spawn_check_exit_status(wait_status: i32) -> Result<(), crate::Error> {
760 unsafe {
761 let mut error: *mut GError = ptr::null_mut();
762 let is_ok: i32 = ffi::g_spawn_check_exit_status(wait_status, &mut error);
763 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
764 if error.is_null() {
765 Ok(())
766 } else {
767 Err(from_glib_full(ptr:error))
768 }
769 }
770}
771
772#[cfg(feature = "v2_70")]
773#[cfg_attr(docsrs, doc(cfg(feature = "v2_70")))]
774#[doc(alias = "g_spawn_check_wait_status")]
775pub fn spawn_check_wait_status(wait_status: i32) -> Result<(), crate::Error> {
776 unsafe {
777 let mut error = ptr::null_mut();
778 let is_ok = ffi::g_spawn_check_wait_status(wait_status, &mut error);
779 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
780 if error.is_null() {
781 Ok(())
782 } else {
783 Err(from_glib_full(error))
784 }
785 }
786}
787
788#[cfg(unix)]
789#[cfg_attr(docsrs, doc(cfg(unix)))]
790#[doc(alias = "g_spawn_command_line_async")]
791pub fn spawn_command_line_async(
792 command_line: impl AsRef<std::ffi::OsStr>,
793) -> Result<(), crate::Error> {
794 unsafe {
795 let mut error: *mut GError = ptr::null_mut();
796 let is_ok: i32 =
797 ffi::g_spawn_command_line_async(command_line:command_line.as_ref().to_glib_none().0, &mut error);
798 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
799 if error.is_null() {
800 Ok(())
801 } else {
802 Err(from_glib_full(ptr:error))
803 }
804 }
805}
806
807//#[doc(alias = "g_spawn_command_line_sync")]
808//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> {
809// unsafe { TODO: call ffi:g_spawn_command_line_sync() }
810//}
811
812//#[doc(alias = "g_spawn_sync")]
813//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> {
814// unsafe { TODO: call ffi:g_spawn_sync() }
815//}
816
817#[doc(alias = "g_unicode_script_from_iso15924")]
818pub fn unicode_script_from_iso15924(iso15924: u32) -> UnicodeScript {
819 unsafe { from_glib(val:ffi::g_unicode_script_from_iso15924(iso15924)) }
820}
821
822#[doc(alias = "g_unicode_script_to_iso15924")]
823pub fn unicode_script_to_iso15924(script: UnicodeScript) -> u32 {
824 unsafe { ffi::g_unicode_script_to_iso15924(script:script.into_glib()) }
825}
826
827//#[cfg(unix)]
828//#[cfg_attr(docsrs, doc(cfg(unix)))]
829//#[cfg(feature = "v2_64")]
830//#[cfg_attr(docsrs, doc(cfg(feature = "v2_64")))]
831//#[doc(alias = "g_unix_get_passwd_entry")]
832//pub fn unix_get_passwd_entry(user_name: &str) -> Result</*Unimplemented*/Option<Basic: Pointer>, crate::Error> {
833// unsafe { TODO: call ffi:g_unix_get_passwd_entry() }
834//}
835
836#[doc(alias = "g_unlink")]
837pub fn unlink(filename: impl AsRef<std::path::Path>) -> i32 {
838 unsafe { ffi::g_unlink(filename:filename.as_ref().to_glib_none().0) }
839}
840
841#[doc(alias = "g_unsetenv")]
842pub fn unsetenv(variable: impl AsRef<std::ffi::OsStr>) {
843 unsafe {
844 ffi::g_unsetenv(variable:variable.as_ref().to_glib_none().0);
845 }
846}
847
848#[doc(alias = "g_usleep")]
849pub fn usleep(microseconds: libc::c_ulong) {
850 unsafe {
851 ffi::g_usleep(microseconds);
852 }
853}
854
855#[doc(alias = "g_uuid_string_is_valid")]
856pub fn uuid_string_is_valid(str: &str) -> bool {
857 unsafe { from_glib(val:ffi::g_uuid_string_is_valid(str:str.to_glib_none().0)) }
858}
859
860#[doc(alias = "g_uuid_string_random")]
861pub fn uuid_string_random() -> crate::GString {
862 unsafe { from_glib_full(ptr:ffi::g_uuid_string_random()) }
863}
864