| author | |
| committer | |
| log | e22bf480aaaca806aa0d4ed0108ad5a719fed25d |
| tree | b2fe5e0ecfbf711cc1245cc8780270c80950e62f |
| parent | 4f16e80ceadc19c50c5be67dd9cc2c2f9aa4beb8 |
| signature |
* but does not fully implement it (missing locale/unicode tables)
* also removes their musl/mingw implementation35 files changed, 190 insertions(+), 550 deletions(-)
lib/c.zig+1| ... | ... | @@ -18,6 +18,7 @@ comptime { |
| 18 | 18 | _ = @import("c/ctype.zig"); |
| 19 | 19 | _ = @import("c/stdlib.zig"); |
| 20 | 20 | _ = @import("c/math.zig"); |
| 21 | _ = @import("c/wchar.zig"); | |
| 21 | 22 | |
| 22 | 23 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { |
| 23 | 24 | // Files specific to musl and wasi-libc. |
lib/c/wchar.zig created+179| ... | ... | @@ -0,0 +1,179 @@ |
| 1 | const std = @import("std"); | |
| 2 | const common = @import("common.zig"); | |
| 3 | const builtin = @import("builtin"); | |
| 4 | const wint_t = std.c.wint_t; | |
| 5 | const wchar_t = std.c.wchar_t; | |
| 6 | ||
| 7 | comptime { | |
| 8 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { | |
| 9 | @export(&wmemchr, .{ .name = "wmemchr", .linkage = common.linkage, .visibility = common.visibility }); | |
| 10 | @export(&wmemcmp, .{ .name = "wmemcmp", .linkage = common.linkage, .visibility = common.visibility }); | |
| 11 | @export(&wmemcpy, .{ .name = "wmemcpy", .linkage = common.linkage, .visibility = common.visibility }); | |
| 12 | @export(&wmemmove, .{ .name = "wmemmove", .linkage = common.linkage, .visibility = common.visibility }); | |
| 13 | @export(&wmemset, .{ .name = "wmemset", .linkage = common.linkage, .visibility = common.visibility }); | |
| 14 | @export(&wcslen, .{ .name = "wcslen", .linkage = common.linkage, .visibility = common.visibility }); | |
| 15 | @export(&wcsnlen, .{ .name = "wcsnlen", .linkage = common.linkage, .visibility = common.visibility }); | |
| 16 | @export(&wcscmp, .{ .name = "wcscmp", .linkage = common.linkage, .visibility = common.visibility }); | |
| 17 | @export(&wcsncmp, .{ .name = "wcsncmp", .linkage = common.linkage, .visibility = common.visibility }); | |
| 18 | @export(&wcpcpy, .{ .name = "wcpcpy", .linkage = common.linkage, .visibility = common.visibility }); | |
| 19 | @export(&wcpncpy, .{ .name = "wcpncpy", .linkage = common.linkage, .visibility = common.visibility }); | |
| 20 | @export(&wcscpy, .{ .name = "wcscpy", .linkage = common.linkage, .visibility = common.visibility }); | |
| 21 | @export(&wcsncpy, .{ .name = "wcsncpy", .linkage = common.linkage, .visibility = common.visibility }); | |
| 22 | @export(&wcscat, .{ .name = "wcscat", .linkage = common.linkage, .visibility = common.visibility }); | |
| 23 | @export(&wcsncat, .{ .name = "wcsncat", .linkage = common.linkage, .visibility = common.visibility }); | |
| 24 | @export(&wcschr, .{ .name = "wcschr", .linkage = common.linkage, .visibility = common.visibility }); | |
| 25 | @export(&wcsrchr, .{ .name = "wcsrchr", .linkage = common.linkage, .visibility = common.visibility }); | |
| 26 | @export(&wcsspn, .{ .name = "wcsspn", .linkage = common.linkage, .visibility = common.visibility }); | |
| 27 | @export(&wcscspn, .{ .name = "wcscspn", .linkage = common.linkage, .visibility = common.visibility }); | |
| 28 | @export(&wcspbrk, .{ .name = "wcspbrk", .linkage = common.linkage, .visibility = common.visibility }); | |
| 29 | @export(&wcsstr, .{ .name = "wcsstr", .linkage = common.linkage, .visibility = common.visibility }); | |
| 30 | @export(&wcswcs, .{ .name = "wcswcs", .linkage = common.linkage, .visibility = common.visibility }); | |
| 31 | } | |
| 32 | ||
| 33 | if (builtin.target.isMinGW()) { | |
| 34 | @export(&wmemchr, .{ .name = "wmemchr", .linkage = common.linkage, .visibility = common.visibility }); | |
| 35 | @export(&wmemcmp, .{ .name = "wmemcmp", .linkage = common.linkage, .visibility = common.visibility }); | |
| 36 | @export(&wmemcpy, .{ .name = "wmemcpy", .linkage = common.linkage, .visibility = common.visibility }); | |
| 37 | @export(&wmempcpy, .{ .name = "wmempcpy", .linkage = common.linkage, .visibility = common.visibility }); | |
| 38 | @export(&wmemmove, .{ .name = "wmemmove", .linkage = common.linkage, .visibility = common.visibility }); | |
| 39 | @export(&wmemset, .{ .name = "wmemset", .linkage = common.linkage, .visibility = common.visibility }); | |
| 40 | @export(&wcsnlen, .{ .name = "wcsnlen", .linkage = common.linkage, .visibility = common.visibility }); | |
| 41 | } | |
| 42 | } | |
| 43 | ||
| 44 | fn wmemchr(ptr: [*]const wchar_t, value: wchar_t, len: usize) callconv(.c) ?[*]wchar_t { | |
| 45 | return @constCast(ptr[std.mem.findScalar(wchar_t, ptr[0..len], value) orelse return null ..]); | |
| 46 | } | |
| 47 | ||
| 48 | fn wmemcmp(a: [*]const wchar_t, b: [*]const wchar_t, len: usize) callconv(.c) c_int { | |
| 49 | const idx = std.mem.findDiff(wchar_t, a[0..len], b[0..len]) orelse return 0; | |
| 50 | ||
| 51 | return switch (std.math.order(a[idx], b[idx])) { | |
| 52 | .eq => unreachable, | |
| 53 | .gt => 1, | |
| 54 | .lt => -1, | |
| 55 | }; | |
| 56 | } | |
| 57 | ||
| 58 | fn wmemcpy(noalias dest: [*]wchar_t, noalias src: [*]const wchar_t, len: usize) callconv(.c) [*]wchar_t { | |
| 59 | @memcpy(dest[0..len], src[0..len]); | |
| 60 | return dest; | |
| 61 | } | |
| 62 | ||
| 63 | fn wmempcpy(noalias dest: [*]wchar_t, noalias src: [*]const wchar_t, len: usize) callconv(.c) [*]wchar_t { | |
| 64 | @memcpy(dest[0..len], src[0..len]); | |
| 65 | return dest + len; | |
| 66 | } | |
| 67 | ||
| 68 | fn wmemmove(dest: [*]wchar_t, src: [*]const wchar_t, len: usize) callconv(.c) [*]wchar_t { | |
| 69 | @memmove(dest[0..len], src[0..len]); | |
| 70 | return dest; | |
| 71 | } | |
| 72 | ||
| 73 | fn wmemset(dest: [*]wchar_t, elem: wchar_t, len: usize) callconv(.c) [*]wchar_t { | |
| 74 | @memset(dest[0..len], elem); | |
| 75 | return dest; | |
| 76 | } | |
| 77 | ||
| 78 | fn wcslen(str: [*:0]const wchar_t) callconv(.c) usize { | |
| 79 | return wcsnlen(str, std.math.maxInt(usize)); | |
| 80 | } | |
| 81 | ||
| 82 | fn wcsnlen(str: [*:0]const wchar_t, max: usize) callconv(.c) usize { | |
| 83 | return std.mem.findScalar(wchar_t, str[0..max], 0) orelse max; | |
| 84 | } | |
| 85 | ||
| 86 | fn wcscmp(a: [*:0]const wchar_t, b: [*:0]const wchar_t) callconv(.c) c_int { | |
| 87 | return wcsncmp(a, b, std.math.maxInt(usize)); | |
| 88 | } | |
| 89 | ||
| 90 | fn wcsncmp(a: [*:0]const wchar_t, b: [*:0]const wchar_t, max: usize) callconv(.c) c_int { | |
| 91 | const a_slice = a[0..wcsnlen(a, max)]; | |
| 92 | const b_slice = b[0..wcsnlen(b, max)]; | |
| 93 | ||
| 94 | return switch (std.math.order(a_slice.len, b_slice.len)) { | |
| 95 | .eq => blk: { | |
| 96 | const idx = std.mem.findDiff(wchar_t, a_slice, b_slice) orelse break :blk 0; | |
| 97 | ||
| 98 | break :blk switch (std.math.order(a[idx], b[idx])) { | |
| 99 | .eq => unreachable, | |
| 100 | .gt => 1, | |
| 101 | .lt => -1, | |
| 102 | }; | |
| 103 | }, | |
| 104 | .gt => 1, | |
| 105 | .lt => -1, | |
| 106 | }; | |
| 107 | } | |
| 108 | ||
| 109 | fn wcpcpy(noalias dst: [*]wchar_t, noalias src: [*:0]const wchar_t) callconv(.c) [*]wchar_t { | |
| 110 | return wcpncpy(dst, src, std.math.maxInt(usize)); | |
| 111 | } | |
| 112 | ||
| 113 | fn wcpncpy(noalias dst: [*]wchar_t, noalias src: [*:0]const wchar_t, max: usize) callconv(.c) [*]wchar_t { | |
| 114 | const src_len = wcsnlen(src, max); | |
| 115 | const copying_len = @min(max, src_len); | |
| 116 | ||
| 117 | @memcpy(dst[0..copying_len], src[0..copying_len]); | |
| 118 | ||
| 119 | if (copying_len < max) dst[copying_len] = 0; | |
| 120 | return dst + copying_len; | |
| 121 | } | |
| 122 | ||
| 123 | fn wcscpy(noalias dst: [*]wchar_t, noalias src: [*:0]const wchar_t) callconv(.c) [*]wchar_t { | |
| 124 | _ = wcpcpy(dst, src); | |
| 125 | return dst; | |
| 126 | } | |
| 127 | ||
| 128 | fn wcsncpy(noalias dst: [*]wchar_t, noalias src: [*:0]const wchar_t, max: usize) callconv(.c) [*]wchar_t { | |
| 129 | _ = wcpncpy(dst, src, max); | |
| 130 | return dst; | |
| 131 | } | |
| 132 | ||
| 133 | fn wcscat(noalias dst: [*:0]wchar_t, noalias src: [*:0]const wchar_t) callconv(.c) [*:0]wchar_t { | |
| 134 | return wcsncat(dst, src, std.math.maxInt(usize)); | |
| 135 | } | |
| 136 | ||
| 137 | fn wcsncat(noalias dst: [*:0]wchar_t, noalias src: [*:0]const wchar_t, max: usize) callconv(.c) [*:0]wchar_t { | |
| 138 | const dst_len = std.mem.len(dst); | |
| 139 | const src_len = std.mem.len(src); | |
| 140 | const copying_len = @min(max, src_len); | |
| 141 | ||
| 142 | @memcpy(dst[dst_len..][0..copying_len], src[0..copying_len]); | |
| 143 | dst[dst_len + copying_len] = 0; | |
| 144 | return dst[0..(dst_len + copying_len) :0].ptr; | |
| 145 | } | |
| 146 | ||
| 147 | fn wcschr(str: [*:0]const wchar_t, value: wchar_t) callconv(.c) ?[*:0]wchar_t { | |
| 148 | const len = std.mem.len(str); | |
| 149 | ||
| 150 | if (value == 0) return @constCast(str + len); | |
| 151 | return @constCast(str[std.mem.findScalar(wchar_t, str[0..len], value) orelse return null ..]); | |
| 152 | } | |
| 153 | ||
| 154 | fn wcsrchr(str: [*:0]const wchar_t, value: wchar_t) callconv(.c) ?[*:0]wchar_t { | |
| 155 | // std.mem.len(str) + 1 to not special case '\0' | |
| 156 | return @constCast(str[std.mem.findScalarLast(wchar_t, str[0..(std.mem.len(str) + 1)], value) orelse return null ..]); | |
| 157 | } | |
| 158 | ||
| 159 | fn wcsspn(dst: [*:0]const wchar_t, values: [*:0]const wchar_t) callconv(.c) usize { | |
| 160 | const dst_slice = std.mem.span(dst); | |
| 161 | return std.mem.findNone(wchar_t, dst_slice, std.mem.span(values)) orelse dst_slice.len; | |
| 162 | } | |
| 163 | ||
| 164 | fn wcscspn(dst: [*:0]const wchar_t, values: [*:0]const wchar_t) callconv(.c) usize { | |
| 165 | const dst_slice = std.mem.span(dst); | |
| 166 | return std.mem.findAny(wchar_t, dst_slice, std.mem.span(values)) orelse dst_slice.len; | |
| 167 | } | |
| 168 | ||
| 169 | fn wcspbrk(haystack: [*:0]const wchar_t, needle: [*:0]const wchar_t) callconv(.c) ?[*:0]wchar_t { | |
| 170 | return @constCast(haystack[std.mem.findAny(wchar_t, std.mem.span(haystack), std.mem.span(needle)) orelse return null ..]); | |
| 171 | } | |
| 172 | ||
| 173 | fn wcsstr(noalias haystack: [*:0]const wchar_t, noalias needle: [*:0]const wchar_t) callconv(.c) ?[*:0]wchar_t { | |
| 174 | return @constCast(haystack[std.mem.find(wchar_t, std.mem.span(haystack), std.mem.span(needle)) orelse return null ..]); | |
| 175 | } | |
| 176 | ||
| 177 | fn wcswcs(noalias haystack: [*:0]const wchar_t, noalias needle: [*:0]const wchar_t) callconv(.c) ?[*:0]wchar_t { | |
| 178 | return wcsstr(haystack, needle); | |
| 179 | } |
lib/libc/mingw/misc/wcsnlen.c deleted-13| ... | ... | @@ -1,13 +0,0 @@ |
| 1 | #define __CRT__NO_INLINE | |
| 2 | #include <string.h> | |
| 3 | ||
| 4 | size_t __cdecl | |
| 5 | wcsnlen(const wchar_t *w, size_t ncnt) | |
| 6 | { | |
| 7 | size_t n = 0; | |
| 8 | ||
| 9 | for (; n < ncnt && *w != 0; n++, w++) | |
| 10 | ; | |
| 11 | ||
| 12 | return n; | |
| 13 | } |
lib/libc/mingw/misc/wmemchr.c deleted-35| ... | ... | @@ -1,35 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | ||
| 7 | #define __CRT__NO_INLINE | |
| 8 | #include	<wchar.h> | |
| 9 | ||
| 10 | #if 0 | |
| 11 | wchar_t *wmemchr(s, c, n) | |
| 12 | 	register const wchar_t	*s; | |
| 13 | 	register wchar_t		c; | |
| 14 | 	register size_t			n; | |
| 15 | { | |
| 16 | 	if ( s != NULL ) | |
| 17 | 		for ( ; n > 0; ++s, --n ) | |
| 18 | 			if ( *s == c ) | |
| 19 | 				return (wchar_t *)s; | |
| 20 | ||
| 21 | 	return NULL; | |
| 22 | } | |
| 23 | #endif | |
| 24 | ||
| 25 | _CONST_RETURN wchar_t *__cdecl wmemchr(const wchar_t *_S,wchar_t _C,size_t _N) | |
| 26 | { | |
| 27 | 	if (_S != NULL) | |
| 28 | 	{ | |
| 29 | 		for ( ; 0 < _N; ++_S, --_N) | |
| 30 | 			if (*_S == _C) | |
| 31 | 				return (_CONST_RETURN wchar_t *)(_S); | |
| 32 | 	} | |
| 33 | 	return NULL; | |
| 34 | } | |
| 35 |
lib/libc/mingw/misc/wmemcmp.c deleted-56| ... | ... | @@ -1,56 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | /*	This source code was extracted from the Q8 package created and placed | |
| 7 | in the PUBLIC DOMAIN by Doug Gwyn <gwyn@arl.mil> | |
| 8 | last edit:	1999/11/05	gwyn@arl.mil | |
| 9 | ||
| 10 | Implements subclause 7.24 of ISO/IEC 9899:1999 (E). | |
| 11 | ||
| 12 | 	It supports an encoding where all char codes are mapped | |
| 13 | 	to the *same* code values within a wchar_t or wint_t, | |
| 14 | 	so long as no other wchar_t codes are used by the program. | |
| 15 | ||
| 16 | */ | |
| 17 | ||
| 18 | #define __CRT__NO_INLINE | |
| 19 | #include	<wchar.h> | |
| 20 | ||
| 21 | #if 0 | |
| 22 | int | |
| 23 | wmemcmp(s1, s2, n) | |
| 24 | 	register const wchar_t	*s1; | |
| 25 | 	register const wchar_t	*s2; | |
| 26 | 	size_t				n; | |
| 27 | { | |
| 28 | 	if ( n == 0 || s1 == s2 ) | |
| 29 | 		return 0;		/* even for NULL pointers */ | |
| 30 | ||
| 31 | 	if ( (s1 != NULL) != (s2 != NULL) ) | |
| 32 | 		return s2 == NULL ? 1 : -1;	/* robust */ | |
| 33 | ||
| 34 | 	for ( ; n > 0; ++s1, ++s2, --n ) | |
| 35 | 		if ( *s1 != *s2 ) | |
| 36 | 			return *s1 - *s2; | |
| 37 | ||
| 38 | 	return 0; | |
| 39 | } | |
| 40 | #endif | |
| 41 | ||
| 42 | int __cdecl wmemcmp(const wchar_t *_S1,const wchar_t *_S2,size_t _N) | |
| 43 | { | |
| 44 | 	if (_N == 0 || _S1 == _S2) | |
| 45 | 		return 0;	/* even for NULL pointers */ | |
| 46 | ||
| 47 | 	if ((_S1 != NULL) != (_S2 != NULL)) | |
| 48 | 		return _S2 == NULL ? 1 : -1;	/* robust */ | |
| 49 | ||
| 50 | 	for ( ; 0 < _N; ++_S1, ++_S2, --_N) | |
| 51 | 		if (*_S1 != *_S2) | |
| 52 | 			return (*_S1 < *_S2 ? -1 : +1); | |
| 53 | ||
| 54 | 	return 0; | |
| 55 | } | |
| 56 |
lib/libc/mingw/misc/wmemcpy.c deleted-33| ... | ... | @@ -1,33 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | ||
| 7 | #define __CRT__NO_INLINE | |
| 8 | #include	<wchar.h> | |
| 9 | ||
| 10 | #if 0 | |
| 11 | wchar_t * | |
| 12 | wmemcpy(s1, s2, n) | |
| 13 | 	register wchar_t * __restrict__		s1; | |
| 14 | 	register const wchar_t * __restrict__	s2; | |
| 15 | 	register size_t					n; | |
| 16 | { | |
| 17 | 	wchar_t						*orig_s1 = s1; | |
| 18 | ||
| 19 | 	if ( s1 == NULL || s2 == NULL || n == 0 ) | |
| 20 | 		return orig_s1;		/* robust */ | |
| 21 | ||
| 22 | 	for ( ; n > 0; --n ) | |
| 23 | 		*s1++ = *s2++; | |
| 24 | ||
| 25 | 	return orig_s1; | |
| 26 | } | |
| 27 | #endif | |
| 28 | ||
| 29 | wchar_t *__cdecl wmemcpy(wchar_t *_S1,const wchar_t *_S2,size_t _N) | |
| 30 | { | |
| 31 | 	return (wchar_t *)memcpy(_S1,_S2,_N*sizeof(wchar_t)); | |
| 32 | } | |
| 33 |
lib/libc/mingw/misc/wmemmove.c deleted-45| ... | ... | @@ -1,45 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | ||
| 7 | #define __CRT__NO_INLINE | |
| 8 | #include	<errno.h> | |
| 9 | #include	<stdio.h> | |
| 10 | #include	<stdlib.h> | |
| 11 | #include	<wchar.h> | |
| 12 | ||
| 13 | #if 0 | |
| 14 | wchar_t * | |
| 15 | wmemmove(s1, s2, n) | |
| 16 | 	register wchar_t		*s1; | |
| 17 | 	register const wchar_t	*s2; | |
| 18 | 	register size_t			n; | |
| 19 | { | |
| 20 | 	wchar_t				*orig_s1 = s1; | |
| 21 | ||
| 22 | 	if ( s1 == NULL || s2 == NULL || n == 0 ) | |
| 23 | 		return orig_s1;		/* robust */ | |
| 24 | ||
| 25 | 	/* XXX -- The following test works only within a flat address space! */ | |
| 26 | 	if ( s2 >= s1 ) | |
| 27 | 		for ( ; n > 0; --n ) | |
| 28 | 			*s1++ = *s2++; | |
| 29 | 	else	{ | |
| 30 | 		s1 += n; | |
| 31 | 		s2 += n; | |
| 32 | ||
| 33 | 		for ( ; n > 0; --n ) | |
| 34 | 			*--s1 = *--s2; | |
| 35 | 		} | |
| 36 | ||
| 37 | 	return orig_s1; | |
| 38 | } | |
| 39 | #endif | |
| 40 | ||
| 41 | wchar_t *__cdecl wmemmove(wchar_t *_S1,const wchar_t *_S2,size_t _N) | |
| 42 | { | |
| 43 | 	return (wchar_t *)memmove(_S1,_S2,_N*sizeof(wchar_t)); | |
| 44 | } | |
| 45 |
lib/libc/mingw/misc/wmempcpy.c deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | #define __CRT__NO_INLINE | |
| 2 | #include <wchar.h> | |
| 3 | ||
| 4 | wchar_t * __cdecl | |
| 5 | wmempcpy (wchar_t *d, const wchar_t *s, size_t len) | |
| 6 | { | |
| 7 | wchar_t *r = d + len; | |
| 8 | if (len != 0) | |
| 9 | memcpy (d, s, len * sizeof (wchar_t)); | |
| 10 | return r; | |
| 11 | } | |
| 12 |
lib/libc/mingw/misc/wmemset.c deleted-34| ... | ... | @@ -1,34 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | ||
| 7 | #define __CRT__NO_INLINE | |
| 8 | #include	<wchar.h> | |
| 9 | ||
| 10 | #if 0 | |
| 11 | wchar_t * | |
| 12 | wmemset(s, c, n) | |
| 13 | 	register wchar_t	*s; | |
| 14 | 	register wchar_t	c; | |
| 15 | 	register size_t		n; | |
| 16 | { | |
| 17 | 	wchar_t			*orig_s = s; | |
| 18 | ||
| 19 | 	if ( s != NULL ) | |
| 20 | 		for ( ; n > 0; --n ) | |
| 21 | 			*s++ = c; | |
| 22 | ||
| 23 | 	return orig_s; | |
| 24 | } | |
| 25 | #endif | |
| 26 | ||
| 27 | wchar_t *__cdecl wmemset(wchar_t *_S,wchar_t _C,size_t _N) | |
| 28 | { | |
| 29 | 	wchar_t *_Su = _S; | |
| 30 | 	for ( ; 0 < _N; ++_Su, --_N) | |
| 31 | 		 *_Su = _C; | |
| 32 | 	return (_S); | |
| 33 | } | |
| 34 |
lib/libc/musl/src/string/wcpcpy.c deleted-6| ... | ... | @@ -1,6 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | wchar_t *wcpcpy(wchar_t *restrict d, const wchar_t *restrict s) | |
| 4 | { | |
| 5 | 	return wcscpy(d, s) + wcslen(s); | |
| 6 | } |
lib/libc/musl/src/string/wcpncpy.c deleted-6| ... | ... | @@ -1,6 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | wchar_t *wcpncpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n) | |
| 4 | { | |
| 5 | 	return wcsncpy(d, s, n) + wcsnlen(s, n); | |
| 6 | } |
lib/libc/musl/src/string/wcscat.c deleted-7| ... | ... | @@ -1,7 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | wchar_t *wcscat(wchar_t *restrict dest, const wchar_t *restrict src) | |
| 4 | { | |
| 5 | 	wcscpy(dest + wcslen(dest), src); | |
| 6 | 	return dest; | |
| 7 | } |
lib/libc/musl/src/string/wcschr.c deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | wchar_t *wcschr(const wchar_t *s, wchar_t c) | |
| 4 | { | |
| 5 | 	if (!c) return (wchar_t *)s + wcslen(s); | |
| 6 | 	for (; *s && *s != c; s++); | |
| 7 | 	return *s ? (wchar_t *)s : 0; | |
| 8 | } |
lib/libc/musl/src/string/wcscmp.c deleted-7| ... | ... | @@ -1,7 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | int wcscmp(const wchar_t *l, const wchar_t *r) | |
| 4 | { | |
| 5 | 	for (; *l==*r && *l && *r; l++, r++); | |
| 6 | 	return *l < *r ? -1 : *l > *r; | |
| 7 | } |
lib/libc/musl/src/string/wcscpy.c deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | wchar_t *wcscpy(wchar_t *restrict d, const wchar_t *restrict s) | |
| 4 | { | |
| 5 | 	wchar_t *a = d; | |
| 6 | 	while ((*d++ = *s++)); | |
| 7 | 	return a; | |
| 8 | } |
lib/libc/musl/src/string/wcscspn.c deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | size_t wcscspn(const wchar_t *s, const wchar_t *c) | |
| 4 | { | |
| 5 | 	const wchar_t *a; | |
| 6 | 	if (!c[0]) return wcslen(s); | |
| 7 | 	if (!c[1]) return (s=wcschr(a=s, *c)) ? s-a : wcslen(a); | |
| 8 | 	for (a=s; *s && !wcschr(c, *s); s++); | |
| 9 | 	return s-a; | |
| 10 | } |
lib/libc/musl/src/string/wcslen.c deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | size_t wcslen(const wchar_t *s) | |
| 4 | { | |
| 5 | 	const wchar_t *a; | |
| 6 | 	for (a=s; *s; s++); | |
| 7 | 	return s-a; | |
| 8 | } |
lib/libc/musl/src/string/wcsncat.c deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | wchar_t *wcsncat(wchar_t *restrict d, const wchar_t *restrict s, size_t n) | |
| 4 | { | |
| 5 | 	wchar_t *a = d; | |
| 6 | 	d += wcslen(d); | |
| 7 | 	while (n && *s) n--, *d++ = *s++; | |
| 8 | 	*d++ = 0; | |
| 9 | 	return a; | |
| 10 | } |
lib/libc/musl/src/string/wcsncmp.c deleted-7| ... | ... | @@ -1,7 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | int wcsncmp(const wchar_t *l, const wchar_t *r, size_t n) | |
| 4 | { | |
| 5 | 	for (; n && *l==*r && *l && *r; n--, l++, r++); | |
| 6 | 	return n ? (*l < *r ? -1 : *l > *r) : 0; | |
| 7 | } |
lib/libc/musl/src/string/wcsncpy.c deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | wchar_t *wcsncpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n) | |
| 4 | { | |
| 5 | 	wchar_t *a = d; | |
| 6 | 	while (n && *s) n--, *d++ = *s++; | |
| 7 | 	wmemset(d, 0, n); | |
| 8 | 	return a; | |
| 9 | } |
lib/libc/musl/src/string/wcsnlen.c deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | size_t wcsnlen(const wchar_t *s, size_t n) | |
| 4 | { | |
| 5 | 	const wchar_t *z = wmemchr(s, 0, n); | |
| 6 | 	if (z) n = z-s; | |
| 7 | 	return n; | |
| 8 | } |
lib/libc/musl/src/string/wcspbrk.c deleted-7| ... | ... | @@ -1,7 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | wchar_t *wcspbrk(const wchar_t *s, const wchar_t *b) | |
| 4 | { | |
| 5 | 	s += wcscspn(s, b); | |
| 6 | 	return *s ? (wchar_t *)s : NULL; | |
| 7 | } |
lib/libc/musl/src/string/wcsrchr.c deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | wchar_t *wcsrchr(const wchar_t *s, wchar_t c) | |
| 4 | { | |
| 5 | 	const wchar_t *p; | |
| 6 | 	for (p=s+wcslen(s); p>=s && *p!=c; p--); | |
| 7 | 	return p>=s ? (wchar_t *)p : 0; | |
| 8 | } |
lib/libc/musl/src/string/wcsspn.c deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | size_t wcsspn(const wchar_t *s, const wchar_t *c) | |
| 4 | { | |
| 5 | 	const wchar_t *a; | |
| 6 | 	for (a=s; *s && wcschr(c, *s); s++); | |
| 7 | 	return s-a; | |
| 8 | } |
lib/libc/musl/src/string/wcsstr.c deleted-105| ... | ... | @@ -1,105 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | #define MAX(a,b) ((a)>(b)?(a):(b)) | |
| 4 | #define MIN(a,b) ((a)<(b)?(a):(b)) | |
| 5 | ||
| 6 | static wchar_t *twoway_wcsstr(const wchar_t *h, const wchar_t *n) | |
| 7 | { | |
| 8 | 	const wchar_t *z; | |
| 9 | 	size_t l, ip, jp, k, p, ms, p0, mem, mem0; | |
| 10 | ||
| 11 | 	/* Computing length of needle */ | |
| 12 | 	for (l=0; n[l] && h[l]; l++); | |
| 13 | 	if (n[l]) return 0; /* hit the end of h */ | |
| 14 | ||
| 15 | 	/* Compute maximal suffix */ | |
| 16 | 	ip = -1; jp = 0; k = p = 1; | |
| 17 | 	while (jp+k<l) { | |
| 18 | 		if (n[ip+k] == n[jp+k]) { | |
| 19 | 			if (k == p) { | |
| 20 | 				jp += p; | |
| 21 | 				k = 1; | |
| 22 | 			} else k++; | |
| 23 | 		} else if (n[ip+k] > n[jp+k]) { | |
| 24 | 			jp += k; | |
| 25 | 			k = 1; | |
| 26 | 			p = jp - ip; | |
| 27 | 		} else { | |
| 28 | 			ip = jp++; | |
| 29 | 			k = p = 1; | |
| 30 | 		} | |
| 31 | 	} | |
| 32 | 	ms = ip; | |
| 33 | 	p0 = p; | |
| 34 | ||
| 35 | 	/* And with the opposite comparison */ | |
| 36 | 	ip = -1; jp = 0; k = p = 1; | |
| 37 | 	while (jp+k<l) { | |
| 38 | 		if (n[ip+k] == n[jp+k]) { | |
| 39 | 			if (k == p) { | |
| 40 | 				jp += p; | |
| 41 | 				k = 1; | |
| 42 | 			} else k++; | |
| 43 | 		} else if (n[ip+k] < n[jp+k]) { | |
| 44 | 			jp += k; | |
| 45 | 			k = 1; | |
| 46 | 			p = jp - ip; | |
| 47 | 		} else { | |
| 48 | 			ip = jp++; | |
| 49 | 			k = p = 1; | |
| 50 | 		} | |
| 51 | 	} | |
| 52 | 	if (ip+1 > ms+1) ms = ip; | |
| 53 | 	else p = p0; | |
| 54 | ||
| 55 | 	/* Periodic needle? */ | |
| 56 | 	if (wmemcmp(n, n+p, ms+1)) { | |
| 57 | 		mem0 = 0; | |
| 58 | 		p = MAX(ms, l-ms-1) + 1; | |
| 59 | 	} else mem0 = l-p; | |
| 60 | 	mem = 0; | |
| 61 | ||
| 62 | 	/* Initialize incremental end-of-haystack pointer */ | |
| 63 | 	z = h; | |
| 64 | ||
| 65 | 	/* Search loop */ | |
| 66 | 	for (;;) { | |
| 67 | 		/* Update incremental end-of-haystack pointer */ | |
| 68 | 		if (z-h < l) { | |
| 69 | 			/* Fast estimate for MIN(l,63) */ | |
| 70 | 			size_t grow = l | 63; | |
| 71 | 			const wchar_t *z2 = wmemchr(z, 0, grow); | |
| 72 | 			if (z2) { | |
| 73 | 				z = z2; | |
| 74 | 				if (z-h < l) return 0; | |
| 75 | 			} else z += grow; | |
| 76 | 		} | |
| 77 | ||
| 78 | 		/* Compare right half */ | |
| 79 | 		for (k=MAX(ms+1,mem); n[k] && n[k] == h[k]; k++); | |
| 80 | 		if (n[k]) { | |
| 81 | 			h += k-ms; | |
| 82 | 			mem = 0; | |
| 83 | 			continue; | |
| 84 | 		} | |
| 85 | 		/* Compare left half */ | |
| 86 | 		for (k=ms+1; k>mem && n[k-1] == h[k-1]; k--); | |
| 87 | 		if (k <= mem) return (wchar_t *)h; | |
| 88 | 		h += p; | |
| 89 | 		mem = mem0; | |
| 90 | 	} | |
| 91 | } | |
| 92 | ||
| 93 | wchar_t *wcsstr(const wchar_t *restrict h, const wchar_t *restrict n) | |
| 94 | { | |
| 95 | 	/* Return immediately on empty needle or haystack */ | |
| 96 | 	if (!n[0]) return (wchar_t *)h; | |
| 97 | 	if (!h[0]) return 0; | |
| 98 | ||
| 99 | 	/* Use faster algorithms for short needles */ | |
| 100 | 	h = wcschr(h, *n); | |
| 101 | 	if (!h || !n[1]) return (wchar_t *)h; | |
| 102 | 	if (!h[1]) return 0; | |
| 103 | ||
| 104 | 	return twoway_wcsstr(h, n); | |
| 105 | } |
lib/libc/musl/src/string/wcswcs.c deleted-6| ... | ... | @@ -1,6 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | wchar_t *wcswcs(const wchar_t *haystack, const wchar_t *needle) | |
| 4 | { | |
| 5 | 	return wcsstr(haystack, needle); | |
| 6 | } |
lib/libc/musl/src/string/wmemchr.c deleted-7| ... | ... | @@ -1,7 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n) | |
| 4 | { | |
| 5 | 	for (; n && *s != c; n--, s++); | |
| 6 | 	return n ? (wchar_t *)s : 0; | |
| 7 | } |
lib/libc/musl/src/string/wmemcmp.c deleted-7| ... | ... | @@ -1,7 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | int wmemcmp(const wchar_t *l, const wchar_t *r, size_t n) | |
| 4 | { | |
| 5 | 	for (; n && *l==*r; n--, l++, r++); | |
| 6 | 	return n ? (*l < *r ? -1 : *l > *r) : 0; | |
| 7 | } |
lib/libc/musl/src/string/wmemcpy.c deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | wchar_t *wmemcpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n) | |
| 4 | { | |
| 5 | 	wchar_t *a = d; | |
| 6 | 	while (n--) *d++ = *s++; | |
| 7 | 	return a; | |
| 8 | } |
lib/libc/musl/src/string/wmemmove.c deleted-13| ... | ... | @@ -1,13 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | #include <stdint.h> | |
| 3 | ||
| 4 | wchar_t *wmemmove(wchar_t *d, const wchar_t *s, size_t n) | |
| 5 | { | |
| 6 | 	wchar_t *d0 = d; | |
| 7 | 	if (d == s) return d; | |
| 8 | 	if ((uintptr_t)d-(uintptr_t)s < n * sizeof *d) | |
| 9 | 		while (n--) d[n] = s[n]; | |
| 10 | 	else | |
| 11 | 		while (n--) *d++ = *s++; | |
| 12 | 	return d0; | |
| 13 | } |
lib/libc/musl/src/string/wmemset.c deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | #include <wchar.h> | |
| 2 | ||
| 3 | wchar_t *wmemset(wchar_t *d, wchar_t c, size_t n) | |
| 4 | { | |
| 5 | 	wchar_t *ret = d; | |
| 6 | 	while (n--) *d++ = c; | |
| 7 | 	return ret; | |
| 8 | } |
lib/std/c.zig+10| ... | ... | @@ -11067,6 +11067,16 @@ pub const imaxdiv_t = extern struct { |
| 11067 | 11067 | pub const intmax_t = i64; |
| 11068 | 11068 | pub const uintmax_t = u64; |
| 11069 | 11069 | |
| 11070 | pub const wint_t = switch (builtin.target.os.tag) { | |
| 11071 | .windows => u16, | |
| 11072 | else => i32, | |
| 11073 | }; | |
| 11074 | ||
| 11075 | pub const wchar_t = switch (builtin.target.os.tag) { | |
| 11076 | .windows => u16, | |
| 11077 | else => if (builtin.target.cpu.arch.isArm() or builtin.target.cpu.arch.isAARCH64()) u32 else i32, | |
| 11078 | }; | |
| 11079 | ||
| 11070 | 11080 | pub extern "c" fn pthread_getthreadid_np() c_int; |
| 11071 | 11081 | pub extern "c" fn pthread_set_name_np(thread: pthread_t, name: [*:0]const u8) void; |
| 11072 | 11082 | pub extern "c" fn pthread_get_name_np(thread: pthread_t, name: [*:0]u8, len: usize) void; |
src/libs/mingw.zig-7| ... | ... | @@ -681,7 +681,6 @@ const mingw32_generic_src = [_][]const u8{ |
| 681 | 681 | "misc" ++ path.sep_str ++ "tfind.c", |
| 682 | 682 | "misc" ++ path.sep_str ++ "tsearch.c", |
| 683 | 683 | "misc" ++ path.sep_str ++ "twalk.c", |
| 684 | "misc" ++ path.sep_str ++ "wcsnlen.c", | |
| 685 | 684 | "misc" ++ path.sep_str ++ "wcstof.c", |
| 686 | 685 | "misc" ++ path.sep_str ++ "wcstoimax.c", |
| 687 | 686 | "misc" ++ path.sep_str ++ "wcstold.c", |
| ... | ... | @@ -691,12 +690,6 @@ const mingw32_generic_src = [_][]const u8{ |
| 691 | 690 | "misc" ++ path.sep_str ++ "winbs_uint64.c", |
| 692 | 691 | "misc" ++ path.sep_str ++ "winbs_ulong.c", |
| 693 | 692 | "misc" ++ path.sep_str ++ "winbs_ushort.c", |
| 694 | "misc" ++ path.sep_str ++ "wmemchr.c", | |
| 695 | "misc" ++ path.sep_str ++ "wmemcmp.c", | |
| 696 | "misc" ++ path.sep_str ++ "wmemcpy.c", | |
| 697 | "misc" ++ path.sep_str ++ "wmemmove.c", | |
| 698 | "misc" ++ path.sep_str ++ "wmempcpy.c", | |
| 699 | "misc" ++ path.sep_str ++ "wmemset.c", | |
| 700 | 693 | "stdio" ++ path.sep_str ++ "_Exit.c", |
| 701 | 694 | "stdio" ++ path.sep_str ++ "_findfirst64i32.c", |
| 702 | 695 | "stdio" ++ path.sep_str ++ "_findnext64i32.c", |
src/libs/musl.zig-22| ... | ... | @@ -1651,34 +1651,12 @@ const src_files = [_][]const u8{ |
| 1651 | 1651 | "musl/src/string/strtok_r.c", |
| 1652 | 1652 | "musl/src/string/strverscmp.c", |
| 1653 | 1653 | "musl/src/string/swab.c", |
| 1654 | "musl/src/string/wcpcpy.c", | |
| 1655 | "musl/src/string/wcpncpy.c", | |
| 1656 | 1654 | "musl/src/string/wcscasecmp.c", |
| 1657 | 1655 | "musl/src/string/wcscasecmp_l.c", |
| 1658 | "musl/src/string/wcscat.c", | |
| 1659 | "musl/src/string/wcschr.c", | |
| 1660 | "musl/src/string/wcscmp.c", | |
| 1661 | "musl/src/string/wcscpy.c", | |
| 1662 | "musl/src/string/wcscspn.c", | |
| 1663 | 1656 | "musl/src/string/wcsdup.c", |
| 1664 | "musl/src/string/wcslen.c", | |
| 1665 | 1657 | "musl/src/string/wcsncasecmp.c", |
| 1666 | 1658 | "musl/src/string/wcsncasecmp_l.c", |
| 1667 | "musl/src/string/wcsncat.c", | |
| 1668 | "musl/src/string/wcsncmp.c", | |
| 1669 | "musl/src/string/wcsncpy.c", | |
| 1670 | "musl/src/string/wcsnlen.c", | |
| 1671 | "musl/src/string/wcspbrk.c", | |
| 1672 | "musl/src/string/wcsrchr.c", | |
| 1673 | "musl/src/string/wcsspn.c", | |
| 1674 | "musl/src/string/wcsstr.c", | |
| 1675 | 1659 | "musl/src/string/wcstok.c", |
| 1676 | "musl/src/string/wcswcs.c", | |
| 1677 | "musl/src/string/wmemchr.c", | |
| 1678 | "musl/src/string/wmemcmp.c", | |
| 1679 | "musl/src/string/wmemcpy.c", | |
| 1680 | "musl/src/string/wmemmove.c", | |
| 1681 | "musl/src/string/wmemset.c", | |
| 1682 | 1660 | "musl/src/temp/mkdtemp.c", |
| 1683 | 1661 | "musl/src/temp/mkostemp.c", |
| 1684 | 1662 | "musl/src/temp/mkostemps.c", |
src/libs/wasi_libc.zig-22| ... | ... | @@ -999,34 +999,12 @@ const libc_top_half_src_files = [_][]const u8{ |
| 999 | 999 | "musl/src/string/strtok_r.c", |
| 1000 | 1000 | "musl/src/string/strverscmp.c", |
| 1001 | 1001 | "musl/src/string/swab.c", |
| 1002 | "musl/src/string/wcpcpy.c", | |
| 1003 | "musl/src/string/wcpncpy.c", | |
| 1004 | 1002 | "musl/src/string/wcscasecmp.c", |
| 1005 | 1003 | "musl/src/string/wcscasecmp_l.c", |
| 1006 | "musl/src/string/wcscat.c", | |
| 1007 | "musl/src/string/wcschr.c", | |
| 1008 | "musl/src/string/wcscmp.c", | |
| 1009 | "musl/src/string/wcscpy.c", | |
| 1010 | "musl/src/string/wcscspn.c", | |
| 1011 | 1004 | "musl/src/string/wcsdup.c", |
| 1012 | "musl/src/string/wcslen.c", | |
| 1013 | 1005 | "musl/src/string/wcsncasecmp.c", |
| 1014 | 1006 | "musl/src/string/wcsncasecmp_l.c", |
| 1015 | "musl/src/string/wcsncat.c", | |
| 1016 | "musl/src/string/wcsncmp.c", | |
| 1017 | "musl/src/string/wcsncpy.c", | |
| 1018 | "musl/src/string/wcsnlen.c", | |
| 1019 | "musl/src/string/wcspbrk.c", | |
| 1020 | "musl/src/string/wcsrchr.c", | |
| 1021 | "musl/src/string/wcsspn.c", | |
| 1022 | "musl/src/string/wcsstr.c", | |
| 1023 | 1007 | "musl/src/string/wcstok.c", |
| 1024 | "musl/src/string/wcswcs.c", | |
| 1025 | "musl/src/string/wmemchr.c", | |
| 1026 | "musl/src/string/wmemcmp.c", | |
| 1027 | "musl/src/string/wmemcpy.c", | |
| 1028 | "musl/src/string/wmemmove.c", | |
| 1029 | "musl/src/string/wmemset.c", | |
| 1030 | 1008 | "musl/src/thread/default_attr.c", |
| 1031 | 1009 | "musl/src/thread/pthread_attr_destroy.c", |
| 1032 | 1010 | "musl/src/thread/pthread_attr_init.c", |