summaryrefslogtreecommitdiff
path: root/uisimulator/common
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2004-06-10 13:29:52 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2004-06-10 13:29:52 +0000
commita6142ab7ab58f69a3f1a034db4bdf1eff24d3dd6 (patch)
treeef00c3ec8074ccb080b221c7d1dd4b3d03c8fd87 /uisimulator/common
parent5fc1b64ae051e454d2b3bf3a20be5d88937e55e7 (diff)
downloadrockbox-a6142ab7ab58f69a3f1a034db4bdf1eff24d3dd6.tar.gz
rockbox-a6142ab7ab58f69a3f1a034db4bdf1eff24d3dd6.zip
Finally, the archos directory sandbox works in the same way for both X11 and win32 simulators. Unfortunately, this breaks the VC++ compatibility. Also, the plugin API now supports DEBUGF. Last, but not least, we have a new plugin, vbrfix.rock.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4726 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/common')
-rw-r--r--uisimulator/common/dir.h45
-rw-r--r--uisimulator/common/file.h71
-rw-r--r--uisimulator/common/io.c225
3 files changed, 341 insertions, 0 deletions
diff --git a/uisimulator/common/dir.h b/uisimulator/common/dir.h
new file mode 100644
index 0000000000..15332be54e
--- /dev/null
+++ b/uisimulator/common/dir.h
@@ -0,0 +1,45 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se>
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#ifndef _SIM_DIR_H_
20#define _SIM_DIR_H_
21
22#include <sys/types.h>
23
24#define DIRFUNCTIONS_DEFINED /* prevent those prototypes */
25#define dirent sim_dirent
26#include "../../firmware/include/dir.h"
27#undef dirent
28
29typedef void * MYDIR;
30
31extern MYDIR *sim_opendir(const char *name);
32extern struct sim_dirent* sim_readdir(MYDIR* dir);
33extern int sim_closedir(MYDIR *dir);
34extern int sim_mkdir(char *name, int mode);
35extern int sim_rmdir(char *name);
36
37#define DIR MYDIR
38#define dirent sim_dirent
39#define opendir(x) sim_opendir(x)
40#define readdir(x) sim_readdir(x)
41#define closedir(x) sim_closedir(x)
42#define mkdir(x, y) sim_mkdir(x, y)
43#define rmdir(x) sim_rmdir(x)
44
45#endif
diff --git a/uisimulator/common/file.h b/uisimulator/common/file.h
new file mode 100644
index 0000000000..8d91b61831
--- /dev/null
+++ b/uisimulator/common/file.h
@@ -0,0 +1,71 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se>
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#ifndef _SIM_FILE_H_
21#define _SIM_FILE_H_
22
23#ifdef WIN32
24#include <io.h>
25#include <fcntl.h>
26#else
27#include <stdio.h>
28#endif
29
30#include <sys/types.h>
31
32#ifdef WIN32
33#ifndef _commit
34extern int _commit( int handle );
35#endif
36#endif
37
38int sim_open(const char *name, int opts);
39int sim_close(int fd);
40int sim_rename(const char *oldpath, const char *newpath);
41int sim_filesize(int fd);
42int sim_creat(const char *name, mode_t mode);
43int sim_remove(const char *name);
44
45#ifndef NO_REDEFINES_PLEASE
46#define open(x,y) sim_open(x,y)
47#define close(x) sim_close(x)
48#define filesize(x) sim_filesize(x)
49#define creat(x,y) sim_creat(x,y)
50#define remove(x) sim_remove(x)
51#define rename(x,y) sim_rename(x,y)
52#ifdef WIN32
53#define fsync _commit
54#endif
55#endif
56
57#include "../../firmware/include/file.h"
58
59#ifndef WIN32
60int open(const char* pathname, int flags);
61int close(int fd);
62int printf(const char *format, ...);
63int ftruncate(int fd, off_t length);
64int fsync(int fd);
65
66off_t lseek(int fildes, off_t offset, int whence);
67ssize_t read(int fd, void *buf, size_t count);
68ssize_t write(int fd, const void *buf, size_t count);
69#endif
70
71#endif
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c
new file mode 100644
index 0000000000..745e417fa6
--- /dev/null
+++ b/uisimulator/common/io.c
@@ -0,0 +1,225 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Daniel Stenberg
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23#include <sys/stat.h>
24#ifdef __FreeBSD__
25#include <sys/param.h>
26#include <sys/mount.h>
27#elif !defined(WIN32)
28#include <sys/vfs.h>
29#endif
30#include <dirent.h>
31#include <unistd.h>
32
33#include <fcntl.h>
34#include "debug.h"
35
36#define DIRFUNCTIONS_DEFINED /* prevent those prototypes */
37#define dirent sim_dirent
38#define DIR SIMDIR
39#include "../../firmware/include/dir.h"
40#undef dirent
41#undef DIR
42
43#define SIMULATOR_ARCHOS_ROOT "archos"
44
45struct mydir {
46 DIR *dir;
47 char *name;
48};
49
50typedef struct mydir MYDIR;
51
52MYDIR *sim_opendir(const char *name)
53{
54 char buffer[256]; /* sufficiently big */
55 DIR *dir;
56
57 if(name[0] == '/') {
58 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
59 dir=(DIR *)opendir(buffer);
60 }
61 else
62 dir=(DIR *)opendir(name);
63
64 if(dir) {
65 MYDIR *my = (MYDIR *)malloc(sizeof(MYDIR));
66 my->dir = dir;
67 my->name = (char *)strdup(name);
68
69 return my;
70 }
71 /* failed open, return NULL */
72 return (MYDIR *)0;
73}
74
75struct sim_dirent *sim_readdir(MYDIR *dir)
76{
77 char buffer[512]; /* sufficiently big */
78 static struct sim_dirent secret;
79 struct stat s;
80 struct dirent *x11 = (readdir)(dir->dir);
81
82 if(!x11)
83 return (struct sim_dirent *)0;
84
85 strcpy(secret.d_name, x11->d_name);
86
87 /* build file name */
88 sprintf(buffer, SIMULATOR_ARCHOS_ROOT "%s/%s",
89 dir->name, x11->d_name);
90 stat(buffer, &s); /* get info */
91
92 secret.attribute = S_ISDIR(s.st_mode)?ATTR_DIRECTORY:0;
93 secret.size = s.st_size;
94
95 return &secret;
96}
97
98void sim_closedir(MYDIR *dir)
99{
100 free(dir->name);
101 (closedir)(dir->dir);
102
103 free(dir);
104}
105
106
107int sim_open(const char *name, int opts)
108{
109 char buffer[256]; /* sufficiently big */
110
111 if(name[0] == '/') {
112 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
113
114 debugf("We open the real file '%s'\n", buffer);
115 return (open)(buffer, opts);
116 }
117 return (open)(name, opts);
118}
119
120int sim_close(int fd)
121{
122 return (close)(fd);
123}
124
125int sim_creat(const char *name, mode_t mode)
126{
127 char buffer[256]; /* sufficiently big */
128 (void)mode;
129 if(name[0] == '/') {
130 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
131
132 debugf("We create the real file '%s'\n", buffer);
133 return (creat)(buffer, 0666);
134 }
135 return (creat)(name, 0666);
136}
137
138int sim_mkdir(const char *name, mode_t mode)
139{
140 char buffer[256]; /* sufficiently big */
141 (void)mode;
142
143 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
144
145 debugf("We create the real directory '%s'\n", buffer);
146#ifdef WIN32
147 return (mkdir)(buffer);
148#else
149 return (mkdir)(buffer, 0666);
150#endif
151}
152
153int sim_rmdir(const char *name)
154{
155 char buffer[256]; /* sufficiently big */
156 if(name[0] == '/') {
157 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
158
159 debugf("We remove the real directory '%s'\n", buffer);
160 return (rmdir)(buffer);
161 }
162 return (rmdir)(name);
163}
164
165int sim_remove(const char *name)
166{
167 char buffer[256]; /* sufficiently big */
168
169 if(name[0] == '/') {
170 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
171
172 debugf("We remove the real file '%s'\n", buffer);
173 return (remove)(buffer);
174 }
175 return (remove)(name);
176}
177
178int sim_rename(const char *oldpath, const char* newpath)
179{
180 char buffer1[256];
181 char buffer2[256];
182
183 if(oldpath[0] == '/') {
184 sprintf(buffer1, "%s%s", SIMULATOR_ARCHOS_ROOT, oldpath);
185 sprintf(buffer2, "%s%s", SIMULATOR_ARCHOS_ROOT, newpath);
186
187 debugf("We rename the real file '%s' to '%s'\n", buffer1, buffer2);
188 return (rename)(buffer1, buffer2);
189 }
190 return -1;
191}
192
193int sim_filesize(int fd)
194{
195 int old = lseek(fd, 0, SEEK_CUR);
196 int size = lseek(fd, 0, SEEK_END);
197 lseek(fd, old, SEEK_SET);
198
199 return(size);
200}
201
202void fat_size(unsigned int* size, unsigned int* free)
203{
204#ifdef WIN32
205 *size = 2049;
206 *free = 1037;
207#else
208 struct statfs fs;
209
210 if (!statfs(".", &fs)) {
211 DEBUGF("statfs: bsize=%d blocks=%d free=%d\n",
212 fs.f_bsize, fs.f_blocks, fs.f_bfree);
213 if (size)
214 *size = fs.f_blocks * (fs.f_bsize / 1024);
215 if (free)
216 *free = fs.f_bfree * (fs.f_bsize / 1024);
217 }
218 else {
219 if (size)
220 *size = 0;
221 if (free)
222 *free = 0;
223 }
224#endif
225}