2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = glib-Miscellaneous-Utility-Functions.html
58 import tango
.io
.Stdout
; // use the tango loging?
62 private import gtkc
.glibtypes
;
64 private import gtkc
.glib
;
67 private import glib
.ListG
;
68 private import glib
.Str
;
75 * These are portable utility functions.
84 * Gets a human-readable name for the application, as set by
85 * g_set_application_name(). This name should be localized if
86 * possible, and is intended for display to the user. Contrast with
87 * g_get_prgname(), which gets a non-localized name. If
88 * g_set_application_name() has not been called, returns the result of
89 * g_get_prgname() (which may be NULL if g_set_prgname() has also not
92 * human-readable application name. may return NULL
95 public static char[] getApplicationName()
97 // const gchar* g_get_application_name (void);
98 return Str
.toString(g_get_application_name() );
102 * Sets a human-readable name for the application. This name should be
103 * localized if possible, and is intended for display to the user.
104 * Contrast with g_set_prgname(), which sets a non-localized name.
105 * g_set_prgname() will be called automatically by gtk_init(),
106 * but g_set_application_name() will not.
107 * Note that for thread safety reasons, this function can only
109 * The application name will be used in contexts such as error messages,
110 * or when displaying an application's name in the task list.
112 * localized name of the application
114 public static void setApplicationName(char[] applicationName
)
116 // void g_set_application_name (const gchar *application_name);
117 g_set_application_name(Str
.toStringz(applicationName
));
121 * Gets the name of the program. This name should not
122 * be localized, contrast with g_get_application_name().
123 * (If you are using GDK or GTK+ the program name is set in gdk_init(),
124 * which is called by gtk_init(). The program name is found by taking
125 * the last component of argv[0].)
127 * the name of the program. The returned string belongs
128 * to GLib and must not be modified or freed.
130 public static char[] getPrgname()
132 // gchar* g_get_prgname (void);
133 return Str
.toString(g_get_prgname() );
137 * Sets the name of the program. This name should not
138 * be localized, contrast with g_set_application_name(). Note that for
139 * thread-safety reasons this function can only be called once.
141 * the name of the program.
143 public static void setPrgname(char[] prgname
)
145 // void g_set_prgname (const gchar *prgname);
146 g_set_prgname(Str
.toStringz(prgname
));
150 * Returns the value of an environment variable. The name and value
151 * are in the GLib file name encoding. On UNIX, this means the actual
152 * bytes which might or might not be in some consistent character set
153 * and encoding. On Windows, it is in UTF-8. On Windows, in case the
154 * environment variable's value contains references to other
155 * environment variables, they are expanded.
157 * the environment variable to get, in the GLib file name encoding.
159 * the value of the environment variable, or NULL if
160 * the environment variable is not found. The returned string may be
161 * overwritten by the next call to g_getenv(), g_setenv() or
164 public static char[] getenv(char[] variable
)
166 // const gchar* g_getenv (const gchar *variable);
167 return Str
.toString(g_getenv(Str
.toStringz(variable
)) );
171 * Sets an environment variable. Both the variable's name and value
172 * should be in the GLib file name encoding. On UNIX, this means that
173 * they can be any sequence of bytes. On Windows, they should be in
175 * Note that on some systems, when variables are overwritten, the memory
176 * used for the previous variables and its value isn't reclaimed.
178 * the environment variable to set, must not contain '='.
180 * the value for to set the variable to.
182 * whether to change the variable if it already exists.
184 * FALSE if the environment variable couldn't be set.
187 public static int setenv(char[] variable
, char[] value
, int overwrite
)
189 // gboolean g_setenv (const gchar *variable, const gchar *value, gboolean overwrite);
190 return g_setenv(Str
.toStringz(variable
), Str
.toStringz(value
), overwrite
);
194 * Removes an environment variable from the environment.
195 * Note that on some systems, when variables are overwritten, the memory
196 * used for the previous variables and its value isn't reclaimed.
197 * Furthermore, this function can't be guaranteed to operate in a
200 * the environment variable to remove, must not contain '='.
203 public static void unsetenv(char[] variable
)
205 // void g_unsetenv (const gchar *variable);
206 g_unsetenv(Str
.toStringz(variable
));
210 * Gets the names of all variables set in the environment.
212 * a NULL-terminated list of strings which must be freed
214 * Programs that want to be portable to Windows should typically use
215 * this function and g_getenv() instead of using the environ array
216 * from the C library directly. On Windows, the strings in the environ
217 * array are in system codepage encoding, while in most of the typical
218 * use cases for environment variables in GLib-using programs you want
219 * the UTF-8 encoding that this function and g_getenv() provide.
222 public static char** listenv()
224 // gchar** g_listenv (void);
229 * Gets the user name of the current user. The encoding of the returned
230 * string is system-defined. On UNIX, it might be the preferred file name
231 * encoding, or something else, and there is no guarantee that it is even
232 * consistent on a machine. On Windows, it is always UTF-8.
234 * the user name of the current user.
236 public static char[] getUserName()
238 // const gchar* g_get_user_name (void);
239 return Str
.toString(g_get_user_name() );
243 * Gets the real name of the user. This usually comes from the user's entry
244 * in the passwd file. The encoding of the returned
245 * string is system-defined. (On Windows, it is, however, always UTF-8.)
246 * If the real user name cannot be determined, the string "Unknown" is
249 * the user's real name.
251 public static char[] getRealName()
253 // const gchar* g_get_real_name (void);
254 return Str
.toString(g_get_real_name() );
258 * Returns a base directory in which to store non-essential, cached
259 * data specific to particular user.
260 * On UNIX platforms this is determined using the mechanisms described in
262 * XDG Base Directory Specification
264 * a string owned by GLib that must not be modified
268 public static char[] getUserCacheDir()
270 // const gchar* g_get_user_cache_dir (void);
271 return Str
.toString(g_get_user_cache_dir() );
275 * Returns a base directory in which to access application data such
276 * as icons that is customized for a particular user.
277 * On UNIX platforms this is determined using the mechanisms described in
279 * XDG Base Directory Specification
281 * a string owned by GLib that must not be modified
285 public static char[] getUserDataDir()
287 // const gchar* g_get_user_data_dir (void);
288 return Str
.toString(g_get_user_data_dir() );
292 * Returns a base directory in which to store user-specific application
293 * configuration information such as user preferences and settings.
294 * On UNIX platforms this is determined using the mechanisms described in
296 * XDG Base Directory Specification
298 * a string owned by GLib that must not be modified
302 public static char[] getUserConfigDir()
304 // const gchar* g_get_user_config_dir (void);
305 return Str
.toString(g_get_user_config_dir() );
309 * Returns an ordered list of base directories in which to access
310 * system-wide application data.
311 * On UNIX platforms this is determined using the mechanisms described in
313 * XDG Base Directory Specification
314 * On Windows the first elements in the list are the Application Data
315 * and Documents folders for All Users. (These can be determined only
316 * on Windows 2000 or later and are not present in the list on other
317 * Windows versions.) See documentation for CSIDL_COMMON_APPDATA and
318 * CSIDL_COMMON_DOCUMENTS.
319 * Then follows the "share" subfolder in the installation folder for
320 * the package containing the DLL that calls this function, if it can
322 * Finally the list contains the "share" subfolder in the installation
323 * folder for GLib, and in the installation folder for the package the
324 * application's .exe file belongs to.
325 * The installation folders above are determined by looking up the
326 * folder where the module (DLL or EXE) in question is located. If the
327 * folder's name is "bin", its parent is used, otherwise the folder
329 * Note that on Windows the returned list can vary depending on where
330 * this function is called.
332 * a NULL-terminated array of strings owned by GLib that must
333 * not be modified or freed.
336 public static char** getSystemDataDirs()
338 // const gchar* const * g_get_system_data_dirs (void);
339 return g_get_system_data_dirs();
343 * Returns an ordered list of base directories in which to access
344 * system-wide configuration information.
345 * On UNIX platforms this is determined using the mechanisms described in
347 * XDG Base Directory Specification
349 * a NULL-terminated array of strings owned by GLib that must
350 * not be modified or freed.
353 public static char** getSystemConfigDirs()
355 // const gchar* const * g_get_system_config_dirs (void);
356 return g_get_system_config_dirs();
360 * Return a name for the machine.
361 * The returned name is not necessarily a fully-qualified domain name,
362 * or even present in DNS or some other name service at all. It need
363 * not even be unique on your local network or site, but usually it
364 * is. Callers should not rely on the return value having any specific
365 * properties like uniqueness for security purposes. Even if the name
366 * of the machine is changed while an application is running, the
367 * return value from this function does not change. The returned
368 * string is owned by GLib and should not be modified or freed. If no
369 * name can be determined, a default fixed string "localhost" is
372 * the host name of the machine.
375 public static char[] getHostName()
377 // const gchar* g_get_host_name (void);
378 return Str
.toString(g_get_host_name() );
382 * Gets the current user's home directory as defined in the
384 * Note that in contrast to traditional UNIX tools, this function
385 * prefers passwd entries over the HOME
386 * environment variable.
388 * the current user's home directory.
390 public static char[] getHomeDir()
392 // const gchar* g_get_home_dir (void);
393 return Str
.toString(g_get_home_dir() );
397 * Gets the directory to use for temporary files. This is found from
398 * inspecting the environment variables TMPDIR,
399 * TMP, and TEMP in that order. If none
400 * of those are defined "/tmp" is returned on UNIX and "C:\" on Windows.
401 * The encoding of the returned string is system-defined. On Windows,
402 * it is always UTF-8. The return value is never NULL.
404 * the directory to use for temporary files.
406 public static char[] getTmpDir()
408 // const gchar* g_get_tmp_dir (void);
409 return Str
.toString(g_get_tmp_dir() );
413 * Gets the current directory.
414 * The returned string should be freed when no longer needed. The encoding
415 * of the returned string is system defined. On Windows, it is always UTF-8.
417 * the current directory.
419 public static char[] getCurrentDir()
421 // gchar* g_get_current_dir (void);
422 return Str
.toString(g_get_current_dir() );
427 * g_basename has been deprecated since version 2.2 and should not be used in newly-written code. Use g_path_get_basename() instead, but notice that
428 * g_path_get_basename() allocates new memory for the returned string, unlike
429 * this function which returns a pointer into the argument.
430 * Gets the name of the file without any leading directory components.
431 * It returns a pointer into the given file name string.
433 * the name of the file.
435 * the name of the file without any leading directory components.
437 public static char[] basename(char[] fileName
)
439 // const gchar* g_basename (const gchar *file_name);
440 return Str
.toString(g_basename(Str
.toStringz(fileName
)) );
445 * Returns TRUE if the given file_name is an absolute file name,
446 * i.e. it contains a full path from the root directory such as "/usr/local"
447 * on UNIX or "C:\windows" on Windows systems.
451 * TRUE if file_name is an absolute path.
453 public static int pathIsAbsolute(char[] fileName
)
455 // gboolean g_path_is_absolute (const gchar *file_name);
456 return g_path_is_absolute(Str
.toStringz(fileName
));
460 * Returns a pointer into file_name after the root component, i.e. after
461 * the "/" in UNIX or "C:\" under Windows. If file_name is not an absolute
462 * path it returns NULL.
466 * a pointer into file_name after the root component.
468 public static char[] pathSkipRoot(char[] fileName
)
470 // const gchar* g_path_skip_root (const gchar *file_name);
471 return Str
.toString(g_path_skip_root(Str
.toStringz(fileName
)) );
475 * Gets the last component of the filename. If file_name ends with a
476 * directory separator it gets the component before the last slash. If
477 * file_name consists only of directory separators (and on Windows,
478 * possibly a drive letter), a single separator is returned. If
479 * file_name is empty, it gets ".".
481 * the name of the file.
483 * a newly allocated string containing the last component of
486 public static char[] pathGetBasename(char[] fileName
)
488 // gchar* g_path_get_basename (const gchar *file_name);
489 return Str
.toString(g_path_get_basename(Str
.toStringz(fileName
)) );
493 * Gets the directory components of a file name. If the file name has no
494 * directory components "." is returned. The returned string should be
495 * freed when no longer needed.
497 * the name of the file.
499 * the directory components of the file.
501 public static char[] pathGetDirname(char[] fileName
)
503 // gchar* g_path_get_dirname (const gchar *file_name);
504 return Str
.toString(g_path_get_dirname(Str
.toStringz(fileName
)) );
508 * Creates a filename from a series of elements using the correct
509 * separator for filenames.
510 * On Unix, this function behaves identically to g_build_path
511 * (G_DIR_SEPARATOR_S, first_element, ....).
512 * On Windows, it takes into account that either the backslash
513 * (\ or slash (/) can be used
514 * as separator in filenames, but otherwise behaves as on Unix. When
515 * file pathname separators need to be inserted, the one that last
516 * previously occurred in the parameters (reading from left to right)
518 * No attempt is made to force the resulting filename to be an absolute
519 * path. If the first element is a relative path, the result will
520 * be a relative path.
522 * the first element in the path
524 * remaining elements in path, terminated by NULL
526 * a newly-allocated string that must be freed with g_free().
528 public static char[] buildFilename(char[] firstElement
, ... )
530 // gchar* g_build_filename (const gchar *first_element, ...);
531 return Str
.toString(g_build_filename(Str
.toStringz(firstElement
)) );
535 * Behaves exactly like g_build_filename(), but takes the path elements
536 * as a string array, instead of varargs. This function is mainly
537 * meant for language bindings.
539 * NULL-terminated array of strings containing the path elements.
541 * a newly-allocated string that must be freed with g_free().
544 public static char[] buildFilenamev(char** args
)
546 // gchar* g_build_filenamev (gchar **args);
547 return Str
.toString(g_build_filenamev(args
) );
551 * Creates a path from a series of elements using separator as the
552 * separator between elements. At the boundary between two elements,
553 * any trailing occurrences of separator in the first element, or
554 * leading occurrences of separator in the second element are removed
555 * and exactly one copy of the separator is inserted.
556 * Empty elements are ignored.
557 * The number of leading copies of the separator on the result is
558 * the same as the number of leading copies of the separator on
559 * the first non-empty element.
560 * The number of trailing copies of the separator on the result is
561 * the same as the number of trailing copies of the separator on
562 * the last non-empty element. (Determination of the number of
563 * trailing copies is done without stripping leading copies, so
564 * if the separator is ABA, ABABA
565 * has 1 trailing copy.)
566 * However, if there is only a single non-empty element, and there
567 * are no characters in that element not part of the leading or
568 * trailing separators, then the result is exactly the original value
570 * Other than for determination of the number of leading and trailing
571 * copies of the separator, elements consisting only of copies
572 * of the separator are ignored.
574 * a string used to separator the elements of the path.
576 * the first element in the path
578 * remaining elements in path, terminated by NULL
580 * a newly-allocated string that must be freed with g_free().
582 public static char[] buildPath(char[] separator
, char[] firstElement
, ... )
584 // gchar* g_build_path (const gchar *separator, const gchar *first_element, ...);
585 return Str
.toString(g_build_path(Str
.toStringz(separator
), Str
.toStringz(firstElement
)) );
589 * Behaves exactly like g_build_path(), but takes the path elements
590 * as a string array, instead of varargs. This function is mainly
591 * meant for language bindings.
593 * a string used to separator the elements of the path.
595 * NULL-terminated array of strings containing the path elements.
597 * a newly-allocated string that must be freed with g_free().
600 public static char[] buildPathv(char[] separator
, char** args
)
602 // gchar* g_build_pathv (const gchar *separator, gchar **args);
603 return Str
.toString(g_build_pathv(Str
.toStringz(separator
), args
) );
607 * Locates the first executable named program in the user's path, in the
608 * same way that execvp() would locate it. Returns an allocated string
609 * with the absolute path name, or NULL if the program is not found in
610 * the path. If program is already an absolute path, returns a copy of
611 * program if program exists and is executable, and NULL otherwise.
612 * On Windows, if program does not have a file type suffix, tries
613 * with the suffixes .exe, .cmd, .bat and .com, and the suffixes in
614 * the PATHEXT environment variable.
615 * On Windows, it looks for the file in the same way as CreateProcess()
616 * would. This means first in the directory where the executing
617 * program was loaded from, then in the current directory, then in the
618 * Windows 32-bit system directory, then in the Windows directory, and
619 * finally in the directories in the PATH environment
620 * variable. If the program is found, the return value contains the
621 * full name including the type suffix.
623 * a program name in the GLib file name encoding
625 * absolute path, or NULL
627 public static char[] findProgramInPath(char[] program
)
629 // gchar* g_find_program_in_path (const gchar *program);
630 return Str
.toString(g_find_program_in_path(Str
.toStringz(program
)) );
634 * Find the position of the first bit set in mask, searching from (but not
635 * including) nth_bit upwards. Bits are numbered from 0 (least significant)
636 * to sizeof(gulong) * 8 - 1 (31 or 63, usually). To start searching from the
637 * 0th bit, set nth_bit to -1.
639 * a gulong containing flags.
641 * the index of the bit to start the search from.
643 * the index of the first bit set which is higher than nth_bit.
645 public static int bitNthLsf(uint mask
, int nthBit
)
647 // gint g_bit_nth_lsf (gulong mask, gint nth_bit);
648 return g_bit_nth_lsf(mask
, nthBit
);
652 * Find the position of the first bit set in mask, searching from (but not
653 * including) nth_bit downwards. Bits are numbered from 0 (least significant)
654 * to sizeof(gulong) * 8 - 1 (31 or 63, usually). To start searching from the
655 * last bit, set nth_bit to -1 or GLIB_SIZEOF_LONG * 8.
657 * a gulong containing flags.
659 * the index of the bit to start the search from.
661 * the index of the first bit set which is lower than nth_bit.
663 public static int bitNthMsf(uint mask
, int nthBit
)
665 // gint g_bit_nth_msf (gulong mask, gint nth_bit);
666 return g_bit_nth_msf(mask
, nthBit
);
670 * Gets the number of bits used to hold number,
671 * e.g. if number is 4, 3 bits are needed.
675 * the number of bits used to hold number.
677 public static uint bitStorage(uint number
)
679 // guint g_bit_storage (gulong number);
680 return g_bit_storage(number
);
684 * Gets the smallest prime number from a built-in array of primes which
685 * is larger than num. This is used within GLib to calculate the optimum
686 * size of a GHashTable.
687 * The built-in array of primes ranges from 11 to 13845163 such that
688 * each prime is approximately 1.5-2 times the previous prime.
692 * the smallest prime number from a built-in array of primes which is
695 public static uint spacedPrimesClosest(uint num
)
697 // guint g_spaced_primes_closest (guint num);
698 return g_spaced_primes_closest(num
);
702 * Specifies a function to be called at normal program termination.
703 * Since GLib 2.8.2, on Windows g_atexit() actually is a preprocessor
704 * macro that maps to a call to the atexit() function in the C
705 * library. This means that in case the code that calls g_atexit(),
706 * i.e. atexit(), is in a DLL, the function will be called when the
707 * DLL is detached from the program. This typically makes more sense
708 * than that the function is called when the GLib DLL is detached,
709 * which happened earlier when g_atexit() was a function in the GLib
711 * The behaviour of atexit() in the context of dynamically loaded
712 * modules is not formally specified and varies wildly.
713 * On POSIX systems, calling g_atexit() (or atexit()) in a dynamically
714 * loaded module which is unloaded before the program terminates might
715 * well cause a crash at program exit.
716 * Some POSIX systems implement atexit() like Windows, and have each
717 * dynamically loaded module maintain an own atexit chain that is
718 * called when the module is unloaded.
719 * On other POSIX systems, before a dynamically loaded module is
720 * unloaded, the registered atexit functions (if any) residing in that
721 * module are called, regardless where the code that registered them
722 * resided. This is presumably the most robust approach.
723 * As can be seen from the above, for portability it's best to avoid
724 * calling g_atexit() (or atexit()) except in the main executable of a
727 * the function to call on normal program termination.
729 public static void atexit(GVoidFunc func
)
731 // void g_atexit (GVoidFunc func);
736 * Parses a string containing debugging options
737 * into a guint containing bit flags. This is used
738 * within GDK and GTK+ to parse the debug options passed on the
739 * command line or through environment variables.
741 * a list of debug options separated by colons, spaces, or
742 * commas; or the string "all" to set all flags.
744 * pointer to an array of GDebugKey which associate
745 * strings with bit flags.
747 * the number of GDebugKeys in the array.
749 * the combined set of bit flags.
751 public static uint parseDebugString(char[] string
, GDebugKey
* keys
, uint nkeys
)
753 // guint g_parse_debug_string (const gchar *string, const GDebugKey *keys, guint nkeys);
754 return g_parse_debug_string(Str
.toStringz(string
), keys
, nkeys
);
761 * This is just like the standard C qsort() function, but
762 * the comparison routine accepts a user data argument.
764 * start of array to sort
766 * elements in the array
768 * size of each element
770 * function to compare elements
772 * data to pass to compare_func
774 public static void qsortWithData(void* pbase
, int totalElems
, uint size
, GCompareDataFunc compareFunc
, void* userData
)
776 // void g_qsort_with_data (gconstpointer pbase, gint total_elems, gsize size, GCompareDataFunc compare_func, gpointer user_data);
777 g_qsort_with_data(pbase
, totalElems
, size
, compareFunc
, userData
);
781 * Set the pointer at the specified location to NULL.
783 * the memory address of the pointer.
785 public static void nullifyPointer(void** nullifyLocation
)
787 // void g_nullify_pointer (gpointer *nullify_location);
788 g_nullify_pointer(nullifyLocation
);