util

util — Miscellaneous utility functions

Synopsis


#include <libxfce4util/libxfce4util.h>


#define     XFCE_LICENSE_BSD
#define     XFCE_LICENSE_GPL
#define     XFCE_LICENSE_LGPL
G_CONST_RETURN gchar* xfce_version_string   (void);
G_CONST_RETURN gchar* xfce_get_homedir      (void);
#define     xfce_get_homefile               (first_element...)
G_CONST_RETURN gchar* xfce_get_homefile_r   (gchar *buffer,
                                             size_t length,
                                             const gchar *format,
                                             ...);
G_CONST_RETURN gchar* xfce_get_userdir      (void);
#define     xfce_get_userfile               (first_element...)
G_CONST_RETURN gchar* xfce_get_userfile_r   (gchar *buffer,
                                             size_t length,
                                             const gchar *format,
                                             ...);
gchar*      xfce_strjoin                    (gchar *separator,
                                             gchar **strings,
                                             gint count);
gchar*      xfce_gethostname                (void);
gint        xfce_putenv                     (const gchar *string);
gint        xfce_setenv                     (const gchar *name,
                                             const gchar *value,
                                             gboolean overwrite);

Description

Details

XFCE_LICENSE_BSD

#define XFCE_LICENSE_BSD  _BUILTIN_LICENSE_TEXT(BSD)

Contains the text of the BSD license.


XFCE_LICENSE_GPL

#define XFCE_LICENSE_GPL  _BUILTIN_LICENSE_TEXT(GPL)

Contains the text of the GNU General Public License.


XFCE_LICENSE_LGPL

#define XFCE_LICENSE_LGPL _BUILTIN_LICENSE_TEXT(LGPL)

Contains the text of the GNU Lesser General Public License.


xfce_version_string ()

G_CONST_RETURN gchar* xfce_version_string   (void);

Queries the version string of the installed Xfce desktop environment.

Returns : the overall version information of the installed Xfce desktop.

xfce_get_homedir ()

G_CONST_RETURN 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(first_element...)

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.

first_element... :NULL terminated list of path components.
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 ()

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

buffer : pointer to a user provided destination buffer.
length : size of buffer in bytes.
format : printf style format string.
... : the arguments to substitute in the output.
Returns : pointer to buffer.

xfce_get_userdir ()

G_CONST_RETURN 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(first_element...)

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

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

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

buffer : user provided destination buffer.
length : size of buffer in bytes.
format : printf style format string.
... : arguments to substitute in the output.
Returns : pointer to buffer.

xfce_strjoin ()

gchar*      xfce_strjoin                    (gchar *separator,
                                             gchar **strings,
                                             gint count);

Joins the count character strings pointed to by strings using separator to a single string.

separator :
strings :
count :
Returns : the joined string. The string has to be freed by the caller using g_free() when no longer needed.

xfce_gethostname ()

gchar*      xfce_gethostname                (void);

Portable way to query the hostname of the node running the process. This function does not every 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_putenv ()

gint        xfce_putenv                     (const gchar *string);

Portable replacement for the Unix putenv() library function. string has to have the form "name=value". Calling xfce_putenv() this way is equal to calling xfce_setenv("name", "value", TRUE).

string : Character string in the form "name=value".
Returns : 0 if the operation was successful; otherwise the global variable errno is set to indicate the error and a value of -1 is returned.

Since 4.1.1


xfce_setenv ()

gint        xfce_setenv                     (const gchar *name,
                                             const gchar *value,
                                             gboolean overwrite);

If the variable name does not exists in the list of environment variables, it is inserted with its value being set to value. If the variable does exist, then its value is only changed to value if overwrite is TRUE.

On plattforms that provide a working native setenv() library call, this functions is used, on all other plattforms setenv() is emulated using xfce_putenv(). That says, xfce_setenv() is not subject to the limitations that apply to some setenv() implementations and seem also to apply to g_setenv() in Glib 2.4.

name : the name of the environment variable to set, must not contain '='.
value : the value to set the variable to.
overwrite : whether to change the variable if it already exists.
Returns : 0 if the operation was successful; otherwise the global variable errno is set to indicate the error and a value of -1 is returned.

Since 4.1.1