Libs/iconv: Untied from Libc, export table added
All checks were successful
Build system / Check kernel codestyle (pull_request) Successful in 39s
Build system / Build (pull_request) Successful in 11m11s

Signed-off-by: Maxim Logaev <maxlogaev@proton.me>
This commit is contained in:
2025-03-06 01:41:57 +03:00
committed by Max Logaev
parent c9137c9aea
commit 63ff372400
3 changed files with 79 additions and 18 deletions

View File

@@ -1,2 +1,2 @@
if tup.getconfig("NO_GCC") ~= "" then return end if tup.getconfig("NO_GCC") ~= "" then return end
tup.rule("iconv.c", "kos32-gcc -c -I../../../../contrib/sdk/sources/newlib/libc/include/ -fno-ident -Os -c -o %o %f " .. tup.getconfig("KPACK_CMD"), "iconv.obj") tup.rule("iconv.c", "kos32-gcc -D_KOLIBRI -Os -fno-ident -fno-leading-underscore -fno-pie -c -o %o %f && kos32-strip %o --strip-unneeded " .. tup.getconfig("KPACK_CMD"), "iconv.obj")

View File

@@ -1,6 +1,10 @@
#ifdef _KOLIBRI
#include "libc_stub.h"
#else
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#endif
typedef int conv_t; typedef int conv_t;
typedef unsigned int ucs4_t; typedef unsigned int ucs4_t;
@@ -39,6 +43,7 @@ typedef int iconv_t;
int encoding(const char *someencoding) { int encoding(const char *someencoding) {
#if 0
char *what = strdup(someencoding); char *what = strdup(someencoding);
/* Ignore //TRANSLIT or //IGNORE for now. */ /* Ignore //TRANSLIT or //IGNORE for now. */
int i; int i;
@@ -48,6 +53,9 @@ int encoding(const char *someencoding) {
break; break;
} }
} }
#else
const char *what = someencoding;
#endif
if (!strcasecmp(what,"CP866")) return CP866; if (!strcasecmp(what,"CP866")) return CP866;
if (!strcasecmp(what,"CP1251")) return CP1251; if (!strcasecmp(what,"CP1251")) return CP1251;
@@ -190,6 +198,23 @@ size_t iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft,
return count1; return count1;
} }
char *iconv_strerr(void)
{
switch (errno)
{
case 0:
return "Success";
case EINVAL:
return "Invalid argument";
case EILSEQ:
return "Illegal byte sequence";
case E2BIG:
return "Arg list too long";
default:
return "Unknown error";
}
}
/* int main() */ /* int main() */
/* { */ /* { */
/* char *s;// ="вертолет"; */ /* char *s;// ="вертолет"; */
@@ -248,22 +273,26 @@ size_t iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft,
/* //for (;s<s+strlen(s);s++) {cp866_mbtowc (0, &pwc, s, 1);printf("%c=%u\n",*s,pwc);} */ /* //for (;s<s+strlen(s);s++) {cp866_mbtowc (0, &pwc, s, 1);printf("%c=%u\n",*s,pwc);} */
/* } */ /* } */
/* typedef struct */ #ifdef _KOLIBRI
/* { */
/* char *name; */
/* void *f; */
/* } export_t; */
/* char szStart[] = "START"; */ typedef struct {
/* char szVersion[] = "version"; */ char *name;
/* char sziconv_open[] = "iconv_open"; */ void *f;
/* char sziconv[] = "iconv"; */ } export_t;
/* export_t EXPORTS[] __asm__("EXPORTS") = */ char szStart[] = "START";
/* { */ char szVersion[] = "version";
/* { szStart, (void*)0x0 }, */ char sziconv_open[] = "iconv_open";
/* { szVersion, (void*)0x00010001 }, */ char sziconv[] = "iconv";
/* { sziconv_open, iconv_open }, */ char sziconv_err[] = "iconv_strerr";
/* { sziconv, iconv }, */
/* { NULL, NULL }, */ export_t EXPORTS[] = {
/* }; */ { szStart, (void*)0x0 },
{ szVersion, (void*)0x00010001 },
{ sziconv_open, iconv_open },
{ sziconv, iconv },
{ sziconv_err, iconv_strerr },
{ NULL, NULL }
};
#endif

View File

@@ -0,0 +1,32 @@
#ifndef _LIBC_STUB_
#define _LIBC_STUB_
#define NULL (void*)0
static int errno = 0;
#define EINVAL 1 /* Invalid argument */
#define EILSEQ 2 /* Illegal byte sequence */
#define E2BIG 3 /* Arg list too long */
typedef unsigned long size_t;
static inline int isupper(int c)
{
return (unsigned)c-'A' < 26;
}
static inline int tolower(int c)
{
if (isupper(c)) return c | 32;
return c;
}
static inline int strcasecmp(const char *_l, const char *_r)
{
const unsigned char *l=(unsigned char*)_l, *r=(unsigned char*)_r;
for (; *l && *r && (*l == *r || tolower(*l) == tolower(*r)); l++, r++);
return tolower(*l) - tolower(*r);
}
#endif // _LIBC_STUB_