summaryrefslogtreecommitdiffstats
path: root/eglib
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2008-03-11 22:54:59 +0000
committerLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2008-03-11 22:54:59 +0000
commit0ef72a5769f1c283786aa105d67127d6b113168c (patch)
tree93ff3208745d5355cc7ad5d57c23864d54734dab /eglib
parent56afc8a3d8a5019d44c9607508b75be0c61b1930 (diff)
Add g_dir* and g_str_has_prefix functions to eglib.
Diffstat (limited to 'eglib')
-rw-r--r--eglib/gmain.c85
-rw-r--r--eglib/gmain.h9
-rw-r--r--eglib/gmodule.c11
-rw-r--r--eglib/gmodule.h1
4 files changed, 106 insertions, 0 deletions
diff --git a/eglib/gmain.c b/eglib/gmain.c
index 878760d8..7bc96961 100644
--- a/eglib/gmain.c
+++ b/eglib/gmain.c
@@ -17,6 +17,7 @@
#include <sys/file.h>
#include <ctype.h>
#include <dlfcn.h>
+#include <dirent.h>
#include <gmain.h>
@@ -64,6 +65,11 @@ struct _GMainLoop {
GMainContext *context;
};
+struct _GDir
+{
+ DIR *dirp;
+};
+
GIOError g_io_channel_read(GIOChannel *channel, gchar *buf, gsize count,
gsize *bytes_read)
{
@@ -1404,6 +1410,23 @@ gboolean g_str_equal(gconstpointer v1, gconstpointer v2)
return strcmp(string1, string2) == 0;
}
+gboolean g_str_has_prefix(const gchar *str, const gchar *prefix)
+{
+ int str_len;
+ int prefix_len;
+
+ if (str == NULL || prefix == NULL)
+ return FALSE;
+
+ str_len = strlen (str);
+ prefix_len = strlen (prefix);
+
+ if (str_len < prefix_len)
+ return FALSE;
+
+ return strncmp(str, prefix, prefix_len) == 0;
+}
+
/* GKeyFile */
struct _GKeyFile {
@@ -1692,3 +1715,65 @@ void g_markup_parse_context_free(GMarkupParseContext *context)
{
g_free(context);
}
+
+gchar * g_build_filename (const gchar *first_element, ...)
+{
+ gchar *str;
+ va_list args;
+
+ va_start (args, first_element);
+ str = g_build_pathname_va(first_element, &args, NULL);
+ va_end (args);
+
+ return str;
+}
+
+GDir *g_dir_open(const gchar *path, guint flags, GError **error)
+{
+ GDir *dir;
+
+ if (path == NULL)
+ return NULL;
+
+ dir = g_new (GDir, 1);
+
+ dir->dirp = opendir (path);
+
+ if (dir->dirp)
+ return dir;
+
+ /* error case */
+ g_set_error(error, 0, 0, "Error opening directory '%s': %s", path,
+ strerror(errno));
+
+ g_free (dir);
+
+ return NULL;
+}
+
+const gchar *g_dir_read_name(GDir *dir)
+{
+ struct dirent *entry;
+
+ if (dir == NULL)
+ return NULL;
+
+ entry = readdir (dir->dirp);
+ while (entry && (0 == strcmp(entry->d_name, ".") ||
+ 0 == strcmp(entry->d_name, "..")))
+ entry = readdir(dir->dirp);
+
+ if (entry)
+ return entry->d_name;
+ else
+ return NULL;
+}
+
+void g_dir_close(GDir *dir)
+{
+ if (dir == NULL)
+ return;
+
+ closedir (dir->dirp);
+ g_free (dir);
+}
diff --git a/eglib/gmain.h b/eglib/gmain.h
index b3590338..beb9e32e 100644
--- a/eglib/gmain.h
+++ b/eglib/gmain.h
@@ -229,6 +229,7 @@ gchar* g_strdelimit(gchar *string, const gchar *delimiters, gchar new_delim);
gchar *g_strconcat(const gchar *string1, ...);
gchar **g_strsplit(const gchar *string, const gchar *delimiter, gint max_tokens);
gboolean g_str_equal(gconstpointer v1, gconstpointer v2);
+gboolean g_str_has_prefix(const gchar *str, const gchar *prefix);
#define g_new(struct_type, n_structs) \
((struct_type *) g_malloc (((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
@@ -345,4 +346,12 @@ gboolean g_markup_parse_context_parse(GMarkupParseContext *context,
void g_markup_parse_context_free(GMarkupParseContext *context);
+/* GDir */
+
+typedef struct _GDir GDir;
+
+GDir *g_dir_open(const gchar *path, guint flags, GError **error);
+const gchar *g_dir_read_name(GDir *dir);
+void g_dir_close(GDir *dir);
+
#endif /* __GMAIN_H */
diff --git a/eglib/gmodule.c b/eglib/gmodule.c
index d9ece8d7..c3400823 100644
--- a/eglib/gmodule.c
+++ b/eglib/gmodule.c
@@ -11,6 +11,7 @@
struct _GModule {
void *handle;
+ gchar *file_name;
};
static const char *dl_error_string = NULL;
@@ -33,6 +34,8 @@ GModule *g_module_open(const gchar *file_name, GModuleFlags flags)
return NULL;
}
+ module->file_name = g_strdup(file_name);
+
return module;
}
@@ -74,3 +77,11 @@ const gchar *g_module_error(void)
return str;
}
+
+const gchar *g_module_name(GModule *module)
+{
+ if (module == NULL)
+ return NULL;
+
+ return module->file_name;
+}
diff --git a/eglib/gmodule.h b/eglib/gmodule.h
index e1830595..e392d5c8 100644
--- a/eglib/gmodule.h
+++ b/eglib/gmodule.h
@@ -14,6 +14,7 @@ typedef enum {
GModule *g_module_open(const gchar *file_name, GModuleFlags flags);
gboolean g_module_symbol(GModule *module, const gchar *symbol_name,
gpointer *symbol);
+const gchar *g_module_name(GModule *module);
gboolean g_module_close(GModule *module);
const gchar *g_module_error(void);