libc: Add get/set for mbstate_t - scc - simple c99 compiler
HTML git clone git://git.simple-cc.org/scc
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
DIR commit 7033385eda09474ab9a8e21ae811d916e3856ce6
DIR parent b454c47b530863e732c6100728d35e8e663d3a5d
HTML Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Mon, 10 Mar 2025 13:57:08 +0100
libc: Add get/set for mbstate_t
The definition of mbstate_t depends of the system, and for that reason
we cannot access directly the content of the data type. To solve this
problem different system functions were added making the generic code
portable between the different implementations.
Diffstat:
M src/libc/arch/bsd/Makefile | 4 +++-
A src/libc/arch/bsd/_mbsget.c | 9 +++++++++
A src/libc/arch/bsd/_mbsset.c | 9 +++++++++
M src/libc/arch/darwin/Makefile | 2 ++
A src/libc/arch/darwin/_mbsget.c | 9 +++++++++
A src/libc/arch/darwin/_mbsset.c | 10 ++++++++++
M src/libc/arch/linux/Makefile | 2 ++
A src/libc/arch/linux/_mbsget.c | 9 +++++++++
A src/libc/arch/linux/_mbsset.c | 9 +++++++++
M src/libc/libc.h | 2 ++
M src/libc/objs/amd64-linux.mk | 2 ++
M src/libc/objs/amd64-netbsd.mk | 2 ++
M src/libc/objs/amd64-openbsd.mk | 2 ++
M src/libc/wchar/mbsinit.c | 4 +++-
14 files changed, 73 insertions(+), 2 deletions(-)
---
DIR diff --git a/src/libc/arch/bsd/Makefile b/src/libc/arch/bsd/Makefile
@@ -4,6 +4,8 @@ include $(PROJECTDIR)/scripts/rules.mk
include ../../rules.mk
OBJS=\
- _waitpid.$O\
+ _mbsget.$O\
+ _mbsset.$O\
+ _waitpid.$O\
all: $(OBJS)
DIR diff --git a/src/libc/arch/bsd/_mbsget.c b/src/libc/arch/bsd/_mbsget.c
@@ -0,0 +1,9 @@
+#include <wchar.h>
+
+#include "../../libc.h"
+
+int
+_mbsget(mbstate_t *ps)
+{
+ return ps->__mbstate8[0];
+}
DIR diff --git a/src/libc/arch/bsd/_mbsset.c b/src/libc/arch/bsd/_mbsset.c
@@ -0,0 +1,9 @@
+#include <wchar.h>
+
+#include "../../libc.h"
+
+int
+_mbsset(mbstate_t *ps, int ch)
+{
+ return ps->__mbstate8[0] = ch;
+}
DIR diff --git a/src/libc/arch/darwin/Makefile b/src/libc/arch/darwin/Makefile
@@ -5,5 +5,7 @@ include ../../rules.mk
OBJS=\
_getheap.$O\
+ _mbsget.$O\
+ _mbsset.$O\
all: $(OBJS)
DIR diff --git a/src/libc/arch/darwin/_mbsget.c b/src/libc/arch/darwin/_mbsget.c
@@ -0,0 +1,9 @@
+#include <wchar.h>
+
+#include "../../libc.h"
+
+int
+_mbsget(mbstate_t *ps)
+{
+ return ps->state[0];
+}
DIR diff --git a/src/libc/arch/darwin/_mbsset.c b/src/libc/arch/darwin/_mbsset.c
@@ -0,0 +1,10 @@
+#include <wchar.h>
+
+#include "../../libc.h"
+
+int
+_mbsset(mbstate_t *ps, int ch)
+{
+ ps-count = 1;
+ return ps->state[0] = ch;
+}
DIR diff --git a/src/libc/arch/linux/Makefile b/src/libc/arch/linux/Makefile
@@ -6,6 +6,8 @@ include ../../rules.mk
OBJS=\
_brk.$O\
_getheap.$O\
+ _mbsget.$O\
+ _mbsset.$O\
_sigaction.$O\
_waitpid.$O\
DIR diff --git a/src/libc/arch/linux/_mbsget.c b/src/libc/arch/linux/_mbsget.c
@@ -0,0 +1,9 @@
+#include <wchar.h>
+
+#include "../../libc.h"
+
+int
+_mbsget(mbstate_t *ps)
+{
+ return ps->__opaque1;
+}
DIR diff --git a/src/libc/arch/linux/_mbsset.c b/src/libc/arch/linux/_mbsset.c
@@ -0,0 +1,9 @@
+#include <wchar.h>
+
+#include "../../libc.h"
+
+int
+_mbsset(mbstate_t *ps, int ch)
+{
+ return ps->__opaque1 = ch;
+}
DIR diff --git a/src/libc/libc.h b/src/libc/libc.h
@@ -61,6 +61,8 @@ extern void (*_atexithdl)(void);
#ifdef _WCHAR_H
extern int _validutf8(wchar_t, int *);
+extern int _mbsset(mbstate_t *, int);
+extern int _mbsget(mbstate_t *);
#ifdef _STDIO_H
extern wint_t _fputwc(wchar_t, FILE *, int *);
#endif
DIR diff --git a/src/libc/objs/amd64-linux.mk b/src/libc/objs/amd64-linux.mk
@@ -36,6 +36,8 @@ OBJS =\
arch/amd64/strcpy.$O\
arch/linux/_brk.$O\
arch/linux/_getheap.$O\
+ arch/linux/_mbsget.$O\
+ arch/linux/_mbsset.$O\
arch/linux/_sigaction.$O\
arch/linux/_waitpid.$O\
arch/posix/_open.$O\
DIR diff --git a/src/libc/objs/amd64-netbsd.mk b/src/libc/objs/amd64-netbsd.mk
@@ -28,6 +28,8 @@ OBJS =\
arch/amd64/strcmp.$O\
arch/amd64/strcpy.$O\
arch/bsd/_waitpid.$O\
+ arch/bsd/_mbsget.$O\
+ arch/bsd/_mbsset.$O\
arch/netbsd/_sigaction.$O\
arch/posix/_getheap.$O\
arch/posix/_open.$O\
DIR diff --git a/src/libc/objs/amd64-openbsd.mk b/src/libc/objs/amd64-openbsd.mk
@@ -33,6 +33,8 @@ OBJS =\
arch/amd64/strcmp.$O\
arch/amd64/strcpy.$O\
arch/bsd/_waitpid.$O\
+ arch/bsd/_mbsget.$O\
+ arch/bsd/_mbsset.$O\
arch/posix/_getheap.$O\
arch/posix/_open.$O\
arch/posix/_systime.$O\
DIR diff --git a/src/libc/wchar/mbsinit.c b/src/libc/wchar/mbsinit.c
@@ -1,5 +1,7 @@
#include <wchar.h>
+#include "../libc.h"
+
#undef mbsinit
int
@@ -7,5 +9,5 @@ mbsinit(const mbstate_t *ps)
{
if (!ps)
return 1;
- return *ps == 0;
+ return _mbsget(ps) == 0;
}