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 	 * Returns: 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 	 * Returns: 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 	 * Returns: 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 	 * Returns: 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 	 * 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
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 	 * Returns: 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 		auto retStr = g_environ_setenv(Str.toStringzArray(envp), Str.toStringz(variable), Str.toStringz(value), overwrite);
230 		
231 		scope(exit) Str.freeStringArray(retStr);
232 		return Str.toStringArray(retStr);
233 	}
234 
235 	/**
236 	 * Removes the environment variable @variable from the provided
237 	 * environment @envp.
238 	 *
239 	 * Params:
240 	 *     envp = an environment
241 	 *         list that can be freed using g_strfreev() (e.g., as returned from g_get_environ()),
242 	 *         or %NULL for an empty environment list
243 	 *     variable = the environment variable to remove, must not contain '='
244 	 *
245 	 * Returns: the
246 	 *     updated environment list. Free it using g_strfreev().
247 	 *
248 	 * Since: 2.32
249 	 */
250 	public static string[] environUnsetenv(string[] envp, string variable)
251 	{
252 		auto retStr = g_environ_unsetenv(Str.toStringzArray(envp), Str.toStringz(variable));
253 		
254 		scope(exit) Str.freeStringArray(retStr);
255 		return Str.toStringArray(retStr);
256 	}
257 
258 	/**
259 	 * Locates the first executable named @program in the user's path, in the
260 	 * same way that execvp() would locate it. Returns an allocated string
261 	 * with the absolute path name, or %NULL if the program is not found in
262 	 * the path. If @program is already an absolute path, returns a copy of
263 	 * @program if @program exists and is executable, and %NULL otherwise.
264 	 *
265 	 * On Windows, if @program does not have a file type suffix, tries
266 	 * with the suffixes .exe, .cmd, .bat and .com, and the suffixes in
267 	 * the `PATHEXT` environment variable.
268 	 *
269 	 * On Windows, it looks for the file in the same way as CreateProcess()
270 	 * would. This means first in the directory where the executing
271 	 * program was loaded from, then in the current directory, then in the
272 	 * Windows 32-bit system directory, then in the Windows directory, and
273 	 * finally in the directories in the `PATH` environment variable. If
274 	 * the program is found, the return value contains the full name
275 	 * including the type suffix.
276 	 *
277 	 * Params:
278 	 *     program = a program name in the GLib file name encoding
279 	 *
280 	 * Returns: a newly-allocated string with the absolute path,
281 	 *     or %NULL
282 	 */
283 	public static string findProgramInPath(string program)
284 	{
285 		auto retStr = g_find_program_in_path(Str.toStringz(program));
286 		
287 		scope(exit) Str.freeString(retStr);
288 		return Str.toString(retStr);
289 	}
290 
291 	/**
292 	 * Formats a size (for example the size of a file) into a human readable
293 	 * string.  Sizes are rounded to the nearest size prefix (kB, MB, GB)
294 	 * and are displayed rounded to the nearest tenth. E.g. the file size
295 	 * 3292528 bytes will be converted into the string "3.2 MB".
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 a human readable
308 	 *     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 containing a human
338 	 *     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 containing a human
361 	 *     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 name. may return %NULL
383 	 *
384 	 * Since: 2.2
385 	 */
386 	public static string getApplicationName()
387 	{
388 		return Str.toString(g_get_application_name());
389 	}
390 
391 	/**
392 	 * Gets the list of environment variables for the current process.
393 	 *
394 	 * The list is %NULL terminated and each item in the list is of the
395 	 * form 'NAME=VALUE'.
396 	 *
397 	 * This is equivalent to direct access to the 'environ' global variable,
398 	 * except portable.
399 	 *
400 	 * The return value is freshly allocated and it should be freed with
401 	 * g_strfreev() when it is no longer needed.
402 	 *
403 	 * Returns: the list of
404 	 *     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 	 * Returns: the host name of the machine.
482 	 *
483 	 * Since: 2.8
484 	 */
485 	public static string getHostName()
486 	{
487 		return Str.toString(g_get_host_name());
488 	}
489 
490 	/**
491 	 * Gets the name of the program. This name should not be localized,
492 	 * in contrast to g_get_application_name().
493 	 *
494 	 * If you are using GDK or GTK+ the program name is set in gdk_init(),
495 	 * which is called by gtk_init(). The program name is found by taking
496 	 * the last component of @argv[0].
497 	 *
498 	 * Returns: the name of the program. The returned string belongs
499 	 *     to GLib and must not be modified or freed.
500 	 */
501 	public static string getPrgname()
502 	{
503 		return Str.toString(g_get_prgname());
504 	}
505 
506 	/**
507 	 * Gets the real name of the user. This usually comes from the user's
508 	 * entry in the `passwd` file. The encoding of the returned string is
509 	 * system-defined. (On Windows, it is, however, always UTF-8.) If the
510 	 * real user name cannot be determined, the string "Unknown" is
511 	 * returned.
512 	 *
513 	 * Returns: the user's real name.
514 	 */
515 	public static string getRealName()
516 	{
517 		return Str.toString(g_get_real_name());
518 	}
519 
520 	/**
521 	 * Returns an ordered list of base directories in which to access
522 	 * system-wide configuration information.
523 	 *
524 	 * On UNIX platforms this is determined using the mechanisms described
525 	 * in the
526 	 * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
527 	 * In this case the list of directories retrieved will be `XDG_CONFIG_DIRS`.
528 	 *
529 	 * On Windows is the directory that contains application data for all users.
530 	 * A typical path is C:\Documents and Settings\All Users\Application Data.
531 	 * This folder is used for application data that is not user specific.
532 	 * For example, an application can store a spell-check dictionary, a database
533 	 * of clip art, or a log file in the CSIDL_COMMON_APPDATA folder.
534 	 * This information will not roam and is available to anyone using the computer.
535 	 *
536 	 * Returns: a %NULL-terminated array of strings owned by GLib that must not be
537 	 *     modified or freed.
538 	 *
539 	 * Since: 2.6
540 	 */
541 	public static string[] getSystemConfigDirs()
542 	{
543 		return Str.toStringArray(g_get_system_config_dirs());
544 	}
545 
546 	/**
547 	 * Returns an ordered list of base directories in which to access
548 	 * system-wide application data.
549 	 *
550 	 * On UNIX platforms this is determined using the mechanisms described
551 	 * in the
552 	 * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec)
553 	 * In this case the list of directories retrieved will be XDG_DATA_DIRS.
554 	 *
555 	 * On Windows the first elements in the list are the Application Data
556 	 * and Documents folders for All Users. (These can be determined only
557 	 * on Windows 2000 or later and are not present in the list on other
558 	 * Windows versions.) See documentation for CSIDL_COMMON_APPDATA and
559 	 * CSIDL_COMMON_DOCUMENTS.
560 	 *
561 	 * Then follows the "share" subfolder in the installation folder for
562 	 * the package containing the DLL that calls this function, if it can
563 	 * be determined.
564 	 *
565 	 * Finally the list contains the "share" subfolder in the installation
566 	 * folder for GLib, and in the installation folder for the package the
567 	 * application's .exe file belongs to.
568 	 *
569 	 * The installation folders above are determined by looking up the
570 	 * folder where the module (DLL or EXE) in question is located. If the
571 	 * folder's name is "bin", its parent is used, otherwise the folder
572 	 * itself.
573 	 *
574 	 * Note that on Windows the returned list can vary depending on where
575 	 * this function is called.
576 	 *
577 	 * Returns: a %NULL-terminated array of strings owned by GLib that must not be
578 	 *     modified or freed.
579 	 *
580 	 * Since: 2.6
581 	 */
582 	public static string[] getSystemDataDirs()
583 	{
584 		return Str.toStringArray(g_get_system_data_dirs());
585 	}
586 
587 	/**
588 	 * Gets the directory to use for temporary files.
589 	 *
590 	 * On UNIX, this is taken from the `TMPDIR` environment variable.
591 	 * If the variable is not set, `P_tmpdir` is
592 	 * used, as defined by the system C library. Failing that, a
593 	 * hard-coded default of "/tmp" is returned.
594 	 *
595 	 * On Windows, the `TEMP` environment variable is used, with the
596 	 * root directory of the Windows installation (eg: "C:\") used
597 	 * as a default.
598 	 *
599 	 * The encoding of the returned string is system-defined. On Windows,
600 	 * it is always UTF-8. The return value is never %NULL or the empty
601 	 * string.
602 	 *
603 	 * Returns: the directory to use for temporary files.
604 	 */
605 	public static string getTmpDir()
606 	{
607 		return Str.toString(g_get_tmp_dir());
608 	}
609 
610 	/**
611 	 * Returns a base directory in which to store non-essential, cached
612 	 * data specific to particular user.
613 	 *
614 	 * On UNIX platforms this is determined using the mechanisms described
615 	 * in the
616 	 * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
617 	 * In this case the directory retrieved will be XDG_CACHE_HOME.
618 	 *
619 	 * On Windows is the directory that serves as a common repository for
620 	 * temporary Internet files. A typical path is
621 	 * C:\Documents and Settings\username\Local Settings\Temporary Internet Files.
622 	 * See documentation for CSIDL_INTERNET_CACHE.
623 	 *
624 	 * Returns: a string owned by GLib that must not be modified
625 	 *     or freed.
626 	 *
627 	 * Since: 2.6
628 	 */
629 	public static string getUserCacheDir()
630 	{
631 		return Str.toString(g_get_user_cache_dir());
632 	}
633 
634 	/**
635 	 * Returns a base directory in which to store user-specific application
636 	 * configuration information such as user preferences and settings.
637 	 *
638 	 * On UNIX platforms this is determined using the mechanisms described
639 	 * in the
640 	 * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
641 	 * In this case the directory retrieved will be `XDG_CONFIG_HOME`.
642 	 *
643 	 * On Windows this is the folder to use for local (as opposed to
644 	 * roaming) application data. See documentation for
645 	 * CSIDL_LOCAL_APPDATA. Note that on Windows it thus is the same as
646 	 * what g_get_user_data_dir() returns.
647 	 *
648 	 * Returns: a string owned by GLib that must not be modified
649 	 *     or freed.
650 	 *
651 	 * Since: 2.6
652 	 */
653 	public static string getUserConfigDir()
654 	{
655 		return Str.toString(g_get_user_config_dir());
656 	}
657 
658 	/**
659 	 * Returns a base directory in which to access application data such
660 	 * as icons that is customized for a particular user.
661 	 *
662 	 * On UNIX platforms this is determined using the mechanisms described
663 	 * in the
664 	 * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
665 	 * In this case the directory retrieved will be `XDG_DATA_HOME`.
666 	 *
667 	 * On Windows this is the folder to use for local (as opposed to
668 	 * roaming) application data. See documentation for
669 	 * CSIDL_LOCAL_APPDATA. Note that on Windows it thus is the same as
670 	 * what g_get_user_config_dir() returns.
671 	 *
672 	 * Returns: a string owned by GLib that must not be modified
673 	 *     or freed.
674 	 *
675 	 * Since: 2.6
676 	 */
677 	public static string getUserDataDir()
678 	{
679 		return Str.toString(g_get_user_data_dir());
680 	}
681 
682 	/**
683 	 * Gets the user name of the current user. The encoding of the returned
684 	 * string is system-defined. On UNIX, it might be the preferred file name
685 	 * encoding, or something else, and there is no guarantee that it is even
686 	 * consistent on a machine. On Windows, it is always UTF-8.
687 	 *
688 	 * Returns: the user name of the current user.
689 	 */
690 	public static string getUserName()
691 	{
692 		return Str.toString(g_get_user_name());
693 	}
694 
695 	/**
696 	 * Returns a directory that is unique to the current user on the local
697 	 * system.
698 	 *
699 	 * On UNIX platforms this is determined using the mechanisms described
700 	 * in the
701 	 * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
702 	 * This is the directory
703 	 * specified in the `XDG_RUNTIME_DIR` environment variable.
704 	 * In the case that this variable is not set, we return the value of
705 	 * g_get_user_cache_dir(), after verifying that it exists.
706 	 *
707 	 * On Windows this is the folder to use for local (as opposed to
708 	 * roaming) application data. See documentation for
709 	 * CSIDL_LOCAL_APPDATA.  Note that on Windows it thus is the same as
710 	 * what g_get_user_config_dir() returns.
711 	 *
712 	 * Returns: a string owned by GLib that must not be
713 	 *     modified or freed.
714 	 *
715 	 * Since: 2.28
716 	 */
717 	public static string getUserRuntimeDir()
718 	{
719 		return Str.toString(g_get_user_runtime_dir());
720 	}
721 
722 	/**
723 	 * Returns the full path of a special directory using its logical id.
724 	 *
725 	 * On UNIX this is done using the XDG special user directories.
726 	 * For compatibility with existing practise, %G_USER_DIRECTORY_DESKTOP
727 	 * falls back to `$HOME/Desktop` when XDG special user directories have
728 	 * not been set up.
729 	 *
730 	 * Depending on the platform, the user might be able to change the path
731 	 * of the special directory without requiring the session to restart; GLib
732 	 * will not reflect any change once the special directories are loaded.
733 	 *
734 	 * Params:
735 	 *     directory = the logical id of special directory
736 	 *
737 	 * Returns: the path to the specified special directory, or
738 	 *     %NULL if the logical id was not found. The returned string is owned by
739 	 *     GLib and should not be modified or freed.
740 	 *
741 	 * Since: 2.14
742 	 */
743 	public static string getUserSpecialDir(GUserDirectory directory)
744 	{
745 		return Str.toString(g_get_user_special_dir(directory));
746 	}
747 
748 	/**
749 	 * Returns the value of an environment variable.
750 	 *
751 	 * On UNIX, the name and value are byte strings which might or might not
752 	 * be in some consistent character set and encoding. On Windows, they are
753 	 * in UTF-8.
754 	 * On Windows, in case the environment variable's value contains
755 	 * references to other environment variables, they are expanded.
756 	 *
757 	 * Params:
758 	 *     variable = the environment variable to get
759 	 *
760 	 * Returns: the value of the environment variable, or %NULL if
761 	 *     the environment variable is not found. The returned string
762 	 *     may be overwritten by the next call to g_getenv(), g_setenv()
763 	 *     or g_unsetenv().
764 	 */
765 	public static string getenv(string variable)
766 	{
767 		return Str.toString(g_getenv(Str.toStringz(variable)));
768 	}
769 
770 	/**
771 	 * Gets the names of all variables set in the environment.
772 	 *
773 	 * Programs that want to be portable to Windows should typically use
774 	 * this function and g_getenv() instead of using the environ array
775 	 * from the C library directly. On Windows, the strings in the environ
776 	 * array are in system codepage encoding, while in most of the typical
777 	 * use cases for environment variables in GLib-using programs you want
778 	 * the UTF-8 encoding that this function and g_getenv() provide.
779 	 *
780 	 * Returns: a %NULL-terminated
781 	 *     list of strings which must be freed with g_strfreev().
782 	 *
783 	 * Since: 2.8
784 	 */
785 	public static string[] listenv()
786 	{
787 		auto retStr = g_listenv();
788 		
789 		scope(exit) Str.freeStringArray(retStr);
790 		return Str.toStringArray(retStr);
791 	}
792 
793 	/**
794 	 * Set the pointer at the specified location to %NULL.
795 	 *
796 	 * Params:
797 	 *     nullifyLocation = the memory address of the pointer.
798 	 */
799 	public static void nullifyPointer(void** nullifyLocation)
800 	{
801 		g_nullify_pointer(nullifyLocation);
802 	}
803 
804 	/**
805 	 * Parses a string containing debugging options
806 	 * into a %guint containing bit flags. This is used
807 	 * within GDK and GTK+ to parse the debug options passed on the
808 	 * command line or through environment variables.
809 	 *
810 	 * If @string is equal to "all", all flags are set. Any flags
811 	 * specified along with "all" in @string are inverted; thus,
812 	 * "all,foo,bar" or "foo,bar,all" sets all flags except those
813 	 * corresponding to "foo" and "bar".
814 	 *
815 	 * If @string is equal to "help", all the available keys in @keys
816 	 * are printed out to standard error.
817 	 *
818 	 * Params:
819 	 *     str = a list of debug options separated by colons, spaces, or
820 	 *         commas, or %NULL.
821 	 *     keys = pointer to an array of #GDebugKey which associate
822 	 *         strings with bit flags.
823 	 *     nkeys = the number of #GDebugKeys in the array.
824 	 *
825 	 * Returns: the combined set of bit flags.
826 	 */
827 	public static uint parseDebugString(string str, GDebugKey[] keys)
828 	{
829 		return g_parse_debug_string(Str.toStringz(str), keys.ptr, cast(uint)keys.length);
830 	}
831 
832 	/**
833 	 * Gets the last component of the filename.
834 	 *
835 	 * If @file_name ends with a directory separator it gets the component
836 	 * before the last slash. If @file_name consists only of directory
837 	 * separators (and on Windows, possibly a drive letter), a single
838 	 * separator is returned. If @file_name is empty, it gets ".".
839 	 *
840 	 * Params:
841 	 *     fileName = the name of the file
842 	 *
843 	 * Returns: a newly allocated string containing the last
844 	 *     component of the filename
845 	 */
846 	public static string pathGetBasename(string fileName)
847 	{
848 		auto retStr = g_path_get_basename(Str.toStringz(fileName));
849 		
850 		scope(exit) Str.freeString(retStr);
851 		return Str.toString(retStr);
852 	}
853 
854 	/**
855 	 * Gets the directory components of a file name.
856 	 *
857 	 * If the file name has no directory components "." is returned.
858 	 * The returned string should be freed when no longer needed.
859 	 *
860 	 * Params:
861 	 *     fileName = the name of the file
862 	 *
863 	 * Returns: the directory components of the file
864 	 */
865 	public static string pathGetDirname(string fileName)
866 	{
867 		auto retStr = g_path_get_dirname(Str.toStringz(fileName));
868 		
869 		scope(exit) Str.freeString(retStr);
870 		return Str.toString(retStr);
871 	}
872 
873 	/**
874 	 * Returns %TRUE if the given @file_name is an absolute file name.
875 	 * Note that this is a somewhat vague concept on Windows.
876 	 *
877 	 * On POSIX systems, an absolute file name is well-defined. It always
878 	 * starts from the single root directory. For example "/usr/local".
879 	 *
880 	 * On Windows, the concepts of current drive and drive-specific
881 	 * current directory introduce vagueness. This function interprets as
882 	 * an absolute file name one that either begins with a directory
883 	 * separator such as "\Users\tml" or begins with the root on a drive,
884 	 * for example "C:\Windows". The first case also includes UNC paths
885 	 * such as "\\myserver\docs\foo". In all cases, either slashes or
886 	 * backslashes are accepted.
887 	 *
888 	 * Note that a file name relative to the current drive root does not
889 	 * truly specify a file uniquely over time and across processes, as
890 	 * the current drive is a per-process value and can be changed.
891 	 *
892 	 * File names relative the current directory on some specific drive,
893 	 * such as "D:foo/bar", are not interpreted as absolute by this
894 	 * function, but they obviously are not relative to the normal current
895 	 * directory as returned by getcwd() or g_get_current_dir()
896 	 * either. Such paths should be avoided, or need to be handled using
897 	 * Windows-specific code.
898 	 *
899 	 * Params:
900 	 *     fileName = a file name
901 	 *
902 	 * Returns: %TRUE if @file_name is absolute
903 	 */
904 	public static bool pathIsAbsolute(string fileName)
905 	{
906 		return g_path_is_absolute(Str.toStringz(fileName)) != 0;
907 	}
908 
909 	/**
910 	 * Returns a pointer into @file_name after the root component,
911 	 * i.e. after the "/" in UNIX or "C:\" under Windows. If @file_name
912 	 * is not an absolute path it returns %NULL.
913 	 *
914 	 * Params:
915 	 *     fileName = a file name
916 	 *
917 	 * Returns: a pointer into @file_name after the
918 	 *     root component
919 	 */
920 	public static string pathSkipRoot(string fileName)
921 	{
922 		return Str.toString(g_path_skip_root(Str.toStringz(fileName)));
923 	}
924 
925 	/**
926 	 * This is just like the standard C qsort() function, but
927 	 * the comparison routine accepts a user data argument.
928 	 *
929 	 * This is guaranteed to be a stable sort since version 2.32.
930 	 *
931 	 * Params:
932 	 *     pbase = start of array to sort
933 	 *     totalElems = elements in the array
934 	 *     size = size of each element
935 	 *     compareFunc = function to compare elements
936 	 *     userData = data to pass to @compare_func
937 	 */
938 	public static void qsortWithData(void* pbase, int totalElems, size_t size, GCompareDataFunc compareFunc, void* userData)
939 	{
940 		g_qsort_with_data(pbase, totalElems, size, compareFunc, userData);
941 	}
942 
943 	/**
944 	 * Resets the cache used for g_get_user_special_dir(), so
945 	 * that the latest on-disk version is used. Call this only
946 	 * if you just changed the data on disk yourself.
947 	 *
948 	 * Due to threadsafety issues this may cause leaking of strings
949 	 * that were previously returned from g_get_user_special_dir()
950 	 * that can't be freed. We ensure to only leak the data for
951 	 * the directories that actually changed value though.
952 	 *
953 	 * Since: 2.22
954 	 */
955 	public static void reloadUserSpecialDirsCache()
956 	{
957 		g_reload_user_special_dirs_cache();
958 	}
959 
960 	/**
961 	 * Sets a human-readable name for the application. This name should be
962 	 * localized if possible, and is intended for display to the user.
963 	 * Contrast with g_set_prgname(), which sets a non-localized name.
964 	 * g_set_prgname() will be called automatically by gtk_init(),
965 	 * but g_set_application_name() will not.
966 	 *
967 	 * Note that for thread safety reasons, this function can only
968 	 * be called once.
969 	 *
970 	 * The application name will be used in contexts such as error messages,
971 	 * or when displaying an application's name in the task list.
972 	 *
973 	 * Params:
974 	 *     applicationName = localized name of the application
975 	 *
976 	 * Since: 2.2
977 	 */
978 	public static void setApplicationName(string applicationName)
979 	{
980 		g_set_application_name(Str.toStringz(applicationName));
981 	}
982 
983 	/**
984 	 * Sets the name of the program. This name should not be localized,
985 	 * in contrast to g_set_application_name().
986 	 *
987 	 * Note that for thread-safety reasons this function can only be called once.
988 	 *
989 	 * Params:
990 	 *     prgname = the name of the program.
991 	 */
992 	public static void setPrgname(string prgname)
993 	{
994 		g_set_prgname(Str.toStringz(prgname));
995 	}
996 
997 	/**
998 	 * Sets an environment variable. On UNIX, both the variable's name and
999 	 * value can be arbitrary byte strings, except that the variable's name
1000 	 * cannot contain '='. On Windows, they should be in UTF-8.
1001 	 *
1002 	 * Note that on some systems, when variables are overwritten, the memory
1003 	 * used for the previous variables and its value isn't reclaimed.
1004 	 *
1005 	 * You should be mindful of the fact that environment variable handling
1006 	 * in UNIX is not thread-safe, and your program may crash if one thread
1007 	 * calls g_setenv() while another thread is calling getenv(). (And note
1008 	 * that many functions, such as gettext(), call getenv() internally.)
1009 	 * This function is only safe to use at the very start of your program,
1010 	 * before creating any other threads (or creating objects that create
1011 	 * worker threads of their own).
1012 	 *
1013 	 * If you need to set up the environment for a child process, you can
1014 	 * use g_get_environ() to get an environment array, modify that with
1015 	 * g_environ_setenv() and g_environ_unsetenv(), and then pass that
1016 	 * array directly to execvpe(), g_spawn_async(), or the like.
1017 	 *
1018 	 * Params:
1019 	 *     variable = the environment variable to set, must not contain '='.
1020 	 *     value = the value for to set the variable to.
1021 	 *     overwrite = whether to change the variable if it already exists.
1022 	 *
1023 	 * Returns: %FALSE if the environment variable couldn't be set.
1024 	 *
1025 	 * Since: 2.4
1026 	 */
1027 	public static bool setenv(string variable, string value, bool overwrite)
1028 	{
1029 		return g_setenv(Str.toStringz(variable), Str.toStringz(value), overwrite) != 0;
1030 	}
1031 
1032 	/**
1033 	 * Gets the smallest prime number from a built-in array of primes which
1034 	 * is larger than @num. This is used within GLib to calculate the optimum
1035 	 * size of a #GHashTable.
1036 	 *
1037 	 * The built-in array of primes ranges from 11 to 13845163 such that
1038 	 * each prime is approximately 1.5-2 times the previous prime.
1039 	 *
1040 	 * Params:
1041 	 *     num = a #guint
1042 	 *
1043 	 * Returns: the smallest prime number from a built-in array of primes
1044 	 *     which is larger than @num
1045 	 */
1046 	public static uint spacedPrimesClosest(uint num)
1047 	{
1048 		return g_spaced_primes_closest(num);
1049 	}
1050 
1051 	/**
1052 	 * Removes an environment variable from the environment.
1053 	 *
1054 	 * Note that on some systems, when variables are overwritten, the
1055 	 * memory used for the previous variables and its value isn't reclaimed.
1056 	 *
1057 	 * You should be mindful of the fact that environment variable handling
1058 	 * in UNIX is not thread-safe, and your program may crash if one thread
1059 	 * calls g_unsetenv() while another thread is calling getenv(). (And note
1060 	 * that many functions, such as gettext(), call getenv() internally.) This
1061 	 * function is only safe to use at the very start of your program, before
1062 	 * creating any other threads (or creating objects that create worker
1063 	 * threads of their own).
1064 	 *
1065 	 * If you need to set up the environment for a child process, you can
1066 	 * use g_get_environ() to get an environment array, modify that with
1067 	 * g_environ_setenv() and g_environ_unsetenv(), and then pass that
1068 	 * array directly to execvpe(), g_spawn_async(), or the like.
1069 	 *
1070 	 * Params:
1071 	 *     variable = the environment variable to remove, must not contain '='
1072 	 *
1073 	 * Since: 2.4
1074 	 */
1075 	public static void unsetenv(string variable)
1076 	{
1077 		g_unsetenv(Str.toStringz(variable));
1078 	}
1079 }