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