Add debian syntax highlightion for specific files
[midnight-commander.git] / vfs / local.c
blob3a539191b1df4a61eb41c98204ae190f1e6ac1f0
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>
9 #include "../src/global.h"
10 #include "../src/tty.h" /* enable/disable interrupt key */
11 #include "../src/wtools.h" /* message() */
12 #include "../src/main.h" /* print_vfs_message */
13 #include "utilvfs.h"
14 #include "vfs.h"
15 #include "local.h"
17 /* Note: Some of this functions are not static. This has rather good
18 * reason: exactly same functions would have to appear in sfs.c. This
19 * saves both computer's memory and my work. <pavel@ucw.cz>
20 * */
22 static struct vfs_class vfs_local_ops;
24 static void *
25 local_open (struct vfs_class *me, const char *file, int flags, int mode)
27 int *local_info;
28 int fd;
30 (void) me;
32 fd = open (file, NO_LINEAR (flags), mode);
33 if (fd == -1)
34 return 0;
36 local_info = g_new (int, 1);
37 *local_info = fd;
39 return local_info;
42 int
43 local_read (void *data, char *buffer, int count)
45 int n;
47 if (!data)
48 return -1;
50 while ((n = read (*((int *) data), buffer, count)) == -1){
51 #ifdef EAGAIN
52 if (errno == EAGAIN) continue;
53 #endif
54 #ifdef EINTR
55 if (errno == EINTR) continue;
56 #endif
57 return -1;
59 return n;
62 int
63 local_close (void *data)
65 int fd;
67 if (!data)
68 return -1;
70 fd = *(int *) data;
71 g_free (data);
72 return close (fd);
75 int
76 local_errno (struct vfs_class *me)
78 (void) me;
79 return errno;
82 static void *
83 local_opendir (struct vfs_class *me, const char *dirname)
85 DIR **local_info;
86 DIR *dir;
88 (void) me;
90 dir = opendir (dirname);
91 if (!dir)
92 return 0;
94 local_info = (DIR **) g_new (DIR *, 1);
95 *local_info = dir;
97 return local_info;
100 static void *
101 local_readdir (void *data)
103 return readdir (*(DIR **) data);
106 static int
107 local_closedir (void *data)
109 int i;
111 i = closedir (* (DIR **) data);
112 g_free (data);
113 return i;
116 static int
117 local_stat (struct vfs_class *me, const char *path, struct stat *buf)
119 (void) me;
121 return stat (path, buf);
124 static int
125 local_lstat (struct vfs_class *me, const char *path, struct stat *buf)
127 (void) me;
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 /* FIXME: avoid type cast */
140 return fstat (*((int *) data), buf);
143 static int
144 local_chmod (struct vfs_class *me, const char *path, int mode)
146 (void) me;
148 return chmod (path, mode);
151 static int
152 local_chown (struct vfs_class *me, const char *path, int owner, int group)
154 (void) me;
156 return chown (path, owner, group);
159 static int
160 local_utime (struct vfs_class *me, const char *path, struct utimbuf *times)
162 (void) me;
164 return utime (path, times);
167 static int
168 local_readlink (struct vfs_class *me, const char *path, char *buf, size_t size)
170 (void) me;
172 return readlink (path, buf, size);
175 static int
176 local_unlink (struct vfs_class *me, const char *path)
178 (void) me;
180 return unlink (path);
183 static int
184 local_symlink (struct vfs_class *me, const char *n1, const char *n2)
186 (void) me;
188 return symlink (n1, n2);
191 static int
192 local_write (void *data, const char *buf, int nbyte)
194 int fd;
195 int n;
197 if (!data)
198 return -1;
200 fd = * (int *) data;
201 while ((n = write (fd, buf, nbyte)) == -1){
202 #ifdef EAGAIN
203 if (errno == EAGAIN) continue;
204 #endif
205 #ifdef EINTR
206 if (errno == EINTR) continue;
207 #endif
208 break;
210 return n;
213 static int
214 local_rename (struct vfs_class *me, const char *a, const char *b)
216 (void) me;
218 return rename (a, b);
221 static int
222 local_chdir (struct vfs_class *me, const char *path)
224 (void) me;
226 return chdir (path);
230 local_lseek (void *data, off_t offset, int whence)
232 int fd = * (int *) data;
234 return lseek (fd, offset, whence);
237 static int
238 local_mknod (struct vfs_class *me, const char *path, int mode, int dev)
240 (void) me;
242 return mknod (path, mode, dev);
245 static int
246 local_link (struct vfs_class *me, const char *p1, const char *p2)
248 (void) me;
250 return link (p1, p2);
253 static int
254 local_mkdir (struct vfs_class *me, const char *path, mode_t mode)
256 (void) me;
258 return mkdir (path, mode);
261 static int
262 local_rmdir (struct vfs_class *me, const char *path)
264 (void) me;
266 return rmdir (path);
269 static char *
270 local_getlocalcopy (struct vfs_class *me, const char *path)
272 (void) me;
274 return g_strdup (path);
277 static int
278 local_ungetlocalcopy (struct vfs_class *me, const char *path,
279 const char *local, int has_changed)
281 (void) me;
282 (void) path;
283 (void) local;
284 (void) has_changed;
286 return 0;
289 static int
290 local_which (struct vfs_class *me, const char *path)
292 (void) me;
293 (void) path;
295 return 0; /* Every path which other systems do not like is expected to be ours */
298 void
299 init_localfs (void)
301 vfs_local_ops.name = "localfs";
302 vfs_local_ops.flags = VFSF_LOCAL;
303 vfs_local_ops.which = local_which;
304 vfs_local_ops.open = local_open;
305 vfs_local_ops.close = local_close;
306 vfs_local_ops.read = local_read;
307 vfs_local_ops.write = local_write;
308 vfs_local_ops.opendir = local_opendir;
309 vfs_local_ops.readdir = local_readdir;
310 vfs_local_ops.closedir = local_closedir;
311 vfs_local_ops.stat = local_stat;
312 vfs_local_ops.lstat = local_lstat;
313 vfs_local_ops.fstat = local_fstat;
314 vfs_local_ops.chmod = local_chmod;
315 vfs_local_ops.chown = local_chown;
316 vfs_local_ops.utime = local_utime;
317 vfs_local_ops.readlink = local_readlink;
318 vfs_local_ops.symlink = local_symlink;
319 vfs_local_ops.link = local_link;
320 vfs_local_ops.unlink = local_unlink;
321 vfs_local_ops.rename = local_rename;
322 vfs_local_ops.chdir = local_chdir;
323 vfs_local_ops.ferrno = local_errno;
324 vfs_local_ops.lseek = local_lseek;
325 vfs_local_ops.mknod = local_mknod;
326 vfs_local_ops.getlocalcopy = local_getlocalcopy;
327 vfs_local_ops.ungetlocalcopy = local_ungetlocalcopy;
328 vfs_local_ops.mkdir = local_mkdir;
329 vfs_local_ops.rmdir = local_rmdir;
330 vfs_register_class (&vfs_local_ops);