summaryrefslogtreecommitdiff
path: root/firmware/target
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-09-01 21:29:34 +0000
committerThomas Martitz <kugel@rockbox.org>2010-09-01 21:29:34 +0000
commit6eaab4d00446c070c655f0e6c9a872532a776b6f (patch)
tree69610996dd0a6092459b14e164d4e48e03b1e5bb /firmware/target
parent8e0a0babc57db3e9edc06f3e269fb47c27292ed5 (diff)
downloadrockbox-6eaab4d00446c070c655f0e6c9a872532a776b6f.tar.gz
rockbox-6eaab4d00446c070c655f0e6c9a872532a776b6f.zip
Ged rid of uisimulator/common/io.c for android builds.
Use host's functions for file i/o directly (open(), close() ,etc.), not the sim_* variants. Some dir functions need to be wrapped still because we need to cache the parents dir's path (host's dirent doesn't let us know). For the same reason (incompatibility) with host's dirent) detach some members from Rockbox' dirent struct and put it into an extra one, the values can be retrieved via the new dir_get_info(). Get rid of the sim_ prefix for sleep as well and change the signature to unix sleep(). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27968 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target')
-rw-r--r--firmware/target/hosted/android/dir-target.h37
-rw-r--r--firmware/target/hosted/android/fs-android.c129
-rw-r--r--firmware/target/hosted/android/lc-android.c40
3 files changed, 206 insertions, 0 deletions
diff --git a/firmware/target/hosted/android/dir-target.h b/firmware/target/hosted/android/dir-target.h
new file mode 100644
index 0000000000..4516215d62
--- /dev/null
+++ b/firmware/target/hosted/android/dir-target.h
@@ -0,0 +1,37 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __DIR_TARGET_H__
23#define __DIR_TARGET_H__
24
25#include <dirent.h>
26
27#define opendir _opendir
28#define mkdir _mkdir
29#define closedir _closedir
30#define readdir _readdir
31
32extern DIR* _opendir(const char* name);
33extern int _mkdir(const char* name);
34extern int _closedir(DIR* dir);
35extern struct dirent *_readdir(DIR* dir);
36
37#endif /* __DIR_TARGET_H__ */
diff --git a/firmware/target/hosted/android/fs-android.c b/firmware/target/hosted/android/fs-android.c
new file mode 100644
index 0000000000..5209458e54
--- /dev/null
+++ b/firmware/target/hosted/android/fs-android.c
@@ -0,0 +1,129 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <stdlib.h>
23#include <sys/stat.h> /* stat() */
24#include <stdio.h> /* snprintf */
25#include <string.h> /* size_t */
26#include <dirent.h>
27#include <time.h> /* localtime() */
28#include "system-target.h"
29#include "dir-target.h"
30#include "file.h"
31#include "dir.h"
32
33
34long filesize(int fd)
35{
36 struct stat buf;
37
38 if (!fstat(fd, &buf))
39 return buf.st_size;
40 else
41 return -1;
42}
43
44/* do we really need this in the app? */
45void fat_size(unsigned long* size, unsigned long* free)
46{
47 *size = *free = 0;
48}
49
50#undef opendir
51#undef closedir
52#undef mkdir
53#undef readdir
54
55/* need to wrap around DIR* because we need to save the parent's
56 * directory path in order to determine dirinfo */
57struct __dir {
58 DIR *dir;
59 char *path;
60};
61
62DIR* _opendir(const char *name)
63{
64 char *buf = malloc(sizeof(struct __dir) + strlen(name)+1);
65 if (!buf)
66 return NULL;
67
68 struct __dir *this = (struct __dir*)buf;
69
70 this->path = buf+sizeof(struct __dir);
71 /* definitely fits due to strlen() */
72 strcpy(this->path, name);
73
74 this->dir = opendir(name);
75
76 if (!this->dir)
77 {
78 free(buf);
79 return NULL;
80 }
81 return (DIR*)this;
82}
83
84int _mkdir(const char *name)
85{
86 return mkdir(name, 0777);
87}
88
89int _closedir(DIR *dir)
90{
91 struct __dir *this = (struct __dir*)dir;
92 int ret = closedir(this->dir);
93 free(this);
94 return ret;
95}
96
97struct dirent* _readdir(DIR* dir)
98{
99 struct __dir *d = (struct __dir*)dir;
100 return readdir(d->dir);
101}
102
103struct dirinfo dir_get_info(struct DIR* _parent, struct dirent *dir)
104{
105 struct __dir *parent = (struct __dir*)_parent;
106 struct stat s;
107 struct tm *tm;
108 struct dirinfo ret;
109 char path[MAX_PATH];
110
111 snprintf(path, sizeof(path), "%s/%s", parent->path, dir->d_name);
112 stat(path, &s);
113 memset(&ret, 0, sizeof(ret));
114
115 if (S_ISDIR(s.st_mode))
116 {
117 ret.attribute = ATTR_DIRECTORY;
118 }
119
120 ret.size = s.st_size;
121 tm = localtime(&(s.st_mtime));
122 ret.wrtdate = ((tm->tm_year - 80) << 9) |
123 ((tm->tm_mon + 1) << 5) |
124 tm->tm_mday;
125 ret.wrttime = (tm->tm_hour << 11) |
126 (tm->tm_min << 5) |
127 (tm->tm_sec >> 1);
128 return ret;
129}
diff --git a/firmware/target/hosted/android/lc-android.c b/firmware/target/hosted/android/lc-android.c
new file mode 100644
index 0000000000..52ab08badb
--- /dev/null
+++ b/firmware/target/hosted/android/lc-android.c
@@ -0,0 +1,40 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <string.h> /* size_t */
23#include "load_code.h"
24
25/* the load_code wrappers simply wrap, nothing to do */
26void *lc_open(const char *filename, char *buf, size_t buf_size)
27{
28 return _lc_open(filename, buf, buf_size);
29}
30
31void *lc_get_header(void *handle)
32{
33 return _lc_get_header(handle);
34}
35
36void lc_close(void *handle)
37{
38 _lc_close(handle);
39}
40