summaryrefslogtreecommitdiff
path: root/riscos
diff options
context:
space:
mode:
Diffstat (limited to 'riscos')
-rw-r--r--riscos/ReadMe8
-rw-r--r--riscos/stubs/ReadMe11
-rw-r--r--riscos/stubs/stubs.c122
3 files changed, 136 insertions, 5 deletions
diff --git a/riscos/ReadMe b/riscos/ReadMe
index 5419b3f..0afd03b 100644
--- a/riscos/ReadMe
+++ b/riscos/ReadMe
@@ -14,19 +14,17 @@ Use the Boot merge facility in Configure to merge the provided !Boot directory
with the one on your system. If there is no !Boot merge facility provided on
your system, simply drag the !Boot directory over your existing boot structure.
-Module source can be found in the "src" directory.
Further documentation can be found in the "doc" directory.
Note for developers:
~~~~~~~~~~~~~~~~~~~~
-The libiconv stubs provided are suitable for use with the SCL.
-UnixLib users should be aware that an interface for this module is provided by
-UnixLib itself.
+The "stubs" directory contains source for a set of C stubs.
+See the ReadMe file in that directory for further information.
Licence
=======
-Iconv is Copyright © 2004-7 J-M Bell
+Iconv is Copyright © 2004-8 J-M Bell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/riscos/stubs/ReadMe b/riscos/stubs/ReadMe
new file mode 100644
index 0000000..40c117a
--- /dev/null
+++ b/riscos/stubs/ReadMe
@@ -0,0 +1,11 @@
+Iconv module stubs
+==================
+
+This directory contains the source code required to build suitable stubs
+for interfacing with the Iconv module from C. The stubs provide the standard
+iconv_open, iconv, and iconv_close API entry points.
+
+UnixLib users should use the veneers provided by that library. These stubs are
+provided for the convenience of those using the Shared C Library, or other
+runtime.
+
diff --git a/riscos/stubs/stubs.c b/riscos/stubs/stubs.c
new file mode 100644
index 0000000..aec8cf6
--- /dev/null
+++ b/riscos/stubs/stubs.c
@@ -0,0 +1,122 @@
+/* Iconv stubs */
+
+#include <errno.h>
+
+#include <sys/errno.h>
+
+#include "swis.h"
+
+#include "iconv.h"
+
+/* SWI numbers */
+#define Iconv_Open (0x57540)
+#define Iconv_Iconv (0x57541)
+#define Iconv_Close (0x57542)
+#define Iconv_Convert (0x57543)
+#define Iconv_CreateMenu (0x57544)
+#define Iconv_DecodeMenu (0x57545)
+
+/* Error numbers */
+#define ERROR_BASE 0x81b900
+
+#define ICONV_NOMEM (ERROR_BASE+0)
+#define ICONV_INVAL (ERROR_BASE+1)
+#define ICONV_2BIG (ERROR_BASE+2)
+#define ICONV_ILSEQ (ERROR_BASE+3)
+
+iconv_t iconv_open(const char *tocode, const char *fromcode)
+{
+ iconv_t ret;
+ _kernel_oserror *error;
+
+ error = _swix(Iconv_Open, _INR(0,1) | _OUT(0),
+ tocode, fromcode,
+ &ret);
+ if (error) {
+ switch (error->errnum) {
+ case ICONV_NOMEM:
+ errno = ENOMEM;
+ break;
+ case ICONV_INVAL:
+ errno = EINVAL;
+ break;
+ case ICONV_2BIG:
+ errno = E2BIG;
+ break;
+ case ICONV_ILSEQ:
+ errno = EILSEQ;
+ break;
+ default:
+ errno = EINVAL; /* munge BAD_SWI to EINVAL */
+ break;
+ }
+ return (iconv_t)(-1);
+ }
+
+ return ret;
+}
+
+size_t iconv(iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf,
+ size_t *outbytesleft)
+{
+ size_t ret;
+ _kernel_oserror *error;
+
+ error = _swix(Iconv_Iconv, _INR(0,4) | _OUT(0),
+ cd, inbuf, inbytesleft, outbuf, outbytesleft,
+ &ret);
+ if (error) {
+ switch (error->errnum) {
+ case ICONV_NOMEM:
+ errno = ENOMEM;
+ break;
+ case ICONV_INVAL:
+ errno = EINVAL;
+ break;
+ case ICONV_2BIG:
+ errno = E2BIG;
+ break;
+ case ICONV_ILSEQ:
+ errno = EILSEQ;
+ break;
+ default:
+ errno = EINVAL; /* munge BAD_SWI to EINVAL */
+ break;
+ }
+ return (size_t)(-1);
+ }
+
+ return ret;
+}
+
+int iconv_close(iconv_t cd)
+{
+ int ret;
+ _kernel_oserror *error;
+
+ error = _swix(Iconv_Close, _IN(0) | _OUT(0),
+ cd,
+ &ret);
+ if (error) {
+ switch (error->errnum) {
+ case ICONV_NOMEM:
+ errno = ENOMEM;
+ break;
+ case ICONV_INVAL:
+ errno = EINVAL;
+ break;
+ case ICONV_2BIG:
+ errno = E2BIG;
+ break;
+ case ICONV_ILSEQ:
+ errno = EILSEQ;
+ break;
+ default:
+ errno = EINVAL; /* munge BAD_SWI to EINVAL */
+ break;
+ }
+ return -1;
+ }
+
+ return ret;
+}