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