comparison Plugins/Input/wma/libffwma/file.c @ 926:3d4af4890339 trunk

[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
author chainsaw
date Wed, 12 Apr 2006 13:35:24 -0700
parents d539e5c5f730
children a63e0fdb3d1e
comparison
equal deleted inserted replaced
925:25963e82c40f 926:3d4af4890339
20 #include "cutils.h" 20 #include "cutils.h"
21 #include <fcntl.h> 21 #include <fcntl.h>
22 #include <unistd.h> 22 #include <unistd.h>
23 #include <sys/ioctl.h> 23 #include <sys/ioctl.h>
24 #include <sys/time.h> 24 #include <sys/time.h>
25 #include "libaudacious/vfs.h"
25 26
26 /* standard file protocol */ 27 /* standard file protocol */
27 28
28 static int file_open(URLContext *h, const char *filename, int flags) 29 static int file_open(URLContext *h, const char *filename, int flags)
29 { 30 {
30 int access; 31 VFSFile *file;
31 int fd;
32 32
33 strstart(filename, "file:", &filename); 33 strstart(filename, "file:", &filename);
34 34
35 if (flags & URL_WRONLY) { 35 if (flags & URL_WRONLY) {
36 access = O_CREAT | O_TRUNC | O_WRONLY; 36 file = vfs_fopen(filename, "wb");
37 } else { 37 } else {
38 access = O_RDONLY; 38 file = vfs_fopen(filename, "rb");
39 } 39 }
40 40
41 fd = open(filename, access, 0666); 41 if (file == NULL)
42 if (fd < 0)
43 return -ENOENT; 42 return -ENOENT;
44 h->priv_data = (void *)(long)fd; 43 h->priv_data = file;
45 return 0; 44 return 0;
46 } 45 }
47 46
48 static int file_read(URLContext *h, unsigned char *buf, int size) 47 static int file_read(URLContext *h, unsigned char *buf, int size)
49 { 48 {
50 int fd = (int)(long)h->priv_data; 49 VFSFile *file;
51 return read(fd, buf, size); 50 file = h->priv_data;
51 return vfs_fread(buf, 1, size, file);
52 } 52 }
53 53
54 static int file_write(URLContext *h, unsigned char *buf, int size) 54 static int file_write(URLContext *h, unsigned char *buf, int size)
55 { 55 {
56 int fd = (int)(long)h->priv_data; 56 VFSFile *file;
57 return write(fd, buf, size); 57 file = h->priv_data;
58 return vfs_fwrite(buf, 1, size, file);
58 } 59 }
59 60
60 /* XXX: use llseek */ 61 /* XXX: use llseek */
61 static offset_t file_seek(URLContext *h, offset_t pos, int whence) 62 static offset_t file_seek(URLContext *h, offset_t pos, int whence)
62 { 63 {
63 int fd = (int)(long)h->priv_data; 64 int result = 0;
64 return lseek(fd, pos, whence); 65 VFSFile *file;
66 file = h->priv_data;
67 result = vfs_fseek(file, pos, whence);
68 if (result == 0)
69 result = vfs_ftell(file);
70 else
71 result = -1;
72 return result;
65 } 73 }
66 74
67 static int file_close(URLContext *h) 75 static int file_close(URLContext *h)
68 { 76 {
69 int fd = (int)(long)h->priv_data; 77 VFSFile *file;
70 return close(fd); 78 file = h->priv_data;
79 return vfs_fclose(file);
71 } 80 }
72 81
73 URLProtocol file_protocol = { 82 URLProtocol file_protocol = {
74 "file", 83 "file",
75 file_open, 84 file_open,