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