## Miscellaneous Utilities

Miscellaneous Utilities — Miscellaneous utility functions

## Functions

const gchar * | xfce_get_homedir ()
#define | xfce_get_homefile()
gchar * | xfce_get_homefile_r ()
const gchar * | xfce_get_userdir ()
#define | xfce_get_userfile()
gchar * | xfce_get_userfile_r ()
gchar * | xfce_gethostname ()
gchar * | xfce_expand_variables ()

## Includes

    #include <libxfce4util/libxfce4util.h>

## Description

## Functions

### xfce_get_homedir ()

    const gchar *
    xfce_get_homedir (void);

Similar to `g_get_homedir()` in functionality but will never return NULL. While `g_get_homedir()` may return NULL under certain circumstances, this function is garantied to never ever return NULL, but always return a valid character pointer with the absolute path to the user's home directory.

The returned string is owned by libxfce4util and must not be freed by the caller.

#### Returns

the path to the current user's home directory.

### xfce_get_homefile()

    #define             xfce_get_homefile(...)

Returns the path to a file in the user's home directory by taking a NULL terminated list of strings and appending them to the absolute path of the current user's home directory.

#### Returns

the absolute path to the specified file in the current user's home directory. The caller is responsible for freeing the returned string using `g_free()`.

### xfce_get_homefile_r ()

    gchar *
    xfce_get_homefile_r (gchar *buffer,
                         size_t length,
                         const gchar *format,
                         ...);

Similar in functionality to xfce_get_homefile, but uses a user defined `buffer` instead of allocating a new buffer.

xfce_get_homefile_r uses safe string operations, that says, it garanties that the resulting string is always zero terminated, as long as the `length` is greater than zero.

#### Parameters

buffer | pointer to a user provided destination buffer. |
length | size of `buffer` in bytes. |
format | printf style format string. |

#### Returns

pointer to `buffer` .

### xfce_get_userdir ()

    const gchar *
    xfce_get_userdir (void);

Safe way to retrieve the path to the user's ".xfce4" directory. The path to the current user's ".xfce4" directory is either taken from the environment variable XFCE4HOME if defined, or if unset, is gained by concatenating the path to the user's home directory and the ".xfce4". That says, it will, by default, return the path "$HOME/.xfce4", where $HOME is replaced with the absolute path to the user's home directory.

The returned string is managed by libxfce4util and must not be freed by the caller.

#### Returns

the path to the current user's ".xfce4" directory.

### xfce_get_userfile()

    #define             xfce_get_userfile(...)

Returns the absolute path to a file within the user's ".xfce4" directory, formed by a NULL terminated list of path components.

#### Returns

the absolute path to the specified file in the user's ".xfce4" directory. The caller is responsible for freeing the returned string using `g_free()`.

### xfce_get_userfile_r ()

    gchar *
    xfce_get_userfile_r (gchar *buffer,
                         size_t length,
                         const gchar *format,
                         ...);

#### Parameters

buffer | user provided destination buffer. |
length | size of `buffer` in bytes. |
format | printf style format string. |

#### Returns

pointer to `buffer` .

### xfce_gethostname ()

    gchar *
    xfce_gethostname (void);

Portable way to query the hostname of the node running the process. This function does not ever return `NULL`, but always returns a string containing the current node's hostname.

#### Returns

the current node's hostname. The string has to be freed by the caller using `g_free()`.

### xfce_expand_variables ()

    gchar *
    xfce_expand_variables (const gchar *command,
                           gchar **envp);

Expands shell like environment variables and tilde (~/ and ~user/ are both supported) in `command` .

#### Parameters

command | Input string or `NULL`. |
envp | Addition environment variables to take into account. These variables have higher priority than the ones in the process's environment. |

#### Returns

`NULL` on error, else the string, which should be freed using `g_free()` when no longer needed.

Since 4.2

## Types and Values