From dd7595a3475407a7fa96a97393bae8c5220e8762 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Wed, 4 Jan 2012 18:41:13 +1000 Subject: Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje. Note that embryo wont be used, but I'm not sure yet if you can build edje without it. --- libraries/evas/src/lib/file/evas_path.c | 154 ++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 libraries/evas/src/lib/file/evas_path.c (limited to 'libraries/evas/src/lib/file/evas_path.c') diff --git a/libraries/evas/src/lib/file/evas_path.c b/libraries/evas/src/lib/file/evas_path.c new file mode 100644 index 0000000..ff13e20 --- /dev/null +++ b/libraries/evas/src/lib/file/evas_path.c @@ -0,0 +1,154 @@ +/* os dependent file code. for unix-y like fs's only for now */ +/* if your os doesn't use unix-like fs starting with "/" for the root and */ +/* the file path separator isn't "/" then you may need to help out by */ +/* adding in a new set of functions here */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +/* get the casefold feature! */ +#include +#ifndef _MSC_VER +# include +# include +#endif + +#ifdef HAVE_EVIL +# include +#endif + +#include "evas_common.h" +#include "evas_private.h" + +#ifdef _WIN32 +# define EVAS_PATH_SEPARATOR "\\" +#else +# define EVAS_PATH_SEPARATOR "/" +#endif + +int +evas_file_path_is_full_path(const char *path) +{ + if (!path) return 0; +#if defined _WIN32_WCE + if (path[0] == '\\') return 1; +#elif defined _WIN32 + if ((path[0] == '\0') || (path[1] == '\0')) + return 0; + if (path[1] == ':') return 1; +#else + if (path[0] == '/') return 1; +#endif + return 0; +} + +char * +evas_file_path_join(const char *path, const char *end) +{ + char *res = NULL; + size_t len; + + if ((!path) && (!end)) return NULL; + if (!path) return strdup(end); + if (!end) return strdup(path); + len = strlen(path); + len += strlen(end); + len += strlen(EVAS_PATH_SEPARATOR); + res = malloc(len + 1); + if (!res) return NULL; + strcpy(res, path); + strcat(res, EVAS_PATH_SEPARATOR); + strcat(res, end); + return res; +} + +int +evas_file_path_exists(const char *path) +{ + struct stat st; + + if (!stat(path, &st)) return 1; + return 0; +} + +int +evas_file_path_is_file(const char *path) +{ + struct stat st; + + if (stat(path, &st) == -1) return 0; + if (S_ISREG(st.st_mode)) return 1; + return 0; +} + +int +evas_file_path_is_dir(const char *path) +{ + struct stat st; + + if (stat(path, &st) == -1) return 0; + if (S_ISDIR(st.st_mode)) return 1; + return 0; +} + +Eina_List * +evas_file_path_list(char *path, const char *match, int match_case) +{ + Eina_File_Direct_Info *info; + Eina_Iterator *it; + Eina_List *files = NULL; + int flags; + + flags = FNM_PATHNAME; +#ifdef FNM_CASEFOLD + if (!match_case) + flags |= FNM_CASEFOLD; +#else +/*#warning "Your libc does not provide case-insensitive matching!"*/ +#endif + + it = eina_file_direct_ls(path); + EINA_ITERATOR_FOREACH(it, info) + { + if (match) + { + if (fnmatch(match, info->path + info->name_start, flags) == 0) + files = eina_list_append(files, strdup(info->path + info->name_start)); + } + else + files = eina_list_append(files, strdup(info->path + info->name_start)); + } + eina_iterator_free(it); + return files; +} + +DATA64 +evas_file_modified_time(const char *file) +{ + struct stat st; + + if (stat(file, &st) < 0) return 0; + if (st.st_ctime > st.st_mtime) return (DATA64)st.st_ctime; + else return (DATA64)st.st_mtime; + return 0; +} + +char * +evas_file_path_resolve(const char *file) +{ +#if 0 + char buf[PATH_MAX], *buf2; +#endif + + return strdup(file); +#if 0 + if (!realpath(file, buf)) return NULL; + buf2 = strdup(buf); + return buf2; +#endif +} -- cgit v1.1