-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add locale stubs so we can compile libcxx
- Loading branch information
1 parent
3d5667b
commit fdd5137
Showing
7 changed files
with
702 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright (C) 2024 John Törnblom | ||
# | ||
# This file is free software; you can redistribute it and/or modify it | ||
# under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, but | ||
# WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; see the file COPYING. If not see | ||
# <http://www.gnu.org/licenses/>. | ||
|
||
DESTDIR ?= /opt/ps5-payload-sdk | ||
|
||
CCS := clang-18 clang-17 clang-16 clang-15 clang | ||
CCS := $(foreach CC,$(CCS),$(if $(shell command -v $(CC) 2> /dev/null),$(CC))) | ||
CC := $(firstword $(CCS)) | ||
ifndef CC | ||
$(error No suitable compiler found) | ||
endif | ||
|
||
ARS := llvm-ar-18 llvm-ar-17 llvm-ar-16 llvm-ar-15 llvm-ar | ||
ARS := $(foreach LD,$(ARS),$(if $(shell command -v $(AR) 2> /dev/null),$(AR))) | ||
AR := $(firstword $(ARS)) | ||
ifndef AR | ||
$(error No suitable archiver found) | ||
endif | ||
|
||
CFLAGS := -target x86_64-sie-ps5 -fPIC -fno-plt -fno-stack-protector | ||
CFLAGS += -nobuiltininc -isystem ../include/freebsd | ||
|
||
SRCS := $(wildcard *.c) | ||
OBJS := $(SRCS:.c=.o) | ||
|
||
ARCHIVE := libc_locale.a | ||
|
||
all: $(ARCHIVE) | ||
|
||
$(ARCHIVE): $(OBJS) | ||
ar -rsc $@ $^ | ||
|
||
clean: | ||
rm -f *.a *.o | ||
|
||
install: $(ARCHIVE) | ||
install -d $(DESTDIR)/target/lib | ||
install $^ $(DESTDIR)/target/lib | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
Copyright © 2005-2020 Rich Felker, et al. | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#include <wchar.h> | ||
|
||
size_t mbsnrtowcs(wchar_t *restrict wcs, const char **restrict src, size_t n, size_t wn, mbstate_t *restrict st) | ||
{ | ||
size_t l, cnt=0, n2; | ||
wchar_t *ws, wbuf[256]; | ||
const char *s = *src; | ||
const char *tmp_s; | ||
|
||
if (!wcs) ws = wbuf, wn = sizeof wbuf / sizeof *wbuf; | ||
else ws = wcs; | ||
|
||
/* making sure output buffer size is at most n/4 will ensure | ||
* that mbsrtowcs never reads more than n input bytes. thus | ||
* we can use mbsrtowcs as long as it's practical.. */ | ||
|
||
while ( s && wn && ( (n2=n/4)>=wn || n2>32 ) ) { | ||
if (n2>=wn) n2=wn; | ||
tmp_s = s; | ||
l = mbsrtowcs(ws, &s, n2, st); | ||
if (!(l+1)) { | ||
cnt = l; | ||
wn = 0; | ||
break; | ||
} | ||
if (ws != wbuf) { | ||
ws += l; | ||
wn -= l; | ||
} | ||
n = s ? n - (s - tmp_s) : 0; | ||
cnt += l; | ||
} | ||
if (s) while (wn && n) { | ||
l = mbrtowc(ws, s, n, st); | ||
if (l+2<=2) { | ||
if (!(l+1)) { | ||
cnt = l; | ||
break; | ||
} | ||
if (!l) { | ||
s = 0; | ||
break; | ||
} | ||
/* have to roll back partial character */ | ||
*(unsigned *)st = 0; | ||
break; | ||
} | ||
s += l; n -= l; | ||
/* safe - this loop runs fewer than sizeof(wbuf)/8 times */ | ||
ws++; wn--; | ||
cnt++; | ||
} | ||
if (wcs) *src = s; | ||
return cnt; | ||
} |
Oops, something went wrong.