gutils.h File Reference

__G_UTILS_H__

G_DIR_SEPARATOR

G_DIR_SEPARATOR_S

G_IS_DIR_SEPARATOR

G_SEARCHPATH_SEPARATOR

G_SEARCHPATH_SEPARATOR_S

G_VA_COPY

inline

G_INLINE_FUNC

g_get_user_name ( void )

IMPORT_C G_CONST_RETURN gchar *g_get_user_name(void)

g_get_user_name:

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.

g_get_real_name ( void )

IMPORT_C G_CONST_RETURN gchar *g_get_real_name(void)

g_get_real_name:

Gets the real name of the user. This usually comes from the user's entry in the <filename>passwd</filename> 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.

g_get_home_dir ( void )

IMPORT_C G_CONST_RETURN gchar *g_get_home_dir(void)

g_get_home_dir:

Gets the current user's home directory as defined in the password database.

Note that in contrast to traditional UNIX tools, this function prefers <filename>passwd</filename> entries over the <envar>HOME</envar> environment variable.

One of the reasons for this decision is that applications in many cases need special handling to deal with the case where <envar>HOME</envar> is <simplelist> <member>Not owned by the user</member> <member>Not writeable</member> <member>Not even readable</member> </simplelist> Since applications are in general <emphasis>not</emphasis> written to deal with these situations it was considered better to make g_get_home_dir() not pay attention to <envar>HOME</envar> and to return the real home directory for the user. If applications want to pay attention to <envar>HOME</envar>, they can do: |[ const char *homedir = g_getenv ("HOME"); if (!homedir) homedir = g_get_home_dir (); ]|

Returns: the current user's home directory

g_get_tmp_dir ( void )

IMPORT_C G_CONST_RETURN gchar *g_get_tmp_dir(void)

g_get_tmp_dir:

Gets the directory to use for temporary files. This is found from inspecting the environment variables <envar>TMPDIR</envar>, <envar>TMP</envar>, and <envar>TEMP</envar> 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.

g_get_host_name ( void )

IMPORT_C G_CONST_RETURN gchar *g_get_host_name(void)

g_get_host_name:

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

g_get_prgname ( void )

IMPORT_C gchar *g_get_prgname(void)

g_get_prgname:

Gets the name of the program. This name should <emphasis>not</emphasis> 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 <literal>argv[0]</literal>.)

Returns: the name of the program. The returned string belongs to GLib and must not be modified or freed.

g_set_prgname ( const gchar * )

IMPORT_C voidg_set_prgname(const gchar *prgname)

g_set_prgname: : the name of the program.

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

g_get_application_name ( void )

IMPORT_C G_CONST_RETURN gchar *g_get_application_name(void)

g_get_application_name:

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

Return value: human-readable application name. may return NULL

Since: 2.2

g_set_application_name ( const gchar * )

IMPORT_C voidg_set_application_name(const gchar *application_name)

g_set_application_name: : localized name of the application

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.

Since: 2.2

g_get_user_data_dir ( void )

IMPORT_C G_CONST_RETURN gchar *g_get_user_data_dir(void)

g_get_user_data_dir:

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 <ulink url="http://www.freedesktop.org/Standards/basedir-spec"> XDG Base Directory Specification</ulink>

Return value: a string owned by GLib that must not be modified or freed. Since: 2.6

g_get_user_config_dir ( void )

IMPORT_C G_CONST_RETURN gchar *g_get_user_config_dir(void)

g_get_user_config_dir:

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 <ulink url="http://www.freedesktop.org/Standards/basedir-spec"> XDG Base Directory Specification</ulink>

Return value: a string owned by GLib that must not be modified or freed. Since: 2.6

g_get_user_cache_dir ( void )

IMPORT_C G_CONST_RETURN gchar *g_get_user_cache_dir(void)

g_get_user_cache_dir:

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 <ulink url="http://www.freedesktop.org/Standards/basedir-spec"> XDG Base Directory Specification</ulink>

Return value: a string owned by GLib that must not be modified or freed. Since: 2.6

g_get_system_data_dirs ( void )

IMPORT_C G_CONST_RETURN gchar *G_CONST_RETURN *g_get_system_data_dirs(void)

g_get_system_data_dirs:

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 <ulink url="http://www.freedesktop.org/Standards/basedir-spec"> XDG Base Directory Specification</ulink>

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.

Return value: a NULL-terminated array of strings owned by GLib that must not be modified or freed. Since: 2.6

g_get_system_config_dirs ( void )

IMPORT_C G_CONST_RETURN gchar *G_CONST_RETURN *g_get_system_config_dirs(void)

g_get_system_config_dirs:

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 <ulink url="http://www.freedesktop.org/Standards/basedir-spec"> XDG Base Directory Specification</ulink>

Return value: a NULL-terminated array of strings owned by GLib that must not be modified or freed. Since: 2.6

g_get_language_names ( void )

