1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module glib.Util;
26 
27 private import glib.Str;
28 private import gtkc.glib;
29 public  import gtkc.glibtypes;
30 
31 
32 /** */
33 public struct Util
34 {
35 	/**
36 	 * Behaves exactly like g_build_filename(), but takes the path elements
37 	 * as a string array, instead of varargs. This function is mainly
38 	 * meant for language bindings.
39 	 *
40 	 * Params:
41 	 *     args = strings containing the path elements.
42 	 *
43 	 * Return: a newly-allocated string that must be freed with g_free().
44 	 *
45 	 * Since: 2.8
46 	 */
47 	public static string buildFilename(string[] firstElement ... )
48 	{
49 		return Str.toString(g_build_filenamev(Str.toStringzArray(firstElement)));
50 	}
51 	
52 	/**
53 	 * Behaves exactly like g_build_path(), but takes the path elements
54 	 * as a string array, instead of varargs. This function is mainly
55 	 * meant for language bindings.
56 	 *
57 	 * Params:
58 	 *     separator = a string used to separator the elements of the path.
59 	 *     args = strings containing the path elements.
60 	 *
61 	 * Return: a newly-allocated string that must be freed with g_free().
62 	 *
63 	 * Since: 2.8
64 	 */
65 	public static string buildPath(string separator, string[] firstElement ... )
66 	{
67 		return Str.toString(g_build_pathv(Str.toStringz(separator), Str.toStringzArray(firstElement)));
68 	}
69 
70 	/**
71 	 */
72 
73 	/**
74 	 * Specifies a function to be called at normal program termination.
75 	 *
76 	 * Since GLib 2.8.2, on Windows g_atexit() actually is a preprocessor
77 	 * macro that maps to a call to the atexit() function in the C
78 	 * library. This means that in case the code that calls g_atexit(),
79 	 * i.e. atexit(), is in a DLL, the function will be called when the
80 	 * DLL is detached from the program. This typically makes more sense
81 	 * than that the function is called when the GLib DLL is detached,
82 	 * which happened earlier when g_atexit() was a function in the GLib
83 	 * DLL.
84 	 *
85 	 * The behaviour of atexit() in the context of dynamically loaded
86 	 * modules is not formally specified and varies wildly.
87 	 *
88 	 * On POSIX systems, calling g_atexit() (or atexit()) in a dynamically
89 	 * loaded module which is unloaded before the program terminates might
90 	 * well cause a crash at program exit.
91 	 *
92 	 * Some POSIX systems implement atexit() like Windows, and have each
93 	 * dynamically loaded module maintain an own atexit chain that is
94 	 * called when the module is unloaded.
95 	 *
96 	 * On other POSIX systems, before a dynamically loaded module is
97 	 * unloaded, the registered atexit functions (if any) residing in that
98 	 * module are called, regardless where the code that registered them
99 	 * resided. This is presumably the most robust approach.
100 	 *
101 	 * As can be seen from the above, for portability it's best to avoid
102 	 * calling g_atexit() (or atexit()) except in the main executable of a
103 	 * program.
104 	 *
105 	 * Deprecated: It is best to avoid g_atexit().
106 	 *
107 	 * Params:
108 	 *     func = the function to call on normal program termination.
109 	 */
110 	public static void atexit(GVoidFunc func)
111 	{
112 		g_atexit(func);
113 	}
114 
115 	/**
116 	 * Gets the name of the file without any leading directory
117 	 * components. It returns a pointer into the given file name
118 	 * string.
119 	 *
120 	 * Deprecated: Use g_path_get_basename() instead, but notice
121 	 * that g_path_get_basename() allocates new memory for the
122 	 * returned string, unlike this function which returns a pointer
123 	 * into the argument.
124 	 *
125 	 * Params:
126 	 *     fileName = the name of the file
127 	 *
128 	 * Return: the name of the file without any leading
129 	 *     directory components
130 	 */
131 	public static string basename(string fileName)
132 	{
133 		return Str.toString(g_basename(Str.toStringz(fileName)));
134 	}
135 
136 	/**
137 	 * Find the position of the first bit set in @mask, searching
138 	 * from (but not including) @nth_bit upwards. Bits are numbered
139 	 * from 0 (least significant) to sizeof(#gulong) * 8 - 1 (31 or 63,
140 	 * usually). To start searching from the 0th bit, set @nth_bit to -1.
141 	 *
142 	 * Params:
143 	 *     mask = a #gulong containing flags
144 	 *     nthBit = the index of the bit to start the search from
145 	 *
146 	 * Return: the index of the first bit set which is higher than @nth_bit, or -1
147 	 *     if no higher bits are set
148 	 */
149 	public static int bitNthLsf(gulong mask, int nthBit)
150 	{
151 		return g_bit_nth_lsf(mask, nthBit);
152 	}
153 
154 	/**
155 	 * Find the position of the first bit set in @mask, searching
156 	 * from (but not including) @nth_bit downwards. Bits are numbered
157 	 * from 0 (least significant) to sizeof(#gulong) * 8 - 1 (31 or 63,
158 	 * usually). To start searching from the last bit, set @nth_bit to
159 	 * -1 or GLIB_SIZEOF_LONG * 8.
160 	 *
161 	 * Params:
162 	 *     mask = a #gulong containing flags
163 	 *     nthBit = the index of the bit to start the search from
164 	 *
165 	 * Return: the index of the first bit set which is lower than @nth_bit, or -1
166 	 *     if no lower bits are set
167 	 */
168 	public static int bitNthMsf(gulong mask, int nthBit)
169 	{
170 		return g_bit_nth_msf(mask, nthBit);
171 	}
172 
173 	/**
174 	 * Gets the number of bits used to hold @number,
175 	 * e.g. if @number is 4, 3 bits are needed.
176 	 *
177 	 * Params:
178 	 *     number = a #guint
179 	 *
180 	 * Return: the number of bits used to hold @number
181 	 */
182 	public static uint bitStorage(gulong number)
183 	{
184 		return g_bit_storage(number);
185 	}
186 
187 	/**
188 	 * Returns the value of the environment variable @variable in the
189 	 * provided list @envp.
190 	 *
191 	 * Params:
192 	 *     envp = an environment
193 	 *         list (eg, as returned from g_get_environ()), or %NULL
194 	 *         for an empty environment list
195 	 *     variable = the environment variable to get
196 	 *
197 	 * Return: the value of the environment variable, or %NULL if
198 	 *     the environment variable is not set in @envp. The returned
199 	 *     string is owned by @envp, and will be freed if @variable is
200 	 *     set or unset again.
201 	 *
202 	 * Since: 2.32
203 	 */
204 	public static string environGetenv(string[] envp, string variable)
205 	{
206 		return Str.toString(g_environ_getenv(Str.toStringzArray(envp), Str.toStringz(variable)));
207 	}
208 
209 	/**
210 	 * Sets the environment variable @variable in the provided list
211 	 * @envp to @value.
212 	 *
213 	 * Params:
214 	 *     envp = an
215 	 *         environment list that can be freed using g_strfreev() (e.g., as
216 	 *         returned from g_get_environ()), or %NULL for an empty
217 	 *         environment list
218 	 *     variable = the environment variable to set, must not contain '='
219 	 *     value = the value for to set the variable to
220 	 *     overwrite = whether to change the variable if it already exists
221 	 *
222 	 * Return: the
223 	 *     updated environment list. Free it using g_strfreev().
224 	 *
225 	 * Since: 2.32
226 	 */
227 	public static string[] environSetenv(string[] envp, string variable, string value, bool overwrite)
228 	{
229 		return Str.toStringArray(g_environ_setenv(Str.toStringzArray(envp), Str.toStringz(variable), Str.toStringz(value), overwrite));
230 	}
231 
232 	/**
233 	 * Removes the environment variable @variable from the provided
234 	 * environment @envp.
235 	 *
236 	 * Params:
237 	 *     envp = an environment
238 	 *         list that can be freed using g_strfreev() (e.g., as returned from g_get_environ()),
239 	 *         or %NULL for an empty environment list
240 	 *     variable = the environment variable to remove, must not contain '='
241 	 *
242 	 * Return: the
243 	 *     updated environment list. Free it using g_strfreev().
244 	 *
245 	 * Since: 2.32
246 	 */
247 	public static string[] environUnsetenv(string[] envp, string variable)
248 	{
249 		return Str.toStringArray(g_environ_unsetenv(Str.toStringzArray(envp), Str.toStringz(variable)));
250 	}
251 
252 	/**
253 	 * Locates the first executable named @program in the user's path, in the
254 	 * same way that execvp() would locate it. Returns an allocated string
255 	 * with the absolute path name, or %NULL if the program is not found in
256 	 * the path. If @program is already an absolute path, returns a copy of
257 	 * @program if @program exists and is executable, and %NULL otherwise.
258 	 *
259 	 * On Windows, if @program does not have a file type suffix, tries
260 	 * with the suffixes .exe, .cmd, .bat and .com, and the suffixes in
261 	 * the `PATHEXT` environment variable.
262 	 *
263 	 * On Windows, it looks for the file in the same way as CreateProcess()
264 	 * would. This means first in the directory where the executing
265 	 * program was loaded from, then in the current directory, then in the
266 	 * Windows 32-bit system directory, then in the Windows directory, and
267 	 * finally in the directories in the `PATH` environment variable. If
268 	 * the program is found, the return value contains the full name
269 	 * including the type suffix.
270 	 *
271 	 * Params:
272 	 *     program = a program name in the GLib file name encoding
273 	 *
274 	 * Return: a newly-allocated string with the absolute path, or %NULL
275 	 */
276 	public static string findProgramInPath(string program)
277 	{
278 		return Str.toString(g_find_program_in_path(Str.toStringz(program)));
279 	}
280 
281 	/**
282 	 * Formats a size (for example the size of a file) into a human readable
283 	 * string.  Sizes are rounded to the nearest size prefix (kB, MB, GB)
284 	 * and are displayed rounded to the nearest tenth. E.g. the file size
285 	 * 3292528 bytes will be converted into the string "3.2 MB".
286 	 *
287 	 * The prefix units base is 1000 (i.e. 1 kB is 1000 bytes).
288 	 *
289 	 * This string should be freed with g_free() when not needed any longer.
290 	 *
291 	 * See g_format_size_full() for more options about how the size might be
292 	 * formatted.
293 	 *
294 	 * Params:
295 	 *     size = a size in bytes
296 	 *
297 	 * Return: a newly-allocated formatted string containing a human readable
298 	 *     file size
299 	 *
300 	 * Since: 2.30
301 	 */
302 	public static string formatSize(ulong size)
303 	{
304 		return Str.toString(g_format_size(size));
305 	}
306 
307 	/**
308 	 * Formats a size (for example the size of a file) into a human
309 	 * readable string. Sizes are rounded to the nearest size prefix
310 	 * (KB, MB, GB) and are displayed rounded to the nearest tenth.
311 	 * E.g. the file size 3292528 bytes will be converted into the
312 	 * string "3.1 MB".
313 	 *
314 	 * The prefix units base is 1024 (i.e. 1 KB is 1024 bytes).
315 	 *
316 	 * This string should be freed with g_free() when not needed any longer.
317 	 *
318 	 * Deprecated: This function is broken due to its use of SI
319 	 * suffixes to denote IEC units. Use g_format_size() instead.
320 	 *
321 	 * Params:
322 	 *     size = a size in bytes
323 	 *
324 	 * Return: a newly-allocated formatted string containing a human
325 	 *     readable file size
326 	 *
327 	 * Since: 2.16
328 	 */
329 	public static string formatSizeForDisplay(long size)
330 	{
331 		return Str.toString(g_format_size_for_display(size));
332 	}
333 
334 	/**
335 	 * Formats a size.
336 	 *
337 	 * This function is similar to g_format_size() but allows for flags
338 	 * that modify the output. See #GFormatSizeFlags.
339 	 *
340 	 * Params:
341 	 *     size = a size in bytes
342 	 *     flags = #GFormatSizeFlags to modify the output
343 	 *
344 	 * Return: a newly-allocated formatted string containing a human
345 	 *     readable file size
346 	 *
347 	 * Since: 2.30
348 	 */
349 	public static string formatSizeFull(ulong size, GFormatSizeFlags flags)
350 	{
351 		return Str.toString(g_format_size_full(size, flags));
352 	}
353 
354 	/**
355 	 * Gets a human-readable name for the application, as set by
356 	 * g_set_application_name(). This name should be localized if
357 	 * possible, and is intended for display to the user.  Contrast with
358 	 * g_get_prgname(), which gets a non-localized name. If
359 	 * g_set_application_name() has not been called, returns the result of
360 	 * g_get_prgname() (which may be %NULL if g_set_prgname() has also not
361 	 * been called).
362 	 *
363 	 * Return: human-readable application name. may return %NULL
364 	 *
365 	 * Since: 2.2
366 	 */
367 	public static string getApplicationName()
368 	{
369 		return Str.toString(g_get_application_name());
370 	}
371 
372 	/**
373 	 * Gets the list of environment variables for the current process.
374 	 *
375 	 * The list is %NULL terminated and each item in the list is of the
376 	 * form 'NAME=VALUE'.
377 	 *
378 	 * This is equivalent to direct access to the 'environ' global variable,
379 	 * except portable.
380 	 *
381 	 * The return value is freshly allocated and it should be freed with
382 	 * g_strfreev() when it is no longer needed.
383 	 *
384 	 * Return: the list of
385 	 *     environment variables
386 	 *
387 	 * Since: 2.28
388 	 */
389 	public static string[] getEnviron()
390 	{
391 		return Str.toStringArray(g_get_environ());
392 	}
393 
394 	/**
395 	 * Gets the current directory.
396 	 *
397 	 * The returned string should be freed when no longer needed.
398 	 * The encoding of the returned string is system defined.
399 	 * On Windows, it is always UTF-8.
400 	 *
401 	 * Since GLib 2.40, this function will return the value of the "PWD"
402 	 * environment variable if it is set and it happens to be the same as
403 	 * the current directory.  This can make a difference in the case that
404 	 * the current directory is the target of a symbolic link.
405 	 *
406 	 * Return: the current directory
407 	 */
408 	public static string getCurrentDir()
409 	{
410 		return Str.toString(g_get_current_dir());
411 	}
412 
413 	/**
414 	 * Gets the current user's home directory.
415 	 *
416 	 * As with most UNIX tools, this function will return the value of the
417 	 * `HOME` environment variable if it is set to an existing absolute path
418 	 * name, falling back to the `passwd` file in the case that it is unset.
419 	 *
420 	 * If the path given in `HOME` is non-absolute, does not exist, or is
421 	 * not a directory, the result is undefined.
422 	 *
423 	 * Before version 2.36 this function would ignore the `HOME` environment
424 	 * variable, taking the value from the `passwd` database instead. This was
425 	 * changed to increase the compatibility of GLib with other programs (and
426 	 * the XDG basedir specification) and to increase testability of programs
427 	 * based on GLib (by making it easier to run them from test frameworks).
428 	 *
429 	 * If your program has a strong requirement for either the new or the
430 	 * old behaviour (and if you don't wish to increase your GLib
431 	 * dependency to ensure that the new behaviour is in effect) then you
432 	 * should either directly check the `HOME` environment variable yourself
433 	 * or unset it before calling any functions in GLib.
434 	 *
435 	 * Return: the current user's home directory
436 	 */
437 	public static string getHomeDir()
438 	{
439 		return Str.toString(g_get_home_dir());
440 	}
441 
442 	/**
443 	 * Return a name for the machine.
444 	 *
445 	 * The returned name is not necessarily a fully-qualified domain name,
446 	 * or even present in DNS or some other name service at all. It need
447 	 * not even be unique on your local network or site, but usually it
448 	 * is. Callers should not rely on the return value having any specific
449 	 * properties like uniqueness for security purposes. Even if the name
450 	 * of the machine is changed while an application is running, the
451 	 * return value from this function does not change. The returned
452 	 * string is owned by GLib and should not be modified or freed. If no
453 	 * name can be determined, a default fixed string "localhost" is
454 	 * returned.
455 	 *
456 	 * Return: the host name of the machine.
457 	 *
458 	 * Since: 2.8
459 	 */
460 	public static string getHostName()
461 	{
462 		return Str.toString(g_get_host_name());
463 	}
464 
465 	/**
466 	 * Gets the name of the program. This name should not be localized,
467 	 * in contrast to g_get_application_name().
468 	 *
469 	 * If you are using GDK or GTK+ the program name is set in gdk_init(),
470 	 * which is called by gtk_init(). The program name is found by taking
471 	 * the last component of @argv[0].
472 	 *
473 	 * Return: the name of the program. The returned string belongs
474 	 *     to GLib and must not be modified or freed.
475 	 */
476 	public static string getPrgname()
477 	{
478 		return Str.toString(g_get_prgname());
479 	}
480 
481 	/**
482 	 * Gets the real name of the user. This usually comes from the user's
483 	 * entry in the `passwd` file. The encoding of the returned string is
484 	 * system-defined. (On Windows, it is, however, always UTF-8.) If the
485 	 * real user name cannot be determined, the string "Unknown" is
486 	 * returned.
487 	 *
488 	 * Return: the user's real name.
489 	 */
490 	public static string getRealName()
491 	{
492 		return Str.toString(g_get_real_name());
493 	}
494 
495 	/**
496 	 * Returns an ordered list of base directories in which to access
497 	 * system-wide configuration information.
498 	 *
499 	 * On UNIX platforms this is determined using the mechanisms described
500 	 * in the
501 	 * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
502 	 * In this case the list of directories retrieved will be `XDG_CONFIG_DIRS`.
503 	 *
504 	 * On Windows is the directory that contains application data for all users.
505 	 * A typical path is C:\Documents and Settings\All Users\Application Data.
506 	 * This folder is used for application data that is not user specific.
507 	 * For example, an application can store a spell-check dictionary, a database
508 	 * of clip art, or a log file in the CSIDL_COMMON_APPDATA folder.
509 	 * This information will not roam and is available to anyone using the computer.
510 	 *
511 	 * Return: a %NULL-terminated array of strings owned by GLib that must
512 	 *     not be modified or freed.
513 	 *
514 	 * Since: 2.6
515 	 */
516 	public static string[] getSystemConfigDirs()
517 	{
518 		return Str.toStringArray(g_get_system_config_dirs());
519 	}
520 
521 	/**
522 	 * Returns an ordered list of base directories in which to access
523 	 * system-wide application data.
524 	 *
525 	 * On UNIX platforms this is determined using the mechanisms described
526 	 * in the
527 	 * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec)
528 	 * In this case the list of directories retrieved will be XDG_DATA_DIRS.
529 	 *
530 	 * On Windows the first elements in the list are the Application Data
531 	 * and Documents folders for All Users. (These can be determined only
532 	 * on Windows 2000 or later and are not present in the list on other
533 	 * Windows versions.) See documentation for CSIDL_COMMON_APPDATA and
534 	 * CSIDL_COMMON_DOCUMENTS.
535 	 *
536 	 * Then follows the "share" subfolder in the installation folder for
537 	 * the package containing the DLL that calls this function, if it can
538 	 * be determined.
539 	 *
540 	 * Finally the list contains the "share" subfolder in the installation
541 	 * folder for GLib, and in the installation folder for the package the
542 	 * application's .exe file belongs to.
543 	 *
544 	 * The installation folders above are determined by looking up the
545 	 * folder where the module (DLL or EXE) in question is located. If the
546 	 * folder's name is "bin", its parent is used, otherwise the folder
547 	 * itself.
548 	 *
549 	 * Note that on Windows the returned list can vary depending on where
550 	 * this function is called.
551 	 *
552 	 * Return: a %NULL-terminated array of strings owned by GLib that must
553 	 *     not be modified or freed.
554 	 *
555 	 * Since: 2.6
556 	 */
557 	public static string[] getSystemDataDirs()
558 	{
559 		return Str.toStringArray(g_get_system_data_dirs());
560 	}
561 
562 	/**
563 	 * Gets the directory to use for temporary files.
564 	 *
565 	 * On UNIX, this is taken from the `TMPDIR` environment variable.
566 	 * If the variable is not set, `P_tmpdir` is
567 	 * used, as defined by the system C library. Failing that, a
568 	 * hard-coded default of "/tmp" is returned.
569 	 *
570 	 * On Windows, the `TEMP` environment variable is used, with the
571 	 * root directory of the Windows installation (eg: "C:\") used
572 	 * as a default.
573 	 *
574 	 * The encoding of the returned string is system-defined. On Windows,
575 	 * it is always UTF-8. The return value is never %NULL or the empty
576 	 * string.
577 	 *
578 	 * Return: the directory to use for temporary files.
579 	 */
580 	public static string getTmpDir()
581 	{
582 		return Str.toString(g_get_tmp_dir());
583 	}
584 
585 	/**
586 	 * Returns a base directory in which to store non-essential, cached
587 	 * data specific to particular user.
588 	 *
589 	 * On UNIX platforms this is determined using the mechanisms described
590 	 * in the
591 	 * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
592 	 * In this case the directory retrieved will be XDG_CACHE_HOME.
593 	 *
594 	 * On Windows is the directory that serves as a common repository for
595 	 * temporary Internet files. A typical path is
596 	 * C:\Documents and Settings\username\Local Settings\Temporary Internet Files.
597 	 * See documentation for CSIDL_INTERNET_CACHE.
598 	 *
599 	 * Return: a string owned by GLib that must not be modified
600 	 *     or freed.
601 	 *
602 	 * Since: 2.6
603 	 */
604 	public static string getUserCacheDir()
605 	{
606 		return Str.toString(g_get_user_cache_dir());
607 	}
608 
609 	/**
610 	 * Returns a base directory in which to store user-specific application
611 	 * configuration information such as user preferences and settings.
612 	 *
613 	 * On UNIX platforms this is determined using the mechanisms described
614 	 * in the
615 	 * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
616 	 * In this case the directory retrieved will be `XDG_CONFIG_HOME`.
617 	 *
618 	 * On Windows this is the folder to use for local (as opposed to
619 	 * roaming) application data. See documentation for
620 	 * CSIDL_LOCAL_APPDATA. Note that on Windows it thus is the same as
621 	 * what g_get_user_data_dir() returns.
622 	 *
623 	 * Return: a string owned by GLib that must not be modified
624 	 *     or freed.
625 	 *
626 	 * Since: 2.6
627 	 */
628 	public static string getUserConfigDir()
629 	{
630 		return Str.toString(g_get_user_config_dir());
631 	}
632 
633 	/**
634 	 * Returns a base directory in which to access application data such
635 	 * as icons that is customized for a particular user.
636 	 *
637 	 * On UNIX platforms this is determined using the mechanisms described
638 	 * in the
639 	 * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
640 	 * In this case the directory retrieved will be `XDG_DATA_HOME`.
641 	 *
642 	 * On Windows this is the folder to use for local (as opposed to
643 	 * roaming) application data. See documentation for
644 	 * CSIDL_LOCAL_APPDATA. Note that on Windows it thus is the same as
645 	 * what g_get_user_config_dir() returns.
646 	 *
647 	 * Return: a string owned by GLib that must not be modified
648 	 *     or freed.
649 	 *
650 	 * Since: 2.6
651 	 */
652 	public static string getUserDataDir()
653 	{
654 		return Str.toString(g_get_user_data_dir());
655 	}
656 
657 	/**
658 	 * Gets the user name of the current user. The encoding of the returned
659 	 * string is system-defined. On UNIX, it might be the preferred file name
660 	 * encoding, or something else, and there is no guarantee that it is even
661 	 * consistent on a machine. On Windows, it is always UTF-8.
662 	 *
663 	 * Return: the user name of the current user.
664 	 */
665 	public static string getUserName()
666 	{
667 		return Str.toString(g_get_user_name());
668 	}
669 
670 	/**
671 	 * Returns a directory that is unique to the current user on the local
672 	 * system.
673 	 *
674 	 * On UNIX platforms this is determined using the mechanisms described
675 	 * in the
676 	 * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
677 	 * This is the directory
678 	 * specified in the `XDG_RUNTIME_DIR` environment variable.
679 	 * In the case that this variable is not set, GLib will issue a warning
680 	 * message to stderr and return the value of g_get_user_cache_dir().
681 	 *
682 	 * On Windows this is the folder to use for local (as opposed to
683 	 * roaming) application data. See documentation for
684 	 * CSIDL_LOCAL_APPDATA.  Note that on Windows it thus is the same as
685 	 * what g_get_user_config_dir() returns.
686 	 *
687 	 * Return: a string owned by GLib that must not be modified or freed.
688 	 *
689 	 * Since: 2.28
690 	 */
691 	public static string getUserRuntimeDir()
692 	{
693 		return Str.toString(g_get_user_runtime_dir());
694 	}
695 
696 	/**
697 	 * Returns the full path of a special directory using its logical id.
698 	 *
699 	 * On UNIX this is done using the XDG special user directories.
700 	 * For compatibility with existing practise, %G_USER_DIRECTORY_DESKTOP
701 	 * falls back to `$HOME/Desktop` when XDG special user directories have
702 	 * not been set up.
703 	 *
704 	 * Depending on the platform, the user might be able to change the path
705 	 * of the special directory without requiring the session to restart; GLib
706 	 * will not reflect any change once the special directories are loaded.
707 	 *
708 	 * Params:
709 	 *     directory = the logical id of special directory
710 	 *
711 	 * Return: the path to the specified special directory, or %NULL
712 	 *     if the logical id was not found. The returned string is owned by
713 	 *     GLib and should not be modified or freed.
714 	 *
715 	 * Since: 2.14
716 	 */
717 	public static string getUserSpecialDir(GUserDirectory directory)
718 	{
719 		return Str.toString(g_get_user_special_dir(directory));
720 	}
721 
722 	/**
723 	 * Returns the value of an environment variable.
724 	 *
725 	 * On UNIX, the name and value are byte strings which might or might not
726 	 * be in some consistent character set and encoding. On Windows, they are
727 	 * in UTF-8.
728 	 * On Windows, in case the environment variable's value contains
729 	 * references to other environment variables, they are expanded.
730 	 *
731 	 * Params:
732 	 *     variable = the environment variable to get
733 	 *
734 	 * Return: the value of the environment variable, or %NULL if
735 	 *     the environment variable is not found. The returned string
736 	 *     may be overwritten by the next call to g_getenv(), g_setenv()
737 	 *     or g_unsetenv().
738 	 */
739 	public static string getenv(string variable)
740 	{
741 		return Str.toString(g_getenv(Str.toStringz(variable)));
742 	}
743 
744 	/**
745 	 * Gets the names of all variables set in the environment.
746 	 *
747 	 * Programs that want to be portable to Windows should typically use
748 	 * this function and g_getenv() instead of using the environ array
749 	 * from the C library directly. On Windows, the strings in the environ
750 	 * array are in system codepage encoding, while in most of the typical
751 	 * use cases for environment variables in GLib-using programs you want
752 	 * the UTF-8 encoding that this function and g_getenv() provide.
753 	 *
754 	 * Return: a %NULL-terminated
755 	 *     list of strings which must be freed with g_strfreev().
756 	 *
757 	 * Since: 2.8
758 	 */
759 	public static string[] listenv()
760 	{
761 		return Str.toStringArray(g_listenv());
762 	}
763 
764 	/**
765 	 * Set the pointer at the specified location to %NULL.
766 	 *
767 	 * Params:
768 	 *     nullifyLocation = the memory address of the pointer.
769 	 */
770 	public static void nullifyPointer(void** nullifyLocation)
771 	{
772 		g_nullify_pointer(nullifyLocation);
773 	}
774 
775 	/**
776 	 * Parses a string containing debugging options
777 	 * into a %guint containing bit flags. This is used
778 	 * within GDK and GTK+ to parse the debug options passed on the
779 	 * command line or through environment variables.
780 	 *
781 	 * If @string is equal to "all", all flags are set. Any flags
782 	 * specified along with "all" in @string are inverted; thus,
783 	 * "all,foo,bar" or "foo,bar,all" sets all flags except those
784 	 * corresponding to "foo" and "bar".
785 	 *
786 	 * If @string is equal to "help", all the available keys in @keys
787 	 * are printed out to standard error.
788 	 *
789 	 * Params:
790 	 *     str = a list of debug options separated by colons, spaces, or
791 	 *         commas, or %NULL.
792 	 *     keys = pointer to an array of #GDebugKey which associate
793 	 *         strings with bit flags.
794 	 *     nkeys = the number of #GDebugKeys in the array.
795 	 *
796 	 * Return: the combined set of bit flags.
797 	 */
798 	public static uint parseDebugString(string str, GDebugKey[] keys)
799 	{
800 		return g_parse_debug_string(Str.toStringz(str), keys.ptr, cast(uint)keys.length);
801 	}
802 
803 	/**
804 	 * Gets the last component of the filename.
805 	 *
806 	 * If @file_name ends with a directory separator it gets the component
807 	 * before the last slash. If @file_name consists only of directory
808 	 * separators (and on Windows, possibly a drive letter), a single
809 	 * separator is returned. If @file_name is empty, it gets ".".
810 	 *
811 	 * Params:
812 	 *     fileName = the name of the file
813 	 *
814 	 * Return: a newly allocated string containing the last
815 	 *     component of the filename
816 	 */
817 	public static string pathGetBasename(string fileName)
818 	{
819 		return Str.toString(g_path_get_basename(Str.toStringz(fileName)));
820 	}
821 
822 	/**
823 	 * Gets the directory components of a file name.
824 	 *
825 	 * If the file name has no directory components "." is returned.
826 	 * The returned string should be freed when no longer needed.
827 	 *
828 	 * Params:
829 	 *     fileName = the name of the file
830 	 *
831 	 * Return: the directory components of the file
832 	 */
833 	public static string pathGetDirname(string fileName)
834 	{
835 		return Str.toString(g_path_get_dirname(Str.toStringz(fileName)));
836 	}
837 
838 	/**
839 	 * Returns %TRUE if the given @file_name is an absolute file name.
840 	 * Note that this is a somewhat vague concept on Windows.
841 	 *
842 	 * On POSIX systems, an absolute file name is well-defined. It always
843 	 * starts from the single root directory. For example "/usr/local".
844 	 *
845 	 * On Windows, the concepts of current drive and drive-specific
846 	 * current directory introduce vagueness. This function interprets as
847 	 * an absolute file name one that either begins with a directory
848 	 * separator such as "\Users\tml" or begins with the root on a drive,
849 	 * for example "C:\Windows". The first case also includes UNC paths
850 	 * such as "\\myserver\docs\foo". In all cases, either slashes or
851 	 * backslashes are accepted.
852 	 *
853 	 * Note that a file name relative to the current drive root does not
854 	 * truly specify a file uniquely over time and across processes, as
855 	 * the current drive is a per-process value and can be changed.
856 	 *
857 	 * File names relative the current directory on some specific drive,
858 	 * such as "D:foo/bar", are not interpreted as absolute by this
859 	 * function, but they obviously are not relative to the normal current
860 	 * directory as returned by getcwd() or g_get_current_dir()
861 	 * either. Such paths should be avoided, or need to be handled using
862 	 * Windows-specific code.
863 	 *
864 	 * Params:
865 	 *     fileName = a file name
866 	 *
867 	 * Return: %TRUE if @file_name is absolute
868 	 */
869 	public static bool pathIsAbsolute(string fileName)
870 	{
871 		return g_path_is_absolute(Str.toStringz(fileName)) != 0;
872 	}
873 
874 	/**
875 	 * Returns a pointer into @file_name after the root component,
876 	 * i.e. after the "/" in UNIX or "C:\" under Windows. If @file_name
877 	 * is not an absolute path it returns %NULL.
878 	 *
879 	 * Params:
880 	 *     fileName = a file name
881 	 *
882 	 * Return: a pointer into @file_name after the root component
883 	 */
884 	public static string pathSkipRoot(string fileName)
885 	{
886 		return Str.toString(g_path_skip_root(Str.toStringz(fileName)));
887 	}
888 
889 	/**
890 	 * This is just like the standard C qsort() function, but
891 	 * the comparison routine accepts a user data argument.
892 	 *
893 	 * This is guaranteed to be a stable sort since version 2.32.
894 	 *
895 	 * Params:
896 	 *     pbase = start of array to sort
897 	 *     totalElems = elements in the array
898 	 *     size = size of each element
899 	 *     compareFunc = function to compare elements
900 	 *     userData = data to pass to @compare_func
901 	 */
902 	public static void qsortWithData(void* pbase, int totalElems, size_t size, GCompareDataFunc compareFunc, void* userData)
903 	{
904 		g_qsort_with_data(pbase, totalElems, size, compareFunc, userData);
905 	}
906 
907 	/**
908 	 * Resets the cache used for g_get_user_special_dir(), so
909 	 * that the latest on-disk version is used. Call this only
910 	 * if you just changed the data on disk yourself.
911 	 *
912 	 * Due to threadsafety issues this may cause leaking of strings
913 	 * that were previously returned from g_get_user_special_dir()
914 	 * that can't be freed. We ensure to only leak the data for
915 	 * the directories that actually changed value though.
916 	 *
917 	 * Since: 2.22
918 	 */
919 	public static void reloadUserSpecialDirsCache()
920 	{
921 		g_reload_user_special_dirs_cache();
922 	}
923 
924 	/**
925 	 * Sets a human-readable name for the application. This name should be
926 	 * localized if possible, and is intended for display to the user.
927 	 * Contrast with g_set_prgname(), which sets a non-localized name.
928 	 * g_set_prgname() will be called automatically by gtk_init(),
929 	 * but g_set_application_name() will not.
930 	 *
931 	 * Note that for thread safety reasons, this function can only
932 	 * be called once.
933 	 *
934 	 * The application name will be used in contexts such as error messages,
935 	 * or when displaying an application's name in the task list.
936 	 *
937 	 * Params:
938 	 *     applicationName = localized name of the application
939 	 *
940 	 * Since: 2.2
941 	 */
942 	public static void setApplicationName(string applicationName)
943 	{
944 		g_set_application_name(Str.toStringz(applicationName));
945 	}
946 
947 	/**
948 	 * Sets the name of the program. This name should not be localized,
949 	 * in contrast to g_set_application_name().
950 	 *
951 	 * Note that for thread-safety reasons this function can only be called once.
952 	 *
953 	 * Params:
954 	 *     prgname = the name of the program.
955 	 */
956 	public static void setPrgname(string prgname)
957 	{
958 		g_set_prgname(Str.toStringz(prgname));
959 	}
960 
961 	/**
962 	 * Sets an environment variable. On UNIX, both the variable's name and
963 	 * value can be arbitrary byte strings, except that the variable's name
964 	 * cannot contain '='. On Windows, they should be in UTF-8.
965 	 *
966 	 * Note that on some systems, when variables are overwritten, the memory
967 	 * used for the previous variables and its value isn't reclaimed.
968 	 *
969 	 * You should be mindful of the fact that environment variable handling
970 	 * in UNIX is not thread-safe, and your program may crash if one thread
971 	 * calls g_setenv() while another thread is calling getenv(). (And note
972 	 * that many functions, such as gettext(), call getenv() internally.)
973 	 * This function is only safe to use at the very start of your program,
974 	 * before creating any other threads (or creating objects that create
975 	 * worker threads of their own).
976 	 *
977 	 * If you need to set up the environment for a child process, you can
978 	 * use g_get_environ() to get an environment array, modify that with
979 	 * g_environ_setenv() and g_environ_unsetenv(), and then pass that
980 	 * array directly to execvpe(), g_spawn_async(), or the like.
981 	 *
982 	 * Params:
983 	 *     variable = the environment variable to set, must not contain '='.
984 	 *     value = the value for to set the variable to.
985 	 *     overwrite = whether to change the variable if it already exists.
986 	 *
987 	 * Return: %FALSE if the environment variable couldn't be set.
988 	 *
989 	 * Since: 2.4
990 	 */
991 	public static bool setenv(string variable, string value, bool overwrite)
992 	{
993 		return g_setenv(Str.toStringz(variable), Str.toStringz(value), overwrite) != 0;
994 	}
995 
996 	/**
997 	 * Gets the smallest prime number from a built-in array of primes which
998 	 * is larger than @num. This is used within GLib to calculate the optimum
999 	 * size of a #GHashTable.
1000 	 *
1001 	 * The built-in array of primes ranges from 11 to 13845163 such that
1002 	 * each prime is approximately 1.5-2 times the previous prime.
1003 	 *
1004 	 * Params:
1005 	 *     num = a #guint
1006 	 *
1007 	 * Return: the smallest prime number from a built-in array of primes
1008 	 *     which is larger than @num
1009 	 */
1010 	public static uint spacedPrimesClosest(uint num)
1011 	{
1012 		return g_spaced_primes_closest(num);
1013 	}
1014 
1015 	/**
1016 	 * Removes an environment variable from the environment.
1017 	 *
1018 	 * Note that on some systems, when variables are overwritten, the
1019 	 * memory used for the previous variables and its value isn't reclaimed.
1020 	 *
1021 	 * You should be mindful of the fact that environment variable handling
1022 	 * in UNIX is not thread-safe, and your program may crash if one thread
1023 	 * calls g_unsetenv() while another thread is calling getenv(). (And note
1024 	 * that many functions, such as gettext(), call getenv() internally.) This
1025 	 * function is only safe to use at the very start of your program, before
1026 	 * creating any other threads (or creating objects that create worker
1027 	 * threads of their own).
1028 	 *
1029 	 * If you need to set up the environment for a child process, you can
1030 	 * use g_get_environ() to get an environment array, modify that with
1031 	 * g_environ_setenv() and g_environ_unsetenv(), and then pass that
1032 	 * array directly to execvpe(), g_spawn_async(), or the like.
1033 	 *
1034 	 * Params:
1035 	 *     variable = the environment variable to remove, must not contain '='
1036 	 *
1037 	 * Since: 2.4
1038 	 */
1039 	public static void unsetenv(string variable)
1040 	{
1041 		g_unsetenv(Str.toStringz(variable));
1042 	}
1043 }