Added cs to the list of languages
[midnight-commander.git] / vfs / local.c
blob73097db20c56377c8941b591dce0199755d2e167
1 #include <config.h>
2 #include <errno.h>
3 #include <sys/types.h>
4 #include <unistd.h>
5 #include <stdio.h>
6 #include <string.h>
8 #include <fcntl.h>
10 #include "utilvfs.h"
12 #include "vfs.h"
13 #include "local.h"
15 /* Note: Some of this functions are not static. This has rather good
16 * reason: exactly same functions would have to appear in sfs.c. This
17 * saves both computer's memory and my work. <pavel@ucw.cz>
18 * */
20 static void *
21 local_open (vfs *me, char *file, int flags, int mode)
23 int *local_info;
24 int fd;
26 fd = open (file, NO_LINEAR(flags), mode);
27 if (fd == -1)
28 return 0;
30 local_info = g_new (int, 1);
31 *local_info = fd;
33 return local_info;
36 int
37 local_read (void *data, char *buffer, int count)
39 int n;
41 if (!data)
42 return -1;
44 while ((n = read (*((int *) data), buffer, count)) == -1){
45 #ifdef EAGAIN
46 if (errno == EAGAIN) continue;
47 #endif
48 #ifdef EINTR
49 if (errno == EINTR) continue;
50 #endif
51 return -1;
53 return n;
56 int
57 local_close (void *data)
59 int fd;
61 if (!data)
62 return -1;
64 fd = *(int *) data;
65 g_free (data);
66 return close (fd);
69 int
70 local_errno (vfs *me)
72 return errno;
75 static void *
76 local_opendir (vfs *me, char *dirname)
78 DIR **local_info;
79 DIR *dir;
81 dir = opendir (dirname);
82 if (!dir)
83 return 0;
85 local_info = (DIR **) g_new (DIR *, 1);
86 *local_info = dir;
88 return local_info;
91 static int
92 local_telldir (void *data)
94 return telldir( *(DIR **) data );
97 static void
98 local_seekdir (void *data, int offset)
100 seekdir( *(DIR **) data, offset );
103 static void *
104 local_readdir (void *data)
106 return readdir (*(DIR **) data);
109 static int
110 local_closedir (void *data)
112 int i;
114 i = closedir (* (DIR **) data);
115 if (data)
116 g_free (data);
117 return i;
120 static int
121 local_stat (vfs *me, char *path, struct stat *buf)
123 return stat (path, buf);
126 static int
127 local_lstat (vfs *me, char *path, struct stat *buf)
129 #ifndef HAVE_STATLSTAT
130 return lstat (path,buf);
131 #else
132 return statlstat (path, buf);
133 #endif
137 local_fstat (void *data, struct stat *buf)
139 return fstat (*((int *) data), buf);
142 static int
143 local_chmod (vfs *me, char *path, int mode)
145 return chmod (path, mode);
148 static int
149 local_chown (vfs *me, char *path, int owner, int group)
151 return chown (path, owner, group);
154 static int
155 local_utime (vfs *me, char *path, struct utimbuf *times)
157 return utime (path, times);
160 static int
161 local_readlink (vfs *me, char *path, char *buf, int size)
163 return readlink (path, buf, size);
166 static int
167 local_unlink (vfs *me, char *path)
169 return unlink (path);
172 static int
173 local_symlink (vfs *me, char *n1, char *n2)
175 return symlink (n1, n2);
178 static int
179 local_write (void *data, char *buf, int nbyte)
181 int fd;
182 int n;
184 if (!data)
185 return -1;
187 fd = * (int *) data;
188 while ((n = write (fd, buf, nbyte)) == -1){
189 #ifdef EAGAIN
190 if (errno == EAGAIN) continue;
191 #endif
192 #ifdef EINTR
193 if (errno == EINTR) continue;
194 #endif
195 break;
197 return n;
200 static int
201 local_rename (vfs *me, char *a, char *b)
203 return rename (a, b);
206 static int
207 local_chdir (vfs *me, char *path)
209 return chdir (path);
213 local_lseek (void *data, off_t offset, int whence)
215 int fd = * (int *) data;
217 return lseek (fd, offset, whence);
220 static int
221 local_mknod (vfs *me, char *path, int mode, int dev)
223 return mknod (path, mode, dev);
226 static int
227 local_link (vfs *me, char *p1, char *p2)
229 return link (p1, p2);
232 static int
233 local_mkdir (vfs *me, char *path, mode_t mode)
235 return mkdir (path, mode);
238 static int
239 local_rmdir (vfs *me, char *path)
241 return rmdir (path);
244 static vfsid
245 local_getid (vfs *me, char *path, struct vfs_stamping **parent)
247 *parent = NULL;
248 return (vfsid) -1; /* We do not free local fs stuff at all */
251 static int
252 local_nothingisopen (vfsid id)
254 return 0;
257 static void
258 local_free (vfsid id)
262 static char *
263 local_getlocalcopy (vfs *me, char *path)
265 return g_strdup (path);
268 static void
269 local_ungetlocalcopy (vfs *me, char *path, char *local, int has_changed)
273 #ifdef HAVE_MMAP
274 caddr_t
275 local_mmap (vfs *me, caddr_t addr, size_t len, int prot, int flags, void *data, off_t offset)
277 int fd = * (int *)data;
279 return mmap (addr, len, prot, flags, fd, offset);
283 local_munmap (vfs *me, caddr_t addr, size_t len, void *data)
285 return munmap (addr, len);
287 #endif
289 static int
290 local_which (vfs *me, char *path)
292 return 0; /* Every path which other systems do not like is expected to be ours */
295 vfs vfs_local_ops = {
296 NULL, /* This is place of next pointer */
297 "Local filesystem",
298 0, /* flags */
299 NULL, /* prefix */
300 NULL, /* data */
301 0, /* errno */
302 NULL,
303 NULL,
304 NULL,
305 local_which,
307 local_open,
308 local_close,
309 local_read,
310 local_write,
312 local_opendir,
313 local_readdir,
314 local_closedir,
315 local_telldir,
316 local_seekdir,
318 local_stat,
319 local_lstat,
320 local_fstat,
322 local_chmod,
323 local_chown,
324 local_utime,
326 local_readlink,
327 local_symlink,
328 local_link,
329 local_unlink,
331 local_rename,
332 local_chdir,
333 local_errno,
334 local_lseek,
335 local_mknod,
337 local_getid,
338 local_nothingisopen,
339 local_free,
341 local_getlocalcopy,
342 local_ungetlocalcopy,
344 local_mkdir,
345 local_rmdir,
347 NULL,
348 NULL
349 #ifdef HAVE_MMAP
350 ,local_mmap,
351 local_munmap
352 #endif