From: Alan Cox Date: Fri, 16 Jan 2015 00:32:04 +0000 (+0000) Subject: libc: various minimalist locale stuff (C locale wrappers basically) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=5549c5f4386fc9a274dc87889668c1264a0b8906;p=FUZIX.git libc: various minimalist locale stuff (C locale wrappers basically) --- diff --git a/Library/libs/Makefile b/Library/libs/Makefile index 9f9e5eb9..e59954f3 100644 --- a/Library/libs/Makefile +++ b/Library/libs/Makefile @@ -28,9 +28,9 @@ SRC_C += malloc.c mkfifo.c nanosleep.c opendir.c pause.c perror.c SRC_C += popen.c printf.c putenv.c putgetch.c putpwent.c pwent.c qsort.c SRC_C += raise.c rand.c readdir.c readlink.c realloc.c regerror.c SRC_C += regsub.c remove.c rewind.c rindex.c setbuffer.c setenv.c setjmp.c -SRC_C += setvbuf.c settimeofday.c sleep.c sprintf.c stat.c stdio0.c +SRC_C += setlocale.c setvbuf.c settimeofday.c sleep.c sprintf.c stat.c stdio0.c SRC_C += strcasecmp.c strcasestr.c strdup.c stricmp.c strlcpy.c strncasecmp.c -SRC_C += strnicmp.c strsep.c +SRC_C += strnlen.c strnicmp.c strsep.c strxfrm.c strcoll.c SRC_C += strtod.c strtol.c system.c time.c tmpnam.c ttyname.c SRC_C += tzset.c ungetc.c utent.c utimes.c utsname.c SRC_C += vfprintf.c vprintf.c wait.c xitoa.c pathconf.c diff --git a/Library/libs/Makefile.6502 b/Library/libs/Makefile.6502 index 84434ec2..e2690202 100644 --- a/Library/libs/Makefile.6502 +++ b/Library/libs/Makefile.6502 @@ -46,9 +46,9 @@ SRC_C += malloc.c mkfifo.c nanosleep.c opendir.c pause.c perror.c SRC_C += popen.c printf.c putenv.c putgetch.c putpwent.c pwent.c qsort.c SRC_C += raise.c rand.c readdir.c readlink.c realloc.c regerror.c SRC_C += regsub.c remove.c rewind.c rindex.c setbuffer.c setenv.c setjmp.c -SRC_C += setvbuf.c settimeofday.c sleep.c sprintf.c stat.c stdio0.c +SRC_C += setlocale.c setvbuf.c settimeofday.c sleep.c sprintf.c stat.c stdio0.c SRC_C += strcasecmp.c strcasestr.c strdup.c stricmp.c strlcpy.c strncasecmp.c -SRC_C += strnicmp.c strsep.c +SRC_C += strnicmp.c strnlen.c strsep.c SRC_C += system.c time.c tmpnam.c ttyname.c SRC_C += tzset.c ungetc.c utent.c utimes.c utsname.c SRC_C += vfprintf.c vprintf.c wait.c xitoa.c pathconf.c @@ -78,7 +78,7 @@ syscall.l: fuzix/syslib.l # (cd fuzix; make) # cat fuzix/syslib.l | tr " " "\\n" | sed -e "s/^/fuzix\//" >syscall.l -syslib.lib: syscall.l +syslib.lib: syscall.l $(OBJ_C) $(AR) a syslib.lib $(OBJ_C) ln -sf syslib.lib c.lib @@ -99,5 +99,5 @@ $(OBJ_HARD):%.o: %.c $(CC) $(CC_NOOPT) $(@:.o=.c) clean: - rm -rf *.rel *.asm *.sym *.lst *.lib *~ syscall.l libc.l syslib.l + rm -rf *.o *.lib *~ syscall.l libc.l syslib.l (cd fuzix-6502; make clean) diff --git a/Library/libs/setlocale.c b/Library/libs/setlocale.c new file mode 100644 index 00000000..7b23ce5e --- /dev/null +++ b/Library/libs/setlocale.c @@ -0,0 +1,62 @@ +#include +#include +#include + +char *setlocale(int category, const char *locale) +{ + if(strcmp(locale, "C") && strcmp(locale, "POSIX")) + return NULL; + return "C"; +} + +locale_t uselocale(locale_t newloc) +{ + return "C"; +} + +locale_t newlocale(int category_mask, const char *locale, locale_t base) +{ + if (strcmp(locale, "C") && strcmp(locale, "POSIX")) + return NULL; + return "C"; +} + +void freelocale(locale_t locale) +{ +} + +locale_t duplocale(locale_t locobj) +{ + return locobj; +} + + +static struct lconv C_lc = { + ".", + "", + "", + "", + "", + "", + "", + "", + "" + "", + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, + CHAR_MAX, +}; + +struct lconv *localeconv(void) +{ + return &C_lc; +} + diff --git a/Library/libs/strcoll.c b/Library/libs/strcoll.c new file mode 100644 index 00000000..c01eb80f --- /dev/null +++ b/Library/libs/strcoll.c @@ -0,0 +1,6 @@ +#include + +int strcoll(const char *s1, const char *s2) +{ + return strcmp(s1, s2); +} diff --git a/Library/libs/strnlen.c b/Library/libs/strnlen.c new file mode 100644 index 00000000..3c23d84e --- /dev/null +++ b/Library/libs/strnlen.c @@ -0,0 +1,9 @@ +#include + +size_t strnlen(const char *t, size_t n) +{ + size_t ct = 0; + while (*t++ && ct++ < n) + t++; + return ct; +} diff --git a/Library/libs/strxfrm.c b/Library/libs/strxfrm.c new file mode 100644 index 00000000..ff7f623a --- /dev/null +++ b/Library/libs/strxfrm.c @@ -0,0 +1,7 @@ +#include + +size_t strxfrm(char *to, const char *from, size_t n) +{ + strncpy(to, from, n); + return strnlen(to, n); +}