glib.Util.Util Class Reference

List of all members.

Detailed Description

Description These are portable utility functions.


Static Public Member Functions

static char[] getApplicationName ()
 Gets a human-readable name for the application, as set by g_set_application_name().
static void setApplicationName (char[] applicationName)
 Sets a human-readable name for the application.
static char[] getPrgname ()
 Gets the name of the program.
static void setPrgname (char[] prgname)
 Sets the name of the program.
static char[] getenv (char[] variable)
 Returns the value of an environment variable.
static int setenv (char[] variable, char[] value, int overwrite)
 Sets an environment variable.
static void unsetenv (char[] variable)
 Removes an environment variable from the environment.
static char ** listenv ()
 Gets the names of all variables set in the environment.
static char[] getUserName ()
 Gets the user name of the current user.
static char[] getRealName ()
 Gets the real name of the user.
static char[] getUserCacheDir ()
 Returns a base directory in which to store non-essential, cached data specific to particular user.
static char[] getUserDataDir ()
 Returns a base directory in which to access application data such as icons that is customized for a particular user.
static char[] getUserConfigDir ()
 Returns a base directory in which to store user-specific application configuration information such as user preferences and settings.
static char ** getSystemDataDirs ()
 Returns an ordered list of base directories in which to access system-wide application data.
static char ** getSystemConfigDirs ()
 Returns an ordered list of base directories in which to access system-wide configuration information.
static char[] getHostName ()
 Return a name for the machine.
static char[] getHomeDir ()
 Gets the current user's home directory.
static char[] getTmpDir ()
 Gets the directory to use for temporary files.
static char[] getCurrentDir ()
 Gets the current directory.
static char[] basename (char[] fileName)
 Warning g_basename has been deprecated since version 2.2 and should not be used in newly-written code.
static int pathIsAbsolute (char[] fileName)
 Returns TRUE if the given file_name is an absolute file name, i.e.
static char[] pathSkipRoot (char[] fileName)
 Returns a pointer into file_name after the root component, i.e.
static char[] pathGetBasename (char[] fileName)
 Gets the last component of the filename.
static char[] pathGetDirname (char[] fileName)
 Gets the directory components of a file name.
static char[] buildFilename (char[] firstElement,...)
 Creates a filename from a series of elements using the correct separator for filenames.
static char[] buildFilenamev (char **args)
 Behaves exactly like g_build_filename(), but takes the path elements as a string array, instead of varargs.
static char[] buildPath (char[] separator, char[] firstElement,...)
 Creates a path from a series of elements using separator as the separator between elements.
static char[] buildPathv (char[] separator, char **args)
 Behaves exactly like g_build_path(), but takes the path elements as a string array, instead of varargs.
static char[] findProgramInPath (char[] program)
 Locates the first executable named program in the user's path, in the same way that execvp() would locate it.
static int bitNthLsf (uint mask, int nthBit)
 Find the position of the first bit set in mask, searching from (but not including) nth_bit upwards.
static int bitNthMsf (uint mask, int nthBit)
 Find the position of the first bit set in mask, searching from (but not including) nth_bit downwards.
static uint bitStorage (uint number)
 Gets the number of bits used to hold number, e.g.
static uint spacedPrimesClosest (uint num)
 Gets the smallest prime number from a built-in array of primes which is larger than num.
static void atexit (GVoidFunc func)
 Specifies a function to be called at normal program termination.
static uint parseDebugString (char[] string, GDebugKey *keys, uint nkeys)
 Parses a string containing debugging options into a guint containing bit flags.
static void qsortWithData (void *pbase, int totalElems, uint size, GCompareDataFunc compareFunc, void *userData)
 This is just like the standard C qsort() function, but the comparison routine accepts a user data argument.
static void nullifyPointer (void **nullifyLocation)
 Set the pointer at the specified location to NULL.


Member Function Documentation

static void glib.Util.Util.atexit ( GVoidFunc  func  )  [static]

Specifies a function to be called at normal program termination.

