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