libc: various minimalist locale stuff (C locale wrappers basically)
authorAlan Cox <alan@linux.intel.com>
Fri, 16 Jan 2015 00:32:04 +0000 (00:32 +0000)
committerAlan Cox <alan@linux.intel.com>
Fri, 16 Jan 2015 00:32:04 +0000 (00:32 +0000)
Library/libs/Makefile
Library/libs/Makefile.6502
Library/libs/setlocale.c [new file with mode: 0644]
Library/libs/strcoll.c [new file with mode: 0644]
Library/libs/strnlen.c [new file with mode: 0644]
Library/libs/strxfrm.c [new file with mode: 0644]

index 9f9e5eb..e59954f 100644 (file)
@@ -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
index 84434ec..e269020 100644 (file)
@@ -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 (file)
index 0000000..7b23ce5
--- /dev/null
@@ -0,0 +1,62 @@
+#include <string.h>
+#include <locale.h>
+#include <limits.h>
+
+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 (file)
index 0000000..c01eb80
--- /dev/null
@@ -0,0 +1,6 @@
+#include <string.h>
+
+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 (file)
index 0000000..3c23d84
--- /dev/null
@@ -0,0 +1,9 @@
+#include <string.h>
+
+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 (file)
index 0000000..ff7f623
--- /dev/null
@@ -0,0 +1,7 @@
+#include <string.h>
+
+size_t strxfrm(char *to, const char *from, size_t n)
+{
+  strncpy(to, from, n);
+  return strnlen(to, n);
+}