aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/lib/file/evas_path.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-04 18:41:13 +1000
committerDavid Walter Seikel2012-01-04 18:41:13 +1000
commitdd7595a3475407a7fa96a97393bae8c5220e8762 (patch)
treee341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/evas/src/lib/file/evas_path.c
parentAdd the skeleton. (diff)
downloadSledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz
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.
Diffstat (limited to 'libraries/evas/src/lib/file/evas_path.c')
-rw-r--r--libraries/evas/src/lib/file/evas_path.c154
1 files changed, 154 insertions, 0 deletions
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 @@
1/* os dependent file code. for unix-y like fs's only for now */
2/* if your os doesn't use unix-like fs starting with "/" for the root and */
3/* the file path separator isn't "/" then you may need to help out by */
4/* adding in a new set of functions here */
5
6#ifdef HAVE_CONFIG_H
7# include <config.h>
8#endif
9
10#include <limits.h>
11#include <stdlib.h>
12#include <sys/types.h>
13#include <sys/stat.h>
14/* get the casefold feature! */
15#include <fnmatch.h>
16#ifndef _MSC_VER
17# include <unistd.h>
18# include <sys/param.h>
19#endif
20
21#ifdef HAVE_EVIL
22# include <Evil.h>
23#endif
24
25#include "evas_common.h"
26#include "evas_private.h"
27
28#ifdef _WIN32
29# define EVAS_PATH_SEPARATOR "\\"
30#else
31# define EVAS_PATH_SEPARATOR "/"
32#endif
33
34int
35evas_file_path_is_full_path(const char *path)
36{
37 if (!path) return 0;
38#if defined _WIN32_WCE
39 if (path[0] == '\\') return 1;
40#elif defined _WIN32
41 if ((path[0] == '\0') || (path[1] == '\0'))
42 return 0;
43 if (path[1] == ':') return 1;
44#else
45 if (path[0] == '/') return 1;
46#endif
47 return 0;
48}
49
50char *
51evas_file_path_join(const char *path, const char *end)
52{
53 char *res = NULL;
54 size_t len;
55
56 if ((!path) && (!end)) return NULL;
57 if (!path) return strdup(end);
58 if (!end) return strdup(path);
59 len = strlen(path);
60 len += strlen(end);
61 len += strlen(EVAS_PATH_SEPARATOR);
62 res = malloc(len + 1);
63 if (!res) return NULL;
64 strcpy(res, path);
65 strcat(res, EVAS_PATH_SEPARATOR);
66 strcat(res, end);
67 return res;
68}
69
70int
71evas_file_path_exists(const char *path)
72{
73 struct stat st;
74
75 if (!stat(path, &st)) return 1;
76 return 0;
77}
78
79int
80evas_file_path_is_file(const char *path)
81{
82 struct stat st;
83
84 if (stat(path, &st) == -1) return 0;
85 if (S_ISREG(st.st_mode)) return 1;
86 return 0;
87}
88
89int
90evas_file_path_is_dir(const char *path)
91{
92 struct stat st;
93
94 if (stat(path, &st) == -1) return 0;
95 if (S_ISDIR(st.st_mode)) return 1;
96 return 0;
97}
98
99Eina_List *
100evas_file_path_list(char *path, const char *match, int match_case)
101{
102 Eina_File_Direct_Info *info;
103 Eina_Iterator *it;
104 Eina_List *files = NULL;
105 int flags;
106
107 flags = FNM_PATHNAME;
108#ifdef FNM_CASEFOLD
109 if (!match_case)
110 flags |= FNM_CASEFOLD;
111#else
112/*#warning "Your libc does not provide case-insensitive matching!"*/
113#endif
114
115 it = eina_file_direct_ls(path);
116 EINA_ITERATOR_FOREACH(it, info)
117 {
118 if (match)
119 {
120 if (fnmatch(match, info->path + info->name_start, flags) == 0)
121 files = eina_list_append(files, strdup(info->path + info->name_start));
122 }
123 else
124 files = eina_list_append(files, strdup(info->path + info->name_start));
125 }
126 eina_iterator_free(it);
127 return files;
128}
129
130DATA64
131evas_file_modified_time(const char *file)
132{
133 struct stat st;
134
135 if (stat(file, &st) < 0) return 0;
136 if (st.st_ctime > st.st_mtime) return (DATA64)st.st_ctime;
137 else return (DATA64)st.st_mtime;
138 return 0;
139}
140
141char *
142evas_file_path_resolve(const char *file)
143{
144#if 0
145 char buf[PATH_MAX], *buf2;
146#endif
147
148 return strdup(file);
149#if 0
150 if (!realpath(file, buf)) return NULL;
151 buf2 = strdup(buf);
152 return buf2;
153#endif
154}