Util

struct Util {}

Members

Static functions

atexit
void atexit(GVoidFunc func)

Specifies a function to be called at normal program termination.

basename
string basename(string fileName)

Gets the name of the file without any leading directory components. It returns a pointer into the given file name string.

bitNthLsf
int bitNthLsf(gulong mask, int nthBit)

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.

bitNthMsf
int bitNthMsf(gulong mask, int nthBit)

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.

bitStorage
uint bitStorage(gulong number)

Gets the number of bits used to hold @number, e.g. if @number is 4, 3 bits are needed.

buildFilename
string buildFilename(string[] firstElement)

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.

buildPath
string buildPath(string separator, string[] firstElement)

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.

canonicalizeFilename
string canonicalizeFilename(string filename, string relativeTo)

Gets the canonical file name from @filename. All triple slashes are turned into single slashes, and all .. and .s resolved against @relative_to.

environGetenv
string environGetenv(string[] envp, string variable)

Returns the value of the environment variable @variable in the provided list @envp.

environSetenv
string[] environSetenv(string[] envp, string variable, string value, bool overwrite)

Sets the environment variable @variable in the provided list @envp to @value.

environUnsetenv
string[] environUnsetenv(string[] envp, string variable)

Removes the environment variable @variable from the provided environment @envp.

findProgramInPath
string findProgramInPath(string program)

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.

formatSize
string formatSize(ulong size)

Formats a size (for example the size of a file) into a human readable string. Sizes are rounded to the nearest size prefix (kB, MB, GB) and are displayed rounded to the nearest tenth. E.g. the file size 3292528 bytes will be converted into the string "3.2 MB". The returned string is UTF-8, and may use a non-breaking space to separate the number and units, to ensure they aren’t separated when line wrapped.

formatSizeForDisplay
string formatSizeForDisplay(long size)

Formats a size (for example the size of a file) into a human readable string. Sizes are rounded to the nearest size prefix (KB, MB, GB) and are displayed rounded to the nearest tenth. E.g. the file size 3292528 bytes will be converted into the string "3.1 MB".

formatSizeFull
string formatSizeFull(ulong size, GFormatSizeFlags flags)

Formats a size.

getApplicationName
string getApplicationName()

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).

getCurrentDir
string getCurrentDir()

Gets the current directory.

getEnviron
string[] getEnviron()

Gets the list of environment variables for the current process.

getHomeDir
string getHomeDir()

Gets the current user's home directory.

getHostName
string getHostName()

Return a name for the machine.

getOsInfo
string getOsInfo(string keyName)

Get information about the operating system.

getPrgname
string getPrgname()

Gets the name of the program. This name should not be localized, in contrast to g_get_application_name().

getRealName
string getRealName()

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.

getSystemConfigDirs
string[] getSystemConfigDirs()

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

getSystemDataDirs
string[] getSystemDataDirs()

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

getTmpDir
string getTmpDir()

Gets the directory to use for temporary files.

getUserCacheDir
string getUserCacheDir()

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

getUserConfigDir
string getUserConfigDir()

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

getUserDataDir
string getUserDataDir()

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

getUserName
string getUserName()

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.

getUserRuntimeDir
string getUserRuntimeDir()

Returns a directory that is unique to the current user on the local system.

getUserSpecialDir
string getUserSpecialDir(GUserDirectory directory)

Returns the full path of a special directory using its logical id.

getenv
string getenv(string variable)

Returns the value of an environment variable.

listenv
string[] listenv()

Gets the names of all variables set in the environment.

nullifyPointer
void nullifyPointer(void** nullifyLocation)

Set the pointer at the specified location to %NULL.

parseDebugString
uint parseDebugString(string string_, GDebugKey[] keys)

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.

pathGetBasename
string pathGetBasename(string fileName)

Gets the last component of the filename.

pathGetDirname
string pathGetDirname(string fileName)

Gets the directory components of a file name. For example, the directory component of /usr/bin/test is /usr/bin. The directory component of / is /.

pathIsAbsolute
bool pathIsAbsolute(string fileName)

Returns %TRUE if the given @file_name is an absolute file name. Note that this is a somewhat vague concept on Windows.

pathSkipRoot
string pathSkipRoot(string fileName)

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.

qsortWithData
void qsortWithData(void* pbase, int totalElems, size_t size, GCompareDataFunc compareFunc, void* userData)

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

reloadUserSpecialDirsCache
void reloadUserSpecialDirsCache()

Resets the cache used for g_get_user_special_dir(), so that the latest on-disk version is used. Call this only if you just changed the data on disk yourself.

setApplicationName
void setApplicationName(string applicationName)

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.

setPrgname
void setPrgname(string prgname)

Sets the name of the program. This name should not be localized, in contrast to g_set_application_name().

setenv
bool setenv(string variable, string value, bool overwrite)

Sets an environment variable. On UNIX, both the variable's name and value can be arbitrary byte strings, except that the variable's name cannot contain '='. On Windows, they should be in UTF-8.

spacedPrimesClosest
uint spacedPrimesClosest(uint num)

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.

unsetenv
void unsetenv(string variable)

Removes an environment variable from the environment.

Meta