summaryrefslogtreecommitdiff
path: root/apps/plugins/lib/stdio_compat.c
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2017-01-21 15:18:31 -0500
committerFranklin Wei <git@fwei.tk>2017-12-23 21:01:26 -0500
commita855d6202536ff28e5aae4f22a0f31d8f5b325d0 (patch)
tree8c75f224dd64ed360505afa8843d016b0d75000b /apps/plugins/lib/stdio_compat.c
parent01c6dcf6c7b9bb1ad2fa0450f99bacc5f3d3e04b (diff)
downloadrockbox-a855d6202536ff28e5aae4f22a0f31d8f5b325d0.zip
rockbox-a855d6202536ff28e5aae4f22a0f31d8f5b325d0.tar.gz
rockbox-a855d6202536ff28e5aae4f22a0f31d8f5b325d0.tar.bz2
rockbox-a855d6202536ff28e5aae4f22a0f31d8f5b325d0.tar.xz
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/stdio_compat.c')
-rw-r--r--apps/plugins/lib/stdio_compat.c50
1 files changed, 39 insertions, 11 deletions
diff --git a/apps/plugins/lib/stdio_compat.c b/apps/plugins/lib/stdio_compat.c
index d2b8f9b..957dd0d 100644
--- a/apps/plugins/lib/stdio_compat.c
+++ b/apps/plugins/lib/stdio_compat.c
@@ -20,12 +20,16 @@
#include "plugin.h"
#include "stdio_compat.h"
+#include "errno.h"
static _FILE_ __file__[MAX_STDIO_FILES] = {
{-1,-1,0},{-1,-1,0},{-1,-1,0},{-1,-1,0},
- {-1,-1,0},{-1,-1,0},{-1,-1,0},{-1,-1,0}
+ {-1,-1,0},{-1,-1,0},{-1,-1,0},{-1,-1,0},
+ {-1,-1,0},{-1,-1,0},{-1,-1,0}
};
+_FILE_ *_stdout_ = NULL, *_stderr_ = NULL;
+
_FILE_ *_fopen_(const char *path, const char *mode)
{
_FILE_ *f = __file__;
@@ -34,13 +38,16 @@ _FILE_ *_fopen_(const char *path, const char *mode)
int i;
/* look for free slot */
- for (i=0; i<MAX_OPEN_FILES; i++, f++)
+ for (i=0; i<MAX_STDIO_FILES; i++, f++)
if (f->fd == -1)
break;
/* no empty slots */
if (i == MAX_STDIO_FILES)
+ {
+ rb->splash(HZ, "no open slots");
return NULL;
+ }
if (*mode != 'r')
{
@@ -72,10 +79,14 @@ _FILE_ *_fopen_(const char *path, const char *mode)
}
- fd = rb->open(path, flags);
+ fd = rb->open(path, flags, 0666);
- if (fd == -1)
+ if (fd < 0)
+ {
+ //extern int errno;
+ //rb->splashf(HZ*2, "open of %s failed (%d)", path, errno);
return NULL;
+ }
/* initialize */
f->fd = fd;
@@ -97,23 +108,40 @@ size_t _fread_(void *ptr, size_t size, size_t nmemb, _FILE_ *stream)
if (ret < (ssize_t)(size*nmemb))
stream->error = -1;
-
- return ret;
+ return ret / size;
}
size_t _fwrite_(const void *ptr, size_t size, size_t nmemb, _FILE_ *stream)
{
- ssize_t ret = rb->write(stream->fd, ptr, size*nmemb);
+ if(stream)
+ {
+ ssize_t ret = rb->write(stream->fd, ptr, size*nmemb);
- if (ret < (ssize_t)(size*nmemb))
- stream->error = -1;
+ if (ret < (ssize_t)(size*nmemb))
+ stream->error = -1;
- return ret;
+ return ret / size;
+ }
+#if 1
+ else
+ {
+ char buf[10];
+ rb->snprintf(buf, 10, "%%%ds", size*nmemb);
+ rb->splashf(HZ, buf, ptr);
+ return size * nmemb;
+ }
+#endif
}
int _fseek_(_FILE_ *stream, long offset, int whence)
{
- return rb->lseek(stream->fd, offset, whence);
+ if(rb->lseek(stream->fd, offset, whence) >= 0)
+ return 0;
+ else
+ {
+ rb->splashf(HZ, "lseek() failed: %d fd:%d", errno, stream->fd);
+ return -1;
+ }
}
long _ftell_(_FILE_ *stream)