# HG changeset patch # User Matti Hamalainen # Date 1352440025 -7200 # Node ID c835aa129e3b704768e71ed995ecdc379391fac7 # Parent f1b33b5e153d4bcfe50bc4d34a09d1de17c3992b Add two new utility functions for checking whether a given path is a directory or not. diff -r f1b33b5e153d -r c835aa129e3b src/xs_support.c --- a/src/xs_support.c Fri Nov 09 07:46:29 2012 +0200 +++ b/src/xs_support.c Fri Nov 09 07:47:05 2012 +0200 @@ -73,6 +73,28 @@ #endif +gboolean xs_is_dir_path(const gchar *path) +{ + XSFile *fp = xs_fopen(path, "rb"); + if (fp != NULL) + { + xs_fclose(fp); + return FALSE; + } + else + return TRUE; +} + + +gchar *xs_get_dir_path(const gchar *path) +{ + if (xs_is_dir_path(path)) + return g_dirname(path); + else + return g_strdup(path); +} + + guint16 xs_fread_be16(XSFile *f) { return (((guint16) xs_fgetc(f)) << 8) | ((guint16) xs_fgetc(f)); diff -r f1b33b5e153d -r c835aa129e3b src/xs_support.h --- a/src/xs_support.h Fri Nov 09 07:46:29 2012 +0200 +++ b/src/xs_support.h Fri Nov 09 07:47:05 2012 +0200 @@ -124,6 +124,9 @@ gboolean xs_fload_buffer_path(const gchar *ppath, const gchar *pfilename, guint8 **pbuf, size_t *bufSize, const size_t maxSize, gboolean failMaxSize); +gboolean xs_is_dir_path(const gchar *path); +gchar *xs_get_dir_path(const gchar *path); + /* Error messages and debugging */