diff --git a/configure b/configure index 512b77d69e86a03842ae91acf3332a0250be105c..1ea3f6a9ffe3b244df962824138237db9914a881 100755 --- a/configure +++ b/configure @@ -1560,7 +1560,7 @@ fi # Define the identity of the package. PACKAGE=libxfce4util - VERSION=0.1 + VERSION=0.2 cat >>confdefs.h <<_ACEOF diff --git a/configure.ac b/configure.ac index a4a26f6fc727bc7fd3e9ceddb76fd99553e1ee9e..72f585f48ddaabc9e8f174ec4e728ac5abe4ddc6 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ AC_INIT(libxfce4util) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(libxfce4util, 0.1) +AM_INIT_AUTOMAKE(libxfce4util, 0.2) AM_MAINTAINER_MODE diff --git a/libxfce4util/util.c b/libxfce4util/util.c index e2b287ad75373f0f6a3d63a21b17fe057ce6b053..bc98471dfd82f848a6d96fb1baf3a0aa435b4be9 100644 --- a/libxfce4util/util.c +++ b/libxfce4util/util.c @@ -32,6 +32,11 @@ #include <err.h> #endif #include <errno.h> +#ifdef HAVE_STAD_ARG_H +#include <stdarg.h> +#elif HAVE_VARARGS_H +#include <varargs.h> +#endif #include <stdio.h> #ifdef HAVE_STDLIB_H #include <stdlib.h> @@ -61,7 +66,7 @@ static const gchar *xfce_userdir = NULL;/* path to users .xfce4 directory */ * Wrapper around gtk_init to to some stuff required for Xfce4 apps */ static void -initialize(void) +__initialize(void) { const gchar *dir; @@ -90,6 +95,28 @@ initialize(void) } } +static G_CONST_RETURN gchar * +__get_file_r(const gchar *dir, gchar *buffer, size_t len, + const gchar *format, va_list ap) +{ + size_t n; + + g_return_val_if_fail(buffer != NULL, NULL); + g_return_val_if_fail(format != NULL, NULL); + g_return_val_if_fail(len > 0, NULL); + + if ((n = g_strlcpy(buffer, dir, len)) >= len) + return(NULL); + + if ((n = g_strlcat(buffer, G_DIR_SEPARATOR_S, len)) >= len) + return(NULL); + + if (g_vsnprintf(buffer + n, len - n, format, ap) >= len - n) + return(NULL); + + return(buffer); +} + /** * This is garantied to never return NULL, unlike g_get_home_dir() */ @@ -98,21 +125,47 @@ xfce_get_homedir(void) { G_LOCK(_lock); if (!xfce_homedir) - initialize(); + __initialize(); G_UNLOCK(_lock); return(xfce_homedir); } +G_CONST_RETURN gchar * +xfce_get_homefile_r(gchar *buffer, size_t len, const gchar *format, ...) +{ + G_CONST_RETURN gchar *ptr; + va_list ap; + + va_start(ap, format); + ptr = __get_file_r(xfce_get_homedir(), buffer, len, format, ap); + va_end(ap); + + return(ptr); +} + G_CONST_RETURN gchar * xfce_get_userdir(void) { G_LOCK(_lock); if (!xfce_userdir) - initialize(); + __initialize(); G_UNLOCK(_lock); return(xfce_userdir); } +G_CONST_RETURN gchar * +xfce_get_userfile_r(gchar *buffer, size_t len, const gchar *format, ...) +{ + G_CONST_RETURN gchar *ptr; + va_list ap; + + va_start(ap, format); + ptr = __get_file_r(xfce_get_userdir(), buffer, len, format, ap); + va_end(ap); + + return(ptr); +} + diff --git a/libxfce4util/util.h b/libxfce4util/util.h index 8b09aa9bc1a60f75fbb1e248a554fe3d225757ab..02263b23dba76ae03471da8b3f113d4da5fdad15 100644 --- a/libxfce4util/util.h +++ b/libxfce4util/util.h @@ -37,10 +37,16 @@ extern G_CONST_RETURN gchar *xfce_get_homedir(void); (g_build_filename(xfce_get_homedir(), \ ## first_element)) +extern G_CONST_RETURN gchar *xfce_get_homefile_r(gchar *buffer, + size_t length, const gchar *format, ...); + /* save way to get path to users ".xfce4" directory */ extern G_CONST_RETURN gchar *xfce_get_userdir(void); #define xfce_get_userfile(first_element...) \ (g_build_filename(xfce_get_userdir(), \ ## first_element)) +extern G_CONST_RETURN gchar *xfce_get_userfile_r(gchar *buffer, + size_t length, const gchar *format, ...); + #endif /* __LIBXFCE4UTIL_UTIL_H__ */