IMPORT_C G_CONST_RETURN gchar *G_CONST_RETURN *g_get_language_names(void)

g_get_language_names:

Computes a list of applicable locale names, which can be used to e.g. construct locale-dependent filenames or search paths. The returned list is sorted from most desirable to least desirable and always contains the default locale "C".

For example, if LANGUAGE=de:en_US, then the returned list is "de", "en_US", "en", "C".

This function consults the environment variables <envar>LANGUAGE</envar>, <envar>LC_ALL</envar>, <envar>LC_MESSAGES</envar> and <envar>LANG</envar> to find the list of locales specified by the user.

Return value: a NULL-terminated array of strings owned by GLib that must not be modified or freed.

Since: 2.6

Enum GUserDirectory

GUserDirectory: : the user's Desktop directory : the user's Documents directory : the user's Downloads directory : the user's Music directory : the user's Pictures directory : the user's shared directory : the user's Templates directory : the user's Movies directory : the number of enum values

These are logical ids for special directories which are defined depending on the platform used. You should use g_get_user_special_dir() to retrieve the full path associated to the logical id.

The GUserDirectory enumeration can be extended at later date. Not every platform has a directory for every logical id in this enumeration.

Since: 2.14

g_get_user_special_dir ( GUserDirectory )

IMPORT_C G_CONST_RETURN gchar *g_get_user_special_dir(GUserDirectorydirectory)

g_get_user_special_dir: : the logical id of special directory

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

On Unix this is done using the XDG special user directories. For compatibility with existing practise, G_USER_DIRECTORY_DESKTOP falls back to <filename>$HOME/Desktop</filename> when XDG special user directories have not been set up.

Depending on the platform, the user might be able to change the path of the special directory without requiring the session to restart; GLib will not reflect any change once the special directories are loaded.

Return value: 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.

Since: 2.14

Typedef GDebugKey

typedef struct _GDebugKeyGDebugKey

g_parse_debug_string ( const gchar *, const GDebugKey *, guint )

IMPORT_C guintg_parse_debug_string(const gchar *string,
const GDebugKey *keys,
guintnkeys
)

g_parse_debug_string: : a list of debug options separated by colons, spaces, or commas, or NULL. : pointer to an array of GDebugKey which associate strings with bit flags. : the number of #GDebugKeys in the array.

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.

If is equal to "all", all flags are set. If is equal to "help", all the available keys in are printed out to standard error.

Returns: the combined set of bit flags.

g_snprintf ( gchar *, gulong, gchar const *, ... )

IMPORT_C gintg_snprintf(gchar *string,
gulongn,
gchar const *format,
...
)

g_vsnprintf ( gchar *, gulong, gchar const *, va_list )

IMPORT_C gint IMPORT_C gintg_vsnprintf(gchar *string,
gulongn,
gchar const *format,
va_listargs
)

g_vsnprintf: : the buffer to hold the output. : the maximum number of bytes to produce (including the terminating nul character). : a standard printf() format string, but notice <link linkend="string-precision">string precision pitfalls</link>. : the list of arguments to insert in the output.

A safer form of the standard vsprintf() function. The output is guaranteed to not exceed characters (including the terminating nul character), so it is easy to ensure that a buffer overflow cannot occur.

See also g_strdup_vprintf().

In versions of GLib prior to 1.2.3, this function may return -1 if the output was truncated, and the truncated string may not be nul-terminated. In versions prior to 1.3.12, this function returns the length of the output string.

The return value of g_vsnprintf() conforms to the vsnprintf() function as standardized in ISO C99. Note that this is different from traditional vsnprintf(), which returns the length of the output string.

The format string may contain positional parameters, as specified in the Single Unix Specification.

Returns: the number of bytes which would be produced if the buffer was large enough.

g_path_is_absolute ( const gchar * )

IMPORT_C gbooleang_path_is_absolute(const gchar *file_name)

g_path_is_absolute: : a file name.

Returns TRUE if the given 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.

Returns: TRUE if is an absolute path.

g_path_skip_root ( const gchar * )

IMPORT_C G_CONST_RETURN gchar *g_path_skip_root(const gchar *file_name)

g_path_skip_root: : a file name.

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

Returns: a pointer into after the root component.

g_basename ( const gchar * )

IMPORT_C G_CONST_RETURN gchar *g_basename(const gchar *file_name)

g_basename: : the name of the file.

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

Return value: the name of the file without any leading directory components.

Deprecated:2.2: 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.

g_dirname

g_get_current_dir ( void )

IMPORT_C gchar *g_get_current_dir(void)

g_get_current_dir:

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.

g_path_get_basename ( const gchar * )

IMPORT_C gchar *g_path_get_basename(const gchar *file_name)

g_path_get_basename: : the name of the file.

Gets the last component of the filename. If ends with a directory separator it gets the component before the last slash. If consists only of directory separators (and on Windows, possibly a drive letter), a single separator is returned. If is empty, it gets ".".

