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