Since GLib 2.8.2, on Windows g_atexit() actually is a preprocessor macro that maps to a call to the atexit() function in the C library. This means that in case the code that calls g_atexit(), i.e. atexit(), is in a DLL, the function will be called when the DLL is detached from the program. This typically makes more sense than that the function is called when the GLib DLL is detached, which happened earlier when g_atexit() was a function in the GLib DLL. The behaviour of atexit() in the context of dynamically loaded modules is not formally specified and varies wildly. On POSIX systems, calling g_atexit() (or atexit()) in a dynamically loaded module which is unloaded before the program terminates might well cause a crash at program exit. Some POSIX systems implement atexit() like Windows, and have each dynamically loaded module maintain an own atexit chain that is called when the module is unloaded. On other POSIX systems, before a dynamically loaded module is unloaded, the registered atexit functions (if any) residing in that module are called, regardless where the code that registered them resided. This is presumably the most robust approach. As can be seen from the above, for portability it's best to avoid calling g_atexit() (or atexit()) except in the main executable of a program. func: the function to call on normal program termination.

static char [] glib.Util.Util.basename ( char[]  fileName  )  [static]

Warning 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 g_path_get_basename() allocates new memory for the returned string, unlike this function which returns a pointer into the argument. Gets the name of the file without any leading directory components. It returns a pointer into the given file name string. file_name: the name of the file. Returns: the name of the file without any leading directory components.

static int glib.Util.Util.bitNthLsf ( uint  mask,
int  nthBit 
) [static]

Find the position of the first bit set in mask, searching from (but not including) nth_bit upwards.

Bits are numbered from 0 (least significant) to sizeof(gulong) * 8 - 1 (31 or 63, usually). To start searching from the 0th bit, set nth_bit to -1. mask: a gulong containing flags. nth_bit: the index of the bit to start the search from. Returns: the index of the first bit set which is higher than nth_bit.

static int glib.Util.Util.bitNthMsf ( uint  mask,
int  nthBit 
) [static]

Find the position of the first bit set in mask, searching from (but not including) nth_bit downwards.

Bits are numbered from 0 (least significant) to sizeof(gulong) * 8 - 1 (31 or 63, usually). To start searching from the last bit, set nth_bit to -1 or GLIB_SIZEOF_LONG * 8. mask: a gulong containing flags. nth_bit: the index of the bit to start the search from. Returns: the index of the first bit set which is lower than nth_bit.

static uint glib.Util.Util.bitStorage ( uint  number  )  [static]

Gets the number of bits used to hold number, e.g.

if number is 4, 3 bits are needed. number: a guint. Returns: the number of bits used to hold number.

static char [] glib.Util.Util.buildFilename ( char[]  firstElement,
  ... 
) [static]

Creates a filename from a series of elements using the correct separator for filenames.

