1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Port of xrick, a Rick Dangerous clone, to Rockbox.
* See http://www.bigorno.net/xrick/
*
* Copyright (C) 2008-2014 Pierluigi Vicinanza
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "xrick/system/system.h"
#include "xrick/config.h"
#include "xrick/util.h"
#include "plugin.h"
#define XRICK_GAME_DIR ROCKBOX_DIR "/xrick/"
/*
* Global variables
*/
const char *sysfile_defaultPath = XRICK_GAME_DIR;
/*
* Local variables
*/
static char *rootPath = NULL;
/*
*
*/
bool sysfile_setRootPath(const char *name)
{
rootPath = u_strdup(name);
return (rootPath != NULL);
}
/*
*
*/
void sysfile_clearRootPath()
{
sysmem_pop(rootPath);
rootPath = NULL;
}
/*
* Open a data file.
*/
file_t sysfile_open(const char *name)
{
long fd;
size_t fullPathLength = rb->strlen(rootPath) + rb->strlen(name) + 2;
char *fullPath = sysmem_push(fullPathLength);
if (!fullPath)
{
return NULL;
}
rb->snprintf(fullPath, fullPathLength, "%s/%s", rootPath, name);
fd = rb->open(fullPath, O_RDONLY);
sysmem_pop(fullPath);
/*
* note: I've never seen zero/NULL being used as a file descriptor under Rockbox.
* Putting a check here in case this will ever happen (will need a fix).
*/
if (fd == 0)
{
sys_error("(file) unsupported file descriptor (zero/NULL) being used");
}
if (fd < 0)
{
return NULL;
}
return (file_t)fd;
}
/*
* Read a file within a data archive.
*/
int sysfile_read(file_t file, void *buf, size_t size, size_t count)
{
long fd = (long)file;
return (rb->read(fd, buf, size * count) / size);
}
/*
* Seek.
*/
int sysfile_seek(file_t file, long offset, int origin)
{
long fd = (long)file;
return rb->lseek(fd, offset, origin);
}
/*
* Close a file within a data archive.
*/
void sysfile_close(file_t file)
{
long fd = (long)file;
rb->close(fd);
}
/* eof */
|