Return value: a newly allocated string containing the last component of the filename.

g_path_get_dirname ( const gchar * )

IMPORT_C gchar *g_path_get_dirname(const gchar *file_name)

g_path_get_dirname: : the name of the file.

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.

Returns: the directory components of the file.

g_nullify_pointer ( gpointer * )

IMPORT_C voidg_nullify_pointer(gpointer *nullify_location)

g_nullify_pointer: : the memory address of the pointer.

Set the pointer at the specified location to NULL.

g_getenv ( const gchar * )

IMPORT_C G_CONST_RETURN gchar *g_getenv(const gchar *variable)

g_getenv: : the environment variable to get, in the GLib file name encoding.

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.

Return value: 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().

g_setenv ( const gchar *, const gchar *, gboolean )

IMPORT_C gbooleang_setenv(const gchar *variable,
const gchar *value,
gbooleanoverwrite
)

g_setenv: : the environment variable to set, must not contain '='. : the value for to set the variable to. : whether to change the variable if it already exists.

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.

Returns: FALSE if the environment variable couldn't be set.

Since: 2.4

g_unsetenv ( const gchar * )

IMPORT_C voidg_unsetenv(const gchar *variable)

g_unsetenv: : the environment variable to remove, must not contain '='.

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.

Since: 2.4

g_listenv ( void )

IMPORT_C gchar **g_listenv(void)

g_listenv:

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

_g_getenv_nomalloc ( const gchar *, gchar )

const gchar *_g_getenv_nomalloc(const gchar *variable,
gcharbuffer
)

Typedef GVoidFunc

typedef void(*GVoidFunc

ATEXIT

g_atexit ( GVoidFunc )

IMPORT_C voidg_atexit(GVoidFuncfunc)

g_atexit: : the function to call on normal program termination.

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.

g_find_program_in_path ( const gchar * )

IMPORT_C gchar *g_find_program_in_path(const gchar *program)

g_find_program_in_path: : a program name in the GLib file name encoding

Locates the first executable named 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 is already an absolute path, returns a copy of if exists and is executable, and NULL otherwise.

On Windows, if does not have a file type suffix, tries with the suffixes .exe, .cmd, .bat and .com, and the suffixes in the <envar>PATHEXT</envar> 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 <envar>PATH</envar> environment variable. If the program is found, the return value contains the full name including the type suffix.

Return value: absolute path, or NULL

g_bit_nth_lsf ( gulong, gint )

gint g_bit_nth_lsf(gulongmask,
gintnth_bit
)

g_bit_nth_msf ( gulong, gint )

gint g_bit_nth_msf(gulongmask,
gintnth_bit
)

g_bit_storage ( gulong )

guint g_bit_storage(gulongnumber)

Typedef GTrashStack

typedef struct _GTrashStackGTrashStack

g_trash_stack_push ( GTrashStack **, gpointer )

voidg_trash_stack_push(GTrashStack **stack_p,
gpointerdata_p
)

g_trash_stack_pop ( GTrashStack ** )

gpointer g_trash_stack_pop(GTrashStack **stack_p)

g_trash_stack_peek ( GTrashStack ** )

gpointer g_trash_stack_peek(GTrashStack **stack_p)

g_trash_stack_height ( GTrashStack ** )

guint g_trash_stack_height(GTrashStack **stack_p)

glib_major_version

GLIB_VAR const guintglib_major_version

glib_minor_version

GLIB_VAR const guintglib_minor_version

glib_micro_version

GLIB_VAR const guintglib_micro_version

glib_interface_age

GLIB_VAR const guintglib_interface_age

glib_binary_age

GLIB_VAR const guintglib_binary_age

_glib_major_version ( void )

IMPORT_C const guint *_glib_major_version(void)

_glib_minor_version ( void )

IMPORT_C const guint *_glib_minor_version(void)

_glib_micro_version ( void )

IMPORT_C const guint *_glib_micro_version(void)

_glib_interface_age ( void )

IMPORT_C const guint *_glib_interface_age(void)

_glib_binary_age ( void )

IMPORT_C const guint *_glib_binary_age(void)

glib_check_version ( guint, guint, guint )

IMPORT_C const gchar *glib_check_version(guintrequired_major,
guintrequired_minor,
guintrequired_micro
)

glib_check_version: : the required major version. : the required minor version. : the required micro version.

Checks that the GLib library in use is compatible with the given version. Generally you would pass in the constants GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION as the three arguments to this function; that produces a check that the library in use is compatible with the version of GLib the application or module was compiled against.

Compatibility is defined by two things: first the version of the running library is newer than the version .required_minor.. Second the running library must be binary compatible with the version .required_minor. (same major version.)

Return value: NULL if the GLib library is compatible with the given version, or a string describing the version mismatch. The returned string is owned by GLib and must not be modified or freed.

Since: 2.6

GLIB_CHECK_VERSION

G_WIN32_DLLMAIN_FOR_DLL_NAME