summaryrefslogtreecommitdiff
path: root/module/stubs.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-11-10 18:43:09 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-11-10 18:43:09 +0000
commitf8d8287cdbd7da9cd9392bcddf04860a10fa598e (patch)
tree668b4cc601fdfd050a51095d4f9bbebef9eaffec /module/stubs.c
downloadiconv-f8d8287cdbd7da9cd9392bcddf04860a10fa598e.tar.gz
iconv-f8d8287cdbd7da9cd9392bcddf04860a10fa598e.tar.bz2
Import Iconv sources
svn path=/trunk/iconv/; revision=5677
Diffstat (limited to 'module/stubs.c')
-rw-r--r--module/stubs.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/module/stubs.c b/module/stubs.c
new file mode 100644
index 0000000..96dee4b
--- /dev/null
+++ b/module/stubs.c
@@ -0,0 +1,102 @@
+/* Iconv stubs */
+
+#include <errno.h>
+
+#include <sys/errno.h>
+
+#include "swis.h"
+
+#include "errors.h" /* for error numbers */
+#include "header.h" /* for SWI numbers */
+#include "iconv.h"
+
+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;
+}