diff options
author | Franklin Wei <git@fwei.tk> | 2017-01-21 15:18:31 -0500 |
---|---|---|
committer | Franklin Wei <git@fwei.tk> | 2017-12-23 21:01:26 -0500 |
commit | a855d6202536ff28e5aae4f22a0f31d8f5b325d0 (patch) | |
tree | 8c75f224dd64ed360505afa8843d016b0d75000b /apps/plugins/lib | |
parent | 01c6dcf6c7b9bb1ad2fa0450f99bacc5f3d3e04b (diff) | |
download | rockbox-a855d6202536ff28e5aae4f22a0f31d8f5b325d0.tar.gz rockbox-a855d6202536ff28e5aae4f22a0f31d8f5b325d0.zip |
Port of Duke Nukem 3D
This ports Fabien Sanglard's Chocolate Duke to run on a version of SDL
for Rockbox.
Change-Id: I8f2c4c78af19de10c1633ed7bb7a997b43256dd9
Diffstat (limited to 'apps/plugins/lib')
-rw-r--r-- | apps/plugins/lib/stdio_compat.c | 50 | ||||
-rw-r--r-- | apps/plugins/lib/stdio_compat.h | 6 |
2 files changed, 44 insertions, 12 deletions
diff --git a/apps/plugins/lib/stdio_compat.c b/apps/plugins/lib/stdio_compat.c index d2b8f9bbc7..957dd0ddc1 100644 --- a/apps/plugins/lib/stdio_compat.c +++ b/apps/plugins/lib/stdio_compat.c | |||
@@ -20,12 +20,16 @@ | |||
20 | 20 | ||
21 | #include "plugin.h" | 21 | #include "plugin.h" |
22 | #include "stdio_compat.h" | 22 | #include "stdio_compat.h" |
23 | #include "errno.h" | ||
23 | 24 | ||
24 | static _FILE_ __file__[MAX_STDIO_FILES] = { | 25 | static _FILE_ __file__[MAX_STDIO_FILES] = { |
25 | {-1,-1,0},{-1,-1,0},{-1,-1,0},{-1,-1,0}, | 26 | {-1,-1,0},{-1,-1,0},{-1,-1,0},{-1,-1,0}, |
26 | {-1,-1,0},{-1,-1,0},{-1,-1,0},{-1,-1,0} | 27 | {-1,-1,0},{-1,-1,0},{-1,-1,0},{-1,-1,0}, |
28 | {-1,-1,0},{-1,-1,0},{-1,-1,0} | ||
27 | }; | 29 | }; |
28 | 30 | ||
31 | _FILE_ *_stdout_ = NULL, *_stderr_ = NULL; | ||
32 | |||
29 | _FILE_ *_fopen_(const char *path, const char *mode) | 33 | _FILE_ *_fopen_(const char *path, const char *mode) |
30 | { | 34 | { |
31 | _FILE_ *f = __file__; | 35 | _FILE_ *f = __file__; |
@@ -34,13 +38,16 @@ _FILE_ *_fopen_(const char *path, const char *mode) | |||
34 | int i; | 38 | int i; |
35 | 39 | ||
36 | /* look for free slot */ | 40 | /* look for free slot */ |
37 | for (i=0; i<MAX_OPEN_FILES; i++, f++) | 41 | for (i=0; i<MAX_STDIO_FILES; i++, f++) |
38 | if (f->fd == -1) | 42 | if (f->fd == -1) |
39 | break; | 43 | break; |
40 | 44 | ||
41 | /* no empty slots */ | 45 | /* no empty slots */ |
42 | if (i == MAX_STDIO_FILES) | 46 | if (i == MAX_STDIO_FILES) |
47 | { | ||
48 | rb->splash(HZ, "no open slots"); | ||
43 | return NULL; | 49 | return NULL; |
50 | } | ||
44 | 51 | ||
45 | if (*mode != 'r') | 52 | if (*mode != 'r') |
46 | { | 53 | { |
@@ -72,10 +79,14 @@ _FILE_ *_fopen_(const char *path, const char *mode) | |||
72 | } | 79 | } |
73 | 80 | ||
74 | 81 | ||
75 | fd = rb->open(path, flags); | 82 | fd = rb->open(path, flags, 0666); |
76 | 83 | ||
77 | if (fd == -1) | 84 | if (fd < 0) |
85 | { | ||
86 | //extern int errno; | ||
87 | //rb->splashf(HZ*2, "open of %s failed (%d)", path, errno); | ||
78 | return NULL; | 88 | return NULL; |
89 | } | ||
79 | 90 | ||
80 | /* initialize */ | 91 | /* initialize */ |
81 | f->fd = fd; | 92 | f->fd = fd; |
@@ -97,23 +108,40 @@ size_t _fread_(void *ptr, size_t size, size_t nmemb, _FILE_ *stream) | |||
97 | 108 | ||
98 | if (ret < (ssize_t)(size*nmemb)) | 109 | if (ret < (ssize_t)(size*nmemb)) |
99 | stream->error = -1; | 110 | stream->error = -1; |
100 | 111 | return ret / size; | |
101 | return ret; | ||
102 | } | 112 | } |
103 | 113 | ||
104 | size_t _fwrite_(const void *ptr, size_t size, size_t nmemb, _FILE_ *stream) | 114 | size_t _fwrite_(const void *ptr, size_t size, size_t nmemb, _FILE_ *stream) |
105 | { | 115 | { |
106 | ssize_t ret = rb->write(stream->fd, ptr, size*nmemb); | 116 | if(stream) |
117 | { | ||
118 | ssize_t ret = rb->write(stream->fd, ptr, size*nmemb); | ||
107 | 119 | ||
108 | if (ret < (ssize_t)(size*nmemb)) | 120 | if (ret < (ssize_t)(size*nmemb)) |
109 | stream->error = -1; | 121 | stream->error = -1; |
110 | 122 | ||
111 | return ret; | 123 | return ret / size; |
124 | } | ||
125 | #if 1 | ||
126 | else | ||
127 | { | ||
128 | char buf[10]; | ||
129 | rb->snprintf(buf, 10, "%%%ds", size*nmemb); | ||
130 | rb->splashf(HZ, buf, ptr); | ||
131 | return size * nmemb; | ||
132 | } | ||
133 | #endif | ||
112 | } | 134 | } |
113 | 135 | ||
114 | int _fseek_(_FILE_ *stream, long offset, int whence) | 136 | int _fseek_(_FILE_ *stream, long offset, int whence) |
115 | { | 137 | { |
116 | return rb->lseek(stream->fd, offset, whence); | 138 | if(rb->lseek(stream->fd, offset, whence) >= 0) |
139 | return 0; | ||
140 | else | ||
141 | { | ||
142 | rb->splashf(HZ, "lseek() failed: %d fd:%d", errno, stream->fd); | ||
143 | return -1; | ||
144 | } | ||
117 | } | 145 | } |
118 | 146 | ||
119 | long _ftell_(_FILE_ *stream) | 147 | long _ftell_(_FILE_ *stream) |
diff --git a/apps/plugins/lib/stdio_compat.h b/apps/plugins/lib/stdio_compat.h index bb37940296..27ccfcf521 100644 --- a/apps/plugins/lib/stdio_compat.h +++ b/apps/plugins/lib/stdio_compat.h | |||
@@ -20,7 +20,7 @@ | |||
20 | 20 | ||
21 | #include <stddef.h> | 21 | #include <stddef.h> |
22 | 22 | ||
23 | #define MAX_STDIO_FILES 8 | 23 | #define MAX_STDIO_FILES 11 |
24 | 24 | ||
25 | #undef FILE | 25 | #undef FILE |
26 | #define FILE _FILE_ | 26 | #define FILE _FILE_ |
@@ -42,6 +42,8 @@ | |||
42 | #define ferror _ferror_ | 42 | #define ferror _ferror_ |
43 | #define feof _feof_ | 43 | #define feof _feof_ |
44 | #define fprintf _fprintf_ | 44 | #define fprintf _fprintf_ |
45 | #define stdout _stdout_ | ||
46 | #define stderr _stderr_ | ||
45 | 47 | ||
46 | typedef struct { | 48 | typedef struct { |
47 | int fd; | 49 | int fd; |
@@ -49,6 +51,8 @@ typedef struct { | |||
49 | int error; | 51 | int error; |
50 | } _FILE_; | 52 | } _FILE_; |
51 | 53 | ||
54 | extern _FILE_ *_stdout_, *_stderr_; | ||
55 | |||
52 | _FILE_ *_fopen_(const char *path, const char *mode); | 56 | _FILE_ *_fopen_(const char *path, const char *mode); |
53 | int _fclose_(_FILE_ *stream); | 57 | int _fclose_(_FILE_ *stream); |
54 | int _fflush_(_FILE_ *stream); | 58 | int _fflush_(_FILE_ *stream); |