On Unix, this function behaves identically to g_build_path (G_DIR_SEPARATOR_S, first_element, ....). On Windows, it takes into account that either the backslash (\ or slash (/) can be used as separator in filenames, but otherwise behaves as on Unix. When file pathname separators need to be inserted, the one that last previously occurred in the parameters (reading from left to right) is used. No attempt is made to force the resulting filename to be an absolute path. If the first element is a relative path, the result will be a relative path. first_element: the first element in the path ...: remaining elements in path, terminated by NULL Returns: a newly-allocated string that must be freed with g_free().

static char [] glib.Util.Util.buildFilenamev ( char **  args  )  [static]

Behaves exactly like g_build_filename(), but takes the path elements as a string array, instead of varargs.

This function is mainly meant for language bindings. args: NULL-terminated array of strings containing the path elements. Returns: a newly-allocated string that must be freed with g_free(). Since 2.8

static char [] glib.Util.Util.buildPath ( char[]  separator,
char[]  firstElement,
  ... 
) [static]

Creates a path from a series of elements using separator as the separator between elements.

At the boundary between two elements, any trailing occurrences of separator in the first element, or leading occurrences of separator in the second element are removed and exactly one copy of the separator is inserted. Empty elements are ignored. The number of leading copies of the separator on the result is the same as the number of leading copies of the separator on the first non-empty element. The number of trailing copies of the separator on the result is the same as the number of trailing copies of the separator on the last non-empty element. (Determination of the number of trailing copies is done without stripping leading copies, so if the separator is ABA, ABABA has 1 trailing copy.) However, if there is only a single non-empty element, and there are no characters in that element not part of the leading or trailing separators, then the result is exactly the original value of that element. Other than for determination of the number of leading and trailing copies of the separator, elements consisting only of copies of the separator are ignored. separator: a string used to separator the elements of the path. first_element: the first element in the path ...: remaining elements in path, terminated by NULL Returns: a newly-allocated string that must be freed with g_free().

static char [] glib.Util.Util.buildPathv ( char[]  separator,
char **  args 
) [static]

Behaves exactly like g_build_path(), but takes the path elements as a string array, instead of varargs.

This function is mainly meant for language bindings. separator: a string used to separator the elements of the path. args: NULL-terminated array of strings containing the path elements. Returns: a newly-allocated string that must be freed with g_free(). Since 2.8

static char [] glib.Util.Util.findProgramInPath ( char[]  program  )  [static]

Locates the first executable named program in the user's path, in the same way that execvp() would locate it.

Returns an allocated string with the absolute path name, or NULL if the program is not found in the path. If program is already an absolute path, returns a copy of program if program exists and is executable, and NULL otherwise. On Windows, if program does not have a file type suffix, tries with the suffixes .exe, .cmd, .bat and .com, and the suffixes in the PATHEXT environment variable. On Windows, it looks for the file in the same way as CreateProcess() would. This means first in the directory where the executing program was loaded from, then in the current directory, then in the Windows 32-bit system directory, then in the Windows directory, and finally in the directories in the PATH environment variable. If the program is found, the return value contains the full name including the type suffix. program: a program name in the GLib file name encoding Returns: absolute path, or NULL

static char [] glib.Util.Util.getApplicationName (  )  [static]

Gets a human-readable name for the application, as set by g_set_application_name().

This name should be localized if possible, and is intended for display to the user. Contrast with g_get_prgname(), which gets a non-localized name. If g_set_application_name() has not been called, returns the result of g_get_prgname() (which may be NULL if g_set_prgname() has also not been called). Returns: human-readable application name. may return NULL Since 2.2

static char [] glib.Util.Util.getCurrentDir (  )  [static]

Gets the current directory.

The returned string should be freed when no longer needed. The encoding of the returned string is system defined. On Windows, it is always UTF-8. Returns: the current directory.

static char [] glib.Util.Util.getenv ( char[]  variable  )  [static]

Returns the value of an environment variable.

The name and value are in the GLib file name encoding. On UNIX, this means the actual bytes which might or might not be in some consistent character set and encoding. On Windows, it is in UTF-8. On Windows, in case the environment variable's value contains references to other environment variables, they are expanded. variable: the environment variable to get, in the GLib file name encoding. 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().

static char [] glib.Util.Util.getHomeDir (  )  [static]

Gets the current user's home directory.

Note that in contrast to traditional UNIX tools, this function prefers passwd entries over the HOME environment variable. Returns: the current user's home directory.

static char [] glib.Util.Util.getHostName (  )  [static]

Return a name for the machine.

The returned name is not necessarily a fully-qualified domain name, or even present in DNS or some other name service at all. It need not even be unique on your local network or site, but usually it is. Callers should not rely on the return value having any specific properties like uniqueness for security purposes. Even if the name of the machine is changed while an application is running, the return value from this function does not change. The returned string is owned by GLib and should not be modified or freed. If no name can be determined, a default fixed string "localhost" is returned. Returns: the host name of the machine. Since 2.8

static char [] glib.Util.Util.getPrgname (  )  [static]

Gets the name of the program.

This name should not be localized, contrast with g_get_application_name(). (If you are using GDK or GTK+ the program name is set in gdk_init(), which is called by gtk_init(). The program name is found by taking the last component of argv[0].) Returns: the name of the program. The returned string belongs to GLib and must not be modified or freed.

static char [] glib.Util.Util.getRealName (  )  [static]

Gets the real name of the user.

This usually comes from the user's entry in the passwd file. The encoding of the returned string is system-defined. (On Windows, it is, however, always UTF-8.) If the real user name cannot be determined, the string "Unknown" is returned. Returns: the user's real name.

static char** glib.Util.Util.getSystemConfigDirs (  )  [static]

Returns an ordered list of base directories in which to access system-wide configuration information.

On UNIX platforms this is determined using the mechanisms described in the XDG Base Directory Specification Returns: a NULL-terminated array of strings owned by GLib that must not be modified or freed. Since 2.6

static char** glib.Util.Util.getSystemDataDirs (  )  [static]

Returns an ordered list of base directories in which to access system-wide application data.

On UNIX platforms this is determined using the mechanisms described in the XDG Base Directory Specification On Windows the first elements in the list are the Application Data and Documents folders for All Users. (These can be determined only on Windows 2000 or later and are not present in the list on other Windows versions.) See documentation for CSIDL_COMMON_APPDATA and CSIDL_COMMON_DOCUMENTS. Then follows the "share" subfolder in the installation folder for the package containing the DLL that calls this function, if it can be determined. Finally the list contains the "share" subfolder in the installation folder for GLib, and in the installation folder for the package the application's .exe file belongs to. The installation folders above are determined by looking up the folder where the module (DLL or EXE) in question is located. If the folder's name is "bin", its parent is used, otherwise the folder itself. Note that on Windows the returned list can vary depending on where this function is called. Returns: a NULL-terminated array of strings owned by GLib that must not be modified or freed. Since 2.6

static char [] glib.Util.Util.getTmpDir (  )  [static]

Gets the directory to use for temporary files.

This is found from inspecting the environment variables TMPDIR, TMP, and TEMP in that order. If none of those are defined "/tmp" is returned on UNIX and "C:\" on Windows. The encoding of the returned string is system-defined. On Windows, it is always UTF-8. The return value is never NULL. Returns: the directory to use for temporary files.

static char [] glib.Util.Util.getUserCacheDir (  )  [static]

Returns a base directory in which to store non-essential, cached data specific to particular user.

On UNIX platforms this is determined using the mechanisms described in the XDG Base Directory Specification Returns: a string owned by GLib that must not be modified or freed. Since 2.6

static char [] glib.Util.Util.getUserConfigDir (  )  [static]

Returns a base directory in which to store user-specific application configuration information such as user preferences and settings.

On UNIX platforms this is determined using the mechanisms described in the XDG Base Directory Specification Returns: a string owned by GLib that must not be modified or freed. Since 2.6

static char [] glib.Util.Util.getUserDataDir (  )  [static]

Returns a base directory in which to access application data such as icons that is customized for a particular user.

On UNIX platforms this is determined using the mechanisms described in the XDG Base Directory Specification Returns: a string owned by GLib that must not be modified or freed. Since 2.6

static char [] glib.Util.Util.getUserName (  )  [static]

Gets the user name of the current user.

The encoding of the returned string is system-defined. On UNIX, it might be the preferred file name encoding, or something else, and there is no guarantee that it is even consistent on a machine. On Windows, it is always UTF-8. Returns: the user name of the current user.

static char** glib.Util.Util.listenv (  )  [static]

Gets the names of all variables set in the environment.

Returns: a NULL-terminated list of strings which must be freed with g_strfreev(). Programs that want to be portable to Windows should typically use this function and g_getenv() instead of using the environ array from the C library directly. On Windows, the strings in the environ array are in system codepage encoding, while in most of the typical use cases for environment variables in GLib-using programs you want the UTF-8 encoding that this function and g_getenv() provide. Since 2.8

static void glib.Util.Util.nullifyPointer ( void **  nullifyLocation  )  [static]

Set the pointer at the specified location to NULL.

nullify_location: the memory address of the pointer.

static uint glib.Util.Util.parseDebugString ( char[]  string,
GDebugKey keys,
uint  nkeys 
) [static]

Parses a string containing debugging options into a guint containing bit flags.

This is used within GDK and GTK+ to parse the debug options passed on the command line or through environment variables. string: a list of debug options separated by colons, spaces, or commas; or the string "all" to set all flags. keys: pointer to an array of GDebugKey which associate strings with bit flags. nkeys: the number of GDebugKeys in the array. Returns: the combined set of bit flags.

static char [] glib.Util.Util.pathGetBasename ( char[]  fileName  )  [static]

Gets the last component of the filename.

If file_name ends with a directory separator it gets the component before the last slash. If file_name consists only of directory separators (and on Windows, possibly a drive letter), a single separator is returned. If file_name is empty, it gets ".". file_name: the name of the file. Returns: a newly allocated string containing the last component of the filename.

static char [] glib.Util.Util.pathGetDirname ( char[]  fileName  )  [static]

Gets the directory components of a file name.

If the file name has no directory components "." is returned. The returned string should be freed when no longer needed. file_name: the name of the file. Returns: the directory components of the file.

static int glib.Util.Util.pathIsAbsolute ( char[]  fileName  )  [static]

Returns TRUE if the given file_name is an absolute file name, i.e.

it contains a full path from the root directory such as "/usr/local" on UNIX or "C:\windows" on Windows systems. file_name: a file name. Returns: TRUE if file_name is an absolute path.

static char [] glib.Util.Util.pathSkipRoot ( char[]  fileName  )  [static]

Returns a pointer into file_name after the root component, i.e.

after the "/" in UNIX or "C:\" under Windows. If file_name is not an absolute path it returns NULL. file_name: a file name. Returns: a pointer into file_name after the root component.

static void glib.Util.Util.qsortWithData ( void *  pbase,
int  totalElems,
uint  size,
GCompareDataFunc  compareFunc,
void *  userData 
) [static]

This is just like the standard C qsort() function, but the comparison routine accepts a user data argument.

pbase: start of array to sort total_elems: elements in the array size: size of each element compare_func: function to compare elements user_data: data to pass to compare_func

static void glib.Util.Util.setApplicationName ( char[]  applicationName  )  [static]

Sets a human-readable name for the application.

This name should be localized if possible, and is intended for display to the user. Contrast with g_set_prgname(), which sets a non-localized name. g_set_prgname() will be called automatically by gtk_init(), but g_set_application_name() will not. Note that for thread safety reasons, this function can only be called once. The application name will be used in contexts such as error messages, or when displaying an application's name in the task list. application_name: localized name of the application

static int glib.Util.Util.setenv ( char[]  variable,
char[]  value,
int  overwrite 
) [static]

Sets an environment variable.

Both the variable's name and value should be in the GLib file name encoding. On UNIX, this means that they can be any sequence of bytes. On Windows, they should be in UTF-8. Note that on some systems, when variables are overwritten, the memory used for the previous variables and its value isn't reclaimed. variable: the environment variable to set, must not contain '='. value: the value for to set the variable to. overwrite: whether to change the variable if it already exists. Returns: FALSE if the environment variable couldn't be set. Since 2.4

static void glib.Util.Util.setPrgname ( char[]  prgname  )  [static]

Sets the name of the program.

This name should not be localized, contrast with g_set_application_name(). Note that for thread-safety reasons this function can only be called once. prgname: the name of the program.

static uint glib.Util.Util.spacedPrimesClosest ( uint  num  )  [static]

Gets the smallest prime number from a built-in array of primes which is larger than num.

This is used within GLib to calculate the optimum size of a GHashTable. The built-in array of primes ranges from 11 to 13845163 such that each prime is approximately 1.5-2 times the previous prime. num: a guint. Returns: the smallest prime number from a built-in array of primes which is larger than num.

static void glib.Util.Util.unsetenv ( char[]  variable  )  [static]

Removes an environment variable from the environment.

Note that on some systems, when variables are overwritten, the memory used for the previous variables and its value isn't reclaimed. Furthermore, this function can't be guaranteed to operate in a threadsafe way. variable: the environment variable to remove, must not contain '='. Since 2.4


SourceForge.net Logo DSource.org Logo digitalmars.com Logo