mirror of
https://github.com/ivoszbg/uniLoader.git
synced 2026-08-15 05:18:32 +00:00
EXPERIMENTAL: Partially implement NewLib
Signed-off-by: Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
This commit is contained in:
1 parent
d85632eb76
commit
a1be36ae02
2546 files changed
+464057
-5
No files matched your search
@@ -0,0 +1,149 @@
|
||||
libc_a_SOURCES += \
|
||||
%D%/bcopy.c \
|
||||
%D%/bzero.c \
|
||||
%D%/explicit_bzero.c \
|
||||
%D%/ffsl.c \
|
||||
%D%/ffsll.c \
|
||||
%D%/fls.c \
|
||||
%D%/flsl.c \
|
||||
%D%/flsll.c \
|
||||
%D%/index.c \
|
||||
%D%/memchr.c \
|
||||
%D%/memcmp.c \
|
||||
%D%/memcpy.c \
|
||||
%D%/memmove.c \
|
||||
%D%/memset.c \
|
||||
%D%/rindex.c \
|
||||
%D%/strcasecmp.c \
|
||||
%D%/strcat.c \
|
||||
%D%/strchr.c \
|
||||
%D%/strcmp.c \
|
||||
%D%/strcoll.c \
|
||||
%D%/strcpy.c \
|
||||
%D%/strcspn.c \
|
||||
%D%/strdup.c \
|
||||
%D%/strdup_r.c \
|
||||
%D%/strerror.c \
|
||||
%D%/strerror_r.c \
|
||||
%D%/strlcat.c \
|
||||
%D%/strlcpy.c \
|
||||
%D%/strlen.c \
|
||||
%D%/strlwr.c \
|
||||
%D%/strncasecmp.c \
|
||||
%D%/strncat.c \
|
||||
%D%/strncmp.c \
|
||||
%D%/strncpy.c \
|
||||
%D%/strnlen.c \
|
||||
%D%/strnstr.c \
|
||||
%D%/strpbrk.c \
|
||||
%D%/strrchr.c \
|
||||
%D%/strsep.c \
|
||||
%D%/strsignal.c \
|
||||
%D%/strspn.c \
|
||||
%D%/strtok.c \
|
||||
%D%/strtok_r.c \
|
||||
%D%/strupr.c \
|
||||
%D%/strxfrm.c \
|
||||
%D%/strstr.c \
|
||||
%D%/swab.c \
|
||||
%D%/timingsafe_bcmp.c \
|
||||
%D%/timingsafe_memcmp.c \
|
||||
%D%/u_strerr.c \
|
||||
%D%/wcscat.c \
|
||||
%D%/wcschr.c \
|
||||
%D%/wcscmp.c \
|
||||
%D%/wcscoll.c \
|
||||
%D%/wcscpy.c \
|
||||
%D%/wcscspn.c \
|
||||
%D%/wcslcat.c \
|
||||
%D%/wcslcpy.c \
|
||||
%D%/wcslen.c \
|
||||
%D%/wcsncat.c \
|
||||
%D%/wcsncmp.c \
|
||||
%D%/wcsncpy.c \
|
||||
%D%/wcsnlen.c \
|
||||
%D%/wcspbrk.c \
|
||||
%D%/wcsrchr.c \
|
||||
%D%/wcsspn.c \
|
||||
%D%/wcsstr.c \
|
||||
%D%/wcstok.c \
|
||||
%D%/wcswidth.c \
|
||||
%D%/wcsxfrm.c \
|
||||
%D%/wcwidth.c \
|
||||
%D%/wmemchr.c \
|
||||
%D%/wmemcmp.c \
|
||||
%D%/wmemcpy.c \
|
||||
%D%/wmemmove.c \
|
||||
%D%/wmemset.c \
|
||||
%D%/xpg_strerror_r.c
|
||||
|
||||
%C%_ELIX_2_SOURCES =
|
||||
if ELIX_LEVEL_1
|
||||
else
|
||||
%C%_ELIX_2_SOURCES += \
|
||||
%D%/bcmp.c \
|
||||
%D%/memccpy.c \
|
||||
%D%/mempcpy.c \
|
||||
%D%/stpcpy.c \
|
||||
%D%/stpncpy.c \
|
||||
%D%/strndup.c \
|
||||
%D%/strcasestr.c \
|
||||
%D%/strchrnul.c \
|
||||
%D%/strndup_r.c \
|
||||
%D%/wcpcpy.c \
|
||||
%D%/wcpncpy.c \
|
||||
%D%/wcsdup.c
|
||||
endif !ELIX_LEVEL_1
|
||||
|
||||
%C%_ELIX_4_SOURCES =
|
||||
if ELIX_LEVEL_1
|
||||
else
|
||||
if ELIX_LEVEL_2
|
||||
else
|
||||
if ELIX_LEVEL_3
|
||||
else
|
||||
%C%_ELIX_4_SOURCES += \
|
||||
%D%/gnu_basename.c \
|
||||
%D%/memmem.c \
|
||||
%D%/memrchr.c \
|
||||
%D%/rawmemchr.c \
|
||||
%D%/strcasecmp_l.c \
|
||||
%D%/strcoll_l.c \
|
||||
%D%/strncasecmp_l.c \
|
||||
%D%/strverscmp.c \
|
||||
%D%/strxfrm_l.c \
|
||||
%D%/wcscasecmp.c \
|
||||
%D%/wcscasecmp_l.c \
|
||||
%D%/wcscoll_l.c \
|
||||
%D%/wcsncasecmp.c \
|
||||
%D%/wcsncasecmp_l.c \
|
||||
%D%/wcsxfrm_l.c \
|
||||
%D%/wmempcpy.c
|
||||
endif !ELIX_LEVEL_3
|
||||
endif !ELIX_LEVEL_2
|
||||
endif !ELIX_LEVEL_1
|
||||
|
||||
libc_a_SOURCES += $(%C%_ELIX_2_SOURCES) $(%C%_ELIX_4_SOURCES)
|
||||
|
||||
LIBC_CHEWOUT_FILES += \
|
||||
%D%/bcmp.def %D%/memcpy.def %D%/strcmp.def %D%/strncat.def %D%/strstr.def \
|
||||
%D%/bcopy.def %D%/memmove.def %D%/strcoll.def %D%/strncmp.def %D%/strtok.def \
|
||||
%D%/bzero.def %D%/memset.def %D%/strcpy.def %D%/strncpy.def %D%/strxfrm.def \
|
||||
%D%/index.def %D%/rindex.def %D%/strcspn.def %D%/strpbrk.def %D%/swab.def \
|
||||
%D%/memchr.def %D%/strcat.def %D%/strerror.def %D%/strerror_r.def %D%/strrchr.def \
|
||||
%D%/memcmp.def %D%/strchr.def %D%/strlen.def %D%/strnlen.def %D%/strspn.def \
|
||||
%D%/strcasecmp.def %D%/strncasecmp.def %D%/strcasestr.def %D%/strlwr.def %D%/strupr.def \
|
||||
%D%/memccpy.def %D%/mempcpy.def %D%/stpcpy.def %D%/stpncpy.def %D%/strsignal.def \
|
||||
%D%/wcscasecmp.def %D%/wcscat.def %D%/wcschr.def %D%/wcscmp.def %D%/wcscoll.def \
|
||||
%D%/wcscpy.def %D%/wcscspn.def %D%/wcpcpy.def %D%/wcpncpy.def %D%/wcsdup.def \
|
||||
%D%/wcslcat.def %D%/wcslcpy.def %D%/wcslen.def %D%/wcsncasecmp.def %D%/wcsncat.def \
|
||||
%D%/wcsncmp.def %D%/wcsncpy.def %D%/wcsnlen.def %D%/wcspbrk.def \
|
||||
%D%/wcsrchr.def %D%/wcsspn.def %D%/wcsstr.def %D%/wcstok.def \
|
||||
%D%/wcswidth.def %D%/wcsxfrm.def %D%/wcwidth.def %D%/wmemchr.def \
|
||||
%D%/wmemcmp.def %D%/wmemcpy.def %D%/wmemmove.def %D%/wmemset.def \
|
||||
%D%/memmem.def %D%/memrchr.def %D%/rawmemchr.def %D%/strchrnul.def \
|
||||
%D%/strcasecmp_l.def %D%/strcoll_l.def %D%/strncasecmp_l.def %D%/strxfrm_l.def \
|
||||
%D%/wcscasecmp_l.def %D%/wcscoll_l.def %D%/wcsncasecmp_l.def %D%/wcsxfrm_l.def \
|
||||
%D%/strverscmp.def %D%/strnstr.def %D%/wmempcpy.def
|
||||
|
||||
LIBC_CHAPTERS += %D%/strings.tex %D%/wcstrings.tex
|
||||
@@ -0,0 +1,569 @@
|
||||
# UAX #11: East Asian Ambiguous
|
||||
|
||||
# Plane 00
|
||||
# Rows Positions (Cells)
|
||||
|
||||
00 A1 A4 A7-A8 AA AD-AE B0-B4 B6-BA BC-BF C6 D0 D7-D8 DE-E1 E6 E8-EA
|
||||
00 EC-ED F0 F2-F3 F7-FA FC FE
|
||||
01 01 11 13 1B 26-27 2B 31-33 38 3F-42 44 48-4B 4D 52-53 66-67 6B
|
||||
01 CE D0 D2 D4 D6 D8 DA DC
|
||||
02 51 61 C4 C7 C9-CB CD D0 D8-DB DD DF
|
||||
03 00-6F 91-A1 A3-A9 B1-C1 C3-C9
|
||||
04 01 10-4F 51
|
||||
20 10 13-16 18-19 1C-1D 20-22 24-27 30 32-33 35 3B 3E 74 7F 81-84
|
||||
20 AC
|
||||
21 03 05 09 13 16 21-22 26 2B 53-54 5B-5E 60-6B 70-79 89 90-99 B8-B9
|
||||
21 D2 D4 E7
|
||||
22 00 02-03 07-08 0B 0F 11 15 1A 1D-20 23 25 27-2C 2E 34-37 3C-3D
|
||||
22 48 4C 52 60-61 64-67 6A-6B 6E-6F 82-83 86-87 95 99 A5 BF
|
||||
23 12
|
||||
24 60-E9 EB-FF
|
||||
25 00-4B 50-73 80-8F 92-95 A0-A1 A3-A9 B2-B3 B6-B7 BC-BD C0-C1 C6-C8
|
||||
25 CB CE-D1 E2-E5 EF
|
||||
26 05-06 09 0E-0F 1C 1E 40 42 60-61 63-65 67-6A 6C-6D 6F 9E-9F BF
|
||||
26 C6-CD CF-D3 D5-E1 E3 E8-E9 EB-F1 F4 F6-F9 FB-FC FE-FF
|
||||
27 3D 76-7F
|
||||
2B 56-59
|
||||
32 48-4F
|
||||
E0 00-FF
|
||||
E1 00-FF
|
||||
E2 00-FF
|
||||
E3 00-FF
|
||||
E4 00-FF
|
||||
E5 00-FF
|
||||
E6 00-FF
|
||||
E7 00-FF
|
||||
E8 00-FF
|
||||
E9 00-FF
|
||||
EA 00-FF
|
||||
EB 00-FF
|
||||
EC 00-FF
|
||||
ED 00-FF
|
||||
EE 00-FF
|
||||
EF 00-FF
|
||||
F0 00-FF
|
||||
F1 00-FF
|
||||
F2 00-FF
|
||||
F3 00-FF
|
||||
F4 00-FF
|
||||
F5 00-FF
|
||||
F6 00-FF
|
||||
F7 00-FF
|
||||
F8 00-FF
|
||||
FE 00-0F
|
||||
FF FD
|
||||
1F1 00-0A 10-2D 30-69 70-8D 8F-90 9B-AC
|
||||
E01 00-EF
|
||||
F00 00-FF
|
||||
F01 00-FF
|
||||
F02 00-FF
|
||||
F03 00-FF
|
||||
F04 00-FF
|
||||
F05 00-FF
|
||||
F06 00-FF
|
||||
F07 00-FF
|
||||
F08 00-FF
|
||||
F09 00-FF
|
||||
F0A 00-FF
|
||||
F0B 00-FF
|
||||
F0C 00-FF
|
||||
F0D 00-FF
|
||||
F0E 00-FF
|
||||
F0F 00-FF
|
||||
F10 00-FF
|
||||
F11 00-FF
|
||||
F12 00-FF
|
||||
F13 00-FF
|
||||
F14 00-FF
|
||||
F15 00-FF
|
||||
F16 00-FF
|
||||
F17 00-FF
|
||||
F18 00-FF
|
||||
F19 00-FF
|
||||
F1A 00-FF
|
||||
F1B 00-FF
|
||||
F1C 00-FF
|
||||
F1D 00-FF
|
||||
F1E 00-FF
|
||||
F1F 00-FF
|
||||
F20 00-FF
|
||||
F21 00-FF
|
||||
F22 00-FF
|
||||
F23 00-FF
|
||||
F24 00-FF
|
||||
F25 00-FF
|
||||
F26 00-FF
|
||||
F27 00-FF
|
||||
F28 00-FF
|
||||
F29 00-FF
|
||||
F2A 00-FF
|
||||
F2B 00-FF
|
||||
F2C 00-FF
|
||||
F2D 00-FF
|
||||
F2E 00-FF
|
||||
F2F 00-FF
|
||||
F30 00-FF
|
||||
F31 00-FF
|
||||
F32 00-FF
|
||||
F33 00-FF
|
||||
F34 00-FF
|
||||
F35 00-FF
|
||||
F36 00-FF
|
||||
F37 00-FF
|
||||
F38 00-FF
|
||||
F39 00-FF
|
||||
F3A 00-FF
|
||||
F3B 00-FF
|
||||
F3C 00-FF
|
||||
F3D 00-FF
|
||||
F3E 00-FF
|
||||
F3F 00-FF
|
||||
F40 00-FF
|
||||
F41 00-FF
|
||||
F42 00-FF
|
||||
F43 00-FF
|
||||
F44 00-FF
|
||||
F45 00-FF
|
||||
F46 00-FF
|
||||
F47 00-FF
|
||||
F48 00-FF
|
||||
F49 00-FF
|
||||
F4A 00-FF
|
||||
F4B 00-FF
|
||||
F4C 00-FF
|
||||
F4D 00-FF
|
||||
F4E 00-FF
|
||||
F4F 00-FF
|
||||
F50 00-FF
|
||||
F51 00-FF
|
||||
F52 00-FF
|
||||
F53 00-FF
|
||||
F54 00-FF
|
||||
F55 00-FF
|
||||
F56 00-FF
|
||||
F57 00-FF
|
||||
F58 00-FF
|
||||
F59 00-FF
|
||||
F5A 00-FF
|
||||
F5B 00-FF
|
||||
F5C 00-FF
|
||||
F5D 00-FF
|
||||
F5E 00-FF
|
||||
F5F 00-FF
|
||||
F60 00-FF
|
||||
F61 00-FF
|
||||
F62 00-FF
|
||||
F63 00-FF
|
||||
F64 00-FF
|
||||
F65 00-FF
|
||||
F66 00-FF
|
||||
F67 00-FF
|
||||
F68 00-FF
|
||||
F69 00-FF
|
||||
F6A 00-FF
|
||||
F6B 00-FF
|
||||
F6C 00-FF
|
||||
F6D 00-FF
|
||||
F6E 00-FF
|
||||
F6F 00-FF
|
||||
F70 00-FF
|
||||
F71 00-FF
|
||||
F72 00-FF
|
||||
F73 00-FF
|
||||
F74 00-FF
|
||||
F75 00-FF
|
||||
F76 00-FF
|
||||
F77 00-FF
|
||||
F78 00-FF
|
||||
F79 00-FF
|
||||
F7A 00-FF
|
||||
F7B 00-FF
|
||||
F7C 00-FF
|
||||
F7D 00-FF
|
||||
F7E 00-FF
|
||||
F7F 00-FF
|
||||
F80 00-FF
|
||||
F81 00-FF
|
||||
F82 00-FF
|
||||
F83 00-FF
|
||||
F84 00-FF
|
||||
F85 00-FF
|
||||
F86 00-FF
|
||||
F87 00-FF
|
||||
F88 00-FF
|
||||
F89 00-FF
|
||||
F8A 00-FF
|
||||
F8B 00-FF
|
||||
F8C 00-FF
|
||||
F8D 00-FF
|
||||
F8E 00-FF
|
||||
F8F 00-FF
|
||||
F90 00-FF
|
||||
F91 00-FF
|
||||
F92 00-FF
|
||||
F93 00-FF
|
||||
F94 00-FF
|
||||
F95 00-FF
|
||||
F96 00-FF
|
||||
F97 00-FF
|
||||
F98 00-FF
|
||||
F99 00-FF
|
||||
F9A 00-FF
|
||||
F9B 00-FF
|
||||
F9C 00-FF
|
||||
F9D 00-FF
|
||||
F9E 00-FF
|
||||
F9F 00-FF
|
||||
FA0 00-FF
|
||||
FA1 00-FF
|
||||
FA2 00-FF
|
||||
FA3 00-FF
|
||||
FA4 00-FF
|
||||
FA5 00-FF
|
||||
FA6 00-FF
|
||||
FA7 00-FF
|
||||
FA8 00-FF
|
||||
FA9 00-FF
|
||||
FAA 00-FF
|
||||
FAB 00-FF
|
||||
FAC 00-FF
|
||||
FAD 00-FF
|
||||
FAE 00-FF
|
||||
FAF 00-FF
|
||||
FB0 00-FF
|
||||
FB1 00-FF
|
||||
FB2 00-FF
|
||||
FB3 00-FF
|
||||
FB4 00-FF
|
||||
FB5 00-FF
|
||||
FB6 00-FF
|
||||
FB7 00-FF
|
||||
FB8 00-FF
|
||||
FB9 00-FF
|
||||
FBA 00-FF
|
||||
FBB 00-FF
|
||||
FBC 00-FF
|
||||
FBD 00-FF
|
||||
FBE 00-FF
|
||||
FBF 00-FF
|
||||
FC0 00-FF
|
||||
FC1 00-FF
|
||||
FC2 00-FF
|
||||
FC3 00-FF
|
||||
FC4 00-FF
|
||||
FC5 00-FF
|
||||
FC6 00-FF
|
||||
FC7 00-FF
|
||||
FC8 00-FF
|
||||
FC9 00-FF
|
||||
FCA 00-FF
|
||||
FCB 00-FF
|
||||
FCC 00-FF
|
||||
FCD 00-FF
|
||||
FCE 00-FF
|
||||
FCF 00-FF
|
||||
FD0 00-FF
|
||||
FD1 00-FF
|
||||
FD2 00-FF
|
||||
FD3 00-FF
|
||||
FD4 00-FF
|
||||
FD5 00-FF
|
||||
FD6 00-FF
|
||||
FD7 00-FF
|
||||
FD8 00-FF
|
||||
FD9 00-FF
|
||||
FDA 00-FF
|
||||
FDB 00-FF
|
||||
FDC 00-FF
|
||||
FDD 00-FF
|
||||
FDE 00-FF
|
||||
FDF 00-FF
|
||||
FE0 00-FF
|
||||
FE1 00-FF
|
||||
FE2 00-FF
|
||||
FE3 00-FF
|
||||
FE4 00-FF
|
||||
FE5 00-FF
|
||||
FE6 00-FF
|
||||
FE7 00-FF
|
||||
FE8 00-FF
|
||||
FE9 00-FF
|
||||
FEA 00-FF
|
||||
FEB 00-FF
|
||||
FEC 00-FF
|
||||
FED 00-FF
|
||||
FEE 00-FF
|
||||
FEF 00-FF
|
||||
FF0 00-FF
|
||||
FF1 00-FF
|
||||
FF2 00-FF
|
||||
FF3 00-FF
|
||||
FF4 00-FF
|
||||
FF5 00-FF
|
||||
FF6 00-FF
|
||||
FF7 00-FF
|
||||
FF8 00-FF
|
||||
FF9 00-FF
|
||||
FFA 00-FF
|
||||
FFB 00-FF
|
||||
FFC 00-FF
|
||||
FFD 00-FF
|
||||
FFE 00-FF
|
||||
FFF 00-FD
|
||||
1000 00-FF
|
||||
1001 00-FF
|
||||
1002 00-FF
|
||||
1003 00-FF
|
||||
1004 00-FF
|
||||
1005 00-FF
|
||||
1006 00-FF
|
||||
1007 00-FF
|
||||
1008 00-FF
|
||||
1009 00-FF
|
||||
100A 00-FF
|
||||
100B 00-FF
|
||||
100C 00-FF
|
||||
100D 00-FF
|
||||
100E 00-FF
|
||||
100F 00-FF
|
||||
1010 00-FF
|
||||
1011 00-FF
|
||||
1012 00-FF
|
||||
1013 00-FF
|
||||
1014 00-FF
|
||||
1015 00-FF
|
||||
1016 00-FF
|
||||
1017 00-FF
|
||||
1018 00-FF
|
||||
1019 00-FF
|
||||
101A 00-FF
|
||||
101B 00-FF
|
||||
101C 00-FF
|
||||
101D 00-FF
|
||||
101E 00-FF
|
||||
101F 00-FF
|
||||
1020 00-FF
|
||||
1021 00-FF
|
||||
1022 00-FF
|
||||
1023 00-FF
|
||||
1024 00-FF
|
||||
1025 00-FF
|
||||
1026 00-FF
|
||||
1027 00-FF
|
||||
1028 00-FF
|
||||
1029 00-FF
|
||||
102A 00-FF
|
||||
102B 00-FF
|
||||
102C 00-FF
|
||||
102D 00-FF
|
||||
102E 00-FF
|
||||
102F 00-FF
|
||||
1030 00-FF
|
||||
1031 00-FF
|
||||
1032 00-FF
|
||||
1033 00-FF
|
||||
1034 00-FF
|
||||
1035 00-FF
|
||||
1036 00-FF
|
||||
1037 00-FF
|
||||
1038 00-FF
|
||||
1039 00-FF
|
||||
103A 00-FF
|
||||
103B 00-FF
|
||||
103C 00-FF
|
||||
103D 00-FF
|
||||
103E 00-FF
|
||||
103F 00-FF
|
||||
1040 00-FF
|
||||
1041 00-FF
|
||||
1042 00-FF
|
||||
1043 00-FF
|
||||
1044 00-FF
|
||||
1045 00-FF
|
||||
1046 00-FF
|
||||
1047 00-FF
|
||||
1048 00-FF
|
||||
1049 00-FF
|
||||
104A 00-FF
|
||||
104B 00-FF
|
||||
104C 00-FF
|
||||
104D 00-FF
|
||||
104E 00-FF
|
||||
104F 00-FF
|
||||
1050 00-FF
|
||||
1051 00-FF
|
||||
1052 00-FF
|
||||
1053 00-FF
|
||||
1054 00-FF
|
||||
1055 00-FF
|
||||
1056 00-FF
|
||||
1057 00-FF
|
||||
1058 00-FF
|
||||
1059 00-FF
|
||||
105A 00-FF
|
||||
105B 00-FF
|
||||
105C 00-FF
|
||||
105D 00-FF
|
||||
105E 00-FF
|
||||
105F 00-FF
|
||||
1060 00-FF
|
||||
1061 00-FF
|
||||
1062 00-FF
|
||||
1063 00-FF
|
||||
1064 00-FF
|
||||
1065 00-FF
|
||||
1066 00-FF
|
||||
1067 00-FF
|
||||
1068 00-FF
|
||||
1069 00-FF
|
||||
106A 00-FF
|
||||
106B 00-FF
|
||||
106C 00-FF
|
||||
106D 00-FF
|
||||
106E 00-FF
|
||||
106F 00-FF
|
||||
1070 00-FF
|
||||
1071 00-FF
|
||||
1072 00-FF
|
||||
1073 00-FF
|
||||
1074 00-FF
|
||||
1075 00-FF
|
||||
1076 00-FF
|
||||
1077 00-FF
|
||||
1078 00-FF
|
||||
1079 00-FF
|
||||
107A 00-FF
|
||||
107B 00-FF
|
||||
107C 00-FF
|
||||
107D 00-FF
|
||||
107E 00-FF
|
||||
107F 00-FF
|
||||
1080 00-FF
|
||||
1081 00-FF
|
||||
1082 00-FF
|
||||
1083 00-FF
|
||||
1084 00-FF
|
||||
1085 00-FF
|
||||
1086 00-FF
|
||||
1087 00-FF
|
||||
1088 00-FF
|
||||
1089 00-FF
|
||||
108A 00-FF
|
||||
108B 00-FF
|
||||
108C 00-FF
|
||||
108D 00-FF
|
||||
108E 00-FF
|
||||
108F 00-FF
|
||||
1090 00-FF
|
||||
1091 00-FF
|
||||
1092 00-FF
|
||||
1093 00-FF
|
||||
1094 00-FF
|
||||
1095 00-FF
|
||||
1096 00-FF
|
||||
1097 00-FF
|
||||
1098 00-FF
|
||||
1099 00-FF
|
||||
109A 00-FF
|
||||
109B 00-FF
|
||||
109C 00-FF
|
||||
109D 00-FF
|
||||
109E 00-FF
|
||||
109F 00-FF
|
||||
10A0 00-FF
|
||||
10A1 00-FF
|
||||
10A2 00-FF
|
||||
10A3 00-FF
|
||||
10A4 00-FF
|
||||
10A5 00-FF
|
||||
10A6 00-FF
|
||||
10A7 00-FF
|
||||
10A8 00-FF
|
||||
10A9 00-FF
|
||||
10AA 00-FF
|
||||
10AB 00-FF
|
||||
10AC 00-FF
|
||||
10AD 00-FF
|
||||
10AE 00-FF
|
||||
10AF 00-FF
|
||||
10B0 00-FF
|
||||
10B1 00-FF
|
||||
10B2 00-FF
|
||||
10B3 00-FF
|
||||
10B4 00-FF
|
||||
10B5 00-FF
|
||||
10B6 00-FF
|
||||
10B7 00-FF
|
||||
10B8 00-FF
|
||||
10B9 00-FF
|
||||
10BA 00-FF
|
||||
10BB 00-FF
|
||||
10BC 00-FF
|
||||
10BD 00-FF
|
||||
10BE 00-FF
|
||||
10BF 00-FF
|
||||
10C0 00-FF
|
||||
10C1 00-FF
|
||||
10C2 00-FF
|
||||
10C3 00-FF
|
||||
10C4 00-FF
|
||||
10C5 00-FF
|
||||
10C6 00-FF
|
||||
10C7 00-FF
|
||||
10C8 00-FF
|
||||
10C9 00-FF
|
||||
10CA 00-FF
|
||||
10CB 00-FF
|
||||
10CC 00-FF
|
||||
10CD 00-FF
|
||||
10CE 00-FF
|
||||
10CF 00-FF
|
||||
10D0 00-FF
|
||||
10D1 00-FF
|
||||
10D2 00-FF
|
||||
10D3 00-FF
|
||||
10D4 00-FF
|
||||
10D5 00-FF
|
||||
10D6 00-FF
|
||||
10D7 00-FF
|
||||
10D8 00-FF
|
||||
10D9 00-FF
|
||||
10DA 00-FF
|
||||
10DB 00-FF
|
||||
10DC 00-FF
|
||||
10DD 00-FF
|
||||
10DE 00-FF
|
||||
10DF 00-FF
|
||||
10E0 00-FF
|
||||
10E1 00-FF
|
||||
10E2 00-FF
|
||||
10E3 00-FF
|
||||
10E4 00-FF
|
||||
10E5 00-FF
|
||||
10E6 00-FF
|
||||
10E7 00-FF
|
||||
10E8 00-FF
|
||||
10E9 00-FF
|
||||
10EA 00-FF
|
||||
10EB 00-FF
|
||||
10EC 00-FF
|
||||
10ED 00-FF
|
||||
10EE 00-FF
|
||||
10EF 00-FF
|
||||
10F0 00-FF
|
||||
10F1 00-FF
|
||||
10F2 00-FF
|
||||
10F3 00-FF
|
||||
10F4 00-FF
|
||||
10F5 00-FF
|
||||
10F6 00-FF
|
||||
10F7 00-FF
|
||||
10F8 00-FF
|
||||
10F9 00-FF
|
||||
10FA 00-FF
|
||||
10FB 00-FF
|
||||
10FC 00-FF
|
||||
10FD 00-FF
|
||||
10FE 00-FF
|
||||
10FF 00-FD
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
{
|
||||
{ 0x00A1, 0x00A1 }, { 0x00A4, 0x00A4 }, { 0x00A7, 0x00A8 },
|
||||
{ 0x00AA, 0x00AA }, { 0x00AE, 0x00AE }, { 0x00B0, 0x00B4 },
|
||||
{ 0x00B6, 0x00BA }, { 0x00BC, 0x00BF }, { 0x00C6, 0x00C6 },
|
||||
{ 0x00D0, 0x00D0 }, { 0x00D7, 0x00D8 }, { 0x00DE, 0x00E1 },
|
||||
{ 0x00E6, 0x00E6 }, { 0x00E8, 0x00EA }, { 0x00EC, 0x00ED },
|
||||
{ 0x00F0, 0x00F0 }, { 0x00F2, 0x00F3 }, { 0x00F7, 0x00FA },
|
||||
{ 0x00FC, 0x00FC }, { 0x00FE, 0x00FE }, { 0x0101, 0x0101 },
|
||||
{ 0x0111, 0x0111 }, { 0x0113, 0x0113 }, { 0x011B, 0x011B },
|
||||
{ 0x0126, 0x0127 }, { 0x012B, 0x012B }, { 0x0131, 0x0133 },
|
||||
{ 0x0138, 0x0138 }, { 0x013F, 0x0142 }, { 0x0144, 0x0144 },
|
||||
{ 0x0148, 0x014B }, { 0x014D, 0x014D }, { 0x0152, 0x0153 },
|
||||
{ 0x0166, 0x0167 }, { 0x016B, 0x016B }, { 0x01CE, 0x01CE },
|
||||
{ 0x01D0, 0x01D0 }, { 0x01D2, 0x01D2 }, { 0x01D4, 0x01D4 },
|
||||
{ 0x01D6, 0x01D6 }, { 0x01D8, 0x01D8 }, { 0x01DA, 0x01DA },
|
||||
{ 0x01DC, 0x01DC }, { 0x0251, 0x0251 }, { 0x0261, 0x0261 },
|
||||
{ 0x02C4, 0x02C4 }, { 0x02C7, 0x02C7 }, { 0x02C9, 0x02CB },
|
||||
{ 0x02CD, 0x02CD }, { 0x02D0, 0x02D0 }, { 0x02D8, 0x02DB },
|
||||
{ 0x02DD, 0x02DD }, { 0x02DF, 0x02DF }, { 0x0391, 0x03A1 },
|
||||
{ 0x03A3, 0x03A9 }, { 0x03B1, 0x03C1 }, { 0x03C3, 0x03C9 },
|
||||
{ 0x0401, 0x0401 }, { 0x0410, 0x044F }, { 0x0451, 0x0451 },
|
||||
{ 0x2010, 0x2010 }, { 0x2013, 0x2016 }, { 0x2018, 0x2019 },
|
||||
{ 0x201C, 0x201D }, { 0x2020, 0x2022 }, { 0x2024, 0x2027 },
|
||||
{ 0x2030, 0x2030 }, { 0x2032, 0x2033 }, { 0x2035, 0x2035 },
|
||||
{ 0x203B, 0x203B }, { 0x203E, 0x203E }, { 0x2074, 0x2074 },
|
||||
{ 0x207F, 0x207F }, { 0x2081, 0x2084 }, { 0x20AC, 0x20AC },
|
||||
{ 0x2103, 0x2103 }, { 0x2105, 0x2105 }, { 0x2109, 0x2109 },
|
||||
{ 0x2113, 0x2113 }, { 0x2116, 0x2116 }, { 0x2121, 0x2122 },
|
||||
{ 0x2126, 0x2126 }, { 0x212B, 0x212B }, { 0x2153, 0x2154 },
|
||||
{ 0x215B, 0x215E }, { 0x2160, 0x216B }, { 0x2170, 0x2179 },
|
||||
{ 0x2189, 0x2189 }, { 0x2190, 0x2199 }, { 0x21B8, 0x21B9 },
|
||||
{ 0x21D2, 0x21D2 }, { 0x21D4, 0x21D4 }, { 0x21E7, 0x21E7 },
|
||||
{ 0x2200, 0x2200 }, { 0x2202, 0x2203 }, { 0x2207, 0x2208 },
|
||||
{ 0x220B, 0x220B }, { 0x220F, 0x220F }, { 0x2211, 0x2211 },
|
||||
{ 0x2215, 0x2215 }, { 0x221A, 0x221A }, { 0x221D, 0x2220 },
|
||||
{ 0x2223, 0x2223 }, { 0x2225, 0x2225 }, { 0x2227, 0x222C },
|
||||
{ 0x222E, 0x222E }, { 0x2234, 0x2237 }, { 0x223C, 0x223D },
|
||||
{ 0x2248, 0x2248 }, { 0x224C, 0x224C }, { 0x2252, 0x2252 },
|
||||
{ 0x2260, 0x2261 }, { 0x2264, 0x2267 }, { 0x226A, 0x226B },
|
||||
{ 0x226E, 0x226F }, { 0x2282, 0x2283 }, { 0x2286, 0x2287 },
|
||||
{ 0x2295, 0x2295 }, { 0x2299, 0x2299 }, { 0x22A5, 0x22A5 },
|
||||
{ 0x22BF, 0x22BF }, { 0x2312, 0x2312 }, { 0x2460, 0x24E9 },
|
||||
{ 0x24EB, 0x254B }, { 0x2550, 0x2573 }, { 0x2580, 0x258F },
|
||||
{ 0x2592, 0x2595 }, { 0x25A0, 0x25A1 }, { 0x25A3, 0x25A9 },
|
||||
{ 0x25B2, 0x25B3 }, { 0x25B6, 0x25B7 }, { 0x25BC, 0x25BD },
|
||||
{ 0x25C0, 0x25C1 }, { 0x25C6, 0x25C8 }, { 0x25CB, 0x25CB },
|
||||
{ 0x25CE, 0x25D1 }, { 0x25E2, 0x25E5 }, { 0x25EF, 0x25EF },
|
||||
{ 0x2605, 0x2606 }, { 0x2609, 0x2609 }, { 0x260E, 0x260F },
|
||||
{ 0x261C, 0x261C }, { 0x261E, 0x261E }, { 0x2640, 0x2640 },
|
||||
{ 0x2642, 0x2642 }, { 0x2660, 0x2661 }, { 0x2663, 0x2665 },
|
||||
{ 0x2667, 0x266A }, { 0x266C, 0x266D }, { 0x266F, 0x266F },
|
||||
{ 0x269E, 0x269F }, { 0x26BF, 0x26BF }, { 0x26C6, 0x26CD },
|
||||
{ 0x26CF, 0x26D3 }, { 0x26D5, 0x26E1 }, { 0x26E3, 0x26E3 },
|
||||
{ 0x26E8, 0x26E9 }, { 0x26EB, 0x26F1 }, { 0x26F4, 0x26F4 },
|
||||
{ 0x26F6, 0x26F9 }, { 0x26FB, 0x26FC }, { 0x26FE, 0x26FF },
|
||||
{ 0x273D, 0x273D }, { 0x2776, 0x277F }, { 0x2B56, 0x2B59 },
|
||||
{ 0x3248, 0x324F }, { 0xE000, 0xF8FF }, { 0xFFFD, 0xFFFD },
|
||||
{ 0x1F100, 0x1F10A }, { 0x1F110, 0x1F12D }, { 0x1F130, 0x1F169 },
|
||||
{ 0x1F170, 0x1F18D }, { 0x1F18F, 0x1F190 }, { 0x1F19B, 0x1F1AC },
|
||||
{ 0xF0000, 0xFFFFD }, { 0x100000, 0x10FFFD }
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<bcmp>>---compare two memory areas
|
||||
|
||||
INDEX
|
||||
bcmp
|
||||
|
||||
SYNOPSIS
|
||||
#include <strings.h>
|
||||
int bcmp(const void *<[s1]>, const void *<[s2]>, size_t <[n]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function compares not more than <[n]> bytes of the
|
||||
object pointed to by <[s1]> with the object pointed to by <[s2]>.
|
||||
|
||||
This function is identical to <<memcmp>>.
|
||||
|
||||
RETURNS
|
||||
The function returns an integer greater than, equal to or
|
||||
less than zero according to whether the object pointed to by
|
||||
<[s1]> is greater than, equal to or less than the object
|
||||
pointed to by <[s2]>.
|
||||
|
||||
PORTABILITY
|
||||
<<bcmp>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
bcmp ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
int
|
||||
bcmp (const void *m1,
|
||||
const void *m2,
|
||||
size_t n)
|
||||
|
||||
{
|
||||
return memcmp (m1, m2, n);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<bcopy>>---copy memory regions
|
||||
|
||||
SYNOPSIS
|
||||
#include <strings.h>
|
||||
void bcopy(const void *<[in]>, void *<[out]>, size_t <[n]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function copies <[n]> bytes from the memory region
|
||||
pointed to by <[in]> to the memory region pointed to by
|
||||
<[out]>.
|
||||
|
||||
This function is implemented in term of <<memmove>>.
|
||||
|
||||
PORTABILITY
|
||||
<<bcopy>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
bcopy - pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
void
|
||||
bcopy (const void *b1,
|
||||
void *b2,
|
||||
size_t length)
|
||||
{
|
||||
memmove (b2, b1, length);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<bzero>>---initialize memory to zero
|
||||
|
||||
INDEX
|
||||
bzero
|
||||
|
||||
SYNOPSIS
|
||||
#include <strings.h>
|
||||
void bzero(void *<[b]>, size_t <[length]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<bzero>> initializes <[length]> bytes of memory, starting at address
|
||||
<[b]>, to zero.
|
||||
|
||||
RETURNS
|
||||
<<bzero>> does not return a result.
|
||||
|
||||
PORTABILITY
|
||||
<<bzero>> is in the Berkeley Software Distribution.
|
||||
Neither ANSI C nor the System V Interface Definition (Issue 2) require
|
||||
<<bzero>>.
|
||||
|
||||
<<bzero>> requires no supporting OS subroutines.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
bzero(void *b, size_t length)
|
||||
{
|
||||
|
||||
memset(b, 0, length);
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
{
|
||||
{ 0x0300, 0x036F }, { 0x0483, 0x0489 }, { 0x0591, 0x05BD },
|
||||
{ 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 }, { 0x05C4, 0x05C5 },
|
||||
{ 0x05C7, 0x05C7 }, { 0x0600, 0x0605 }, { 0x0610, 0x061A },
|
||||
{ 0x061C, 0x061C }, { 0x064B, 0x065F }, { 0x0670, 0x0670 },
|
||||
{ 0x06D6, 0x06DD }, { 0x06DF, 0x06E4 }, { 0x06E7, 0x06E8 },
|
||||
{ 0x06EA, 0x06ED }, { 0x070F, 0x070F }, { 0x0711, 0x0711 },
|
||||
{ 0x0730, 0x074A }, { 0x07A6, 0x07B0 }, { 0x07EB, 0x07F3 },
|
||||
{ 0x07FD, 0x07FD }, { 0x0816, 0x0819 }, { 0x081B, 0x0823 },
|
||||
{ 0x0825, 0x0827 }, { 0x0829, 0x082D }, { 0x0859, 0x085B },
|
||||
{ 0x0890, 0x0891 }, { 0x0898, 0x089F }, { 0x08CA, 0x0902 },
|
||||
{ 0x093A, 0x093A }, { 0x093C, 0x093C }, { 0x0941, 0x0948 },
|
||||
{ 0x094D, 0x094D }, { 0x0951, 0x0957 }, { 0x0962, 0x0963 },
|
||||
{ 0x0981, 0x0981 }, { 0x09BC, 0x09BC }, { 0x09C1, 0x09C4 },
|
||||
{ 0x09CD, 0x09CD }, { 0x09E2, 0x09E3 }, { 0x09FE, 0x09FE },
|
||||
{ 0x0A01, 0x0A02 }, { 0x0A3C, 0x0A3C }, { 0x0A41, 0x0A42 },
|
||||
{ 0x0A47, 0x0A48 }, { 0x0A4B, 0x0A4D }, { 0x0A51, 0x0A51 },
|
||||
{ 0x0A70, 0x0A71 }, { 0x0A75, 0x0A75 }, { 0x0A81, 0x0A82 },
|
||||
{ 0x0ABC, 0x0ABC }, { 0x0AC1, 0x0AC5 }, { 0x0AC7, 0x0AC8 },
|
||||
{ 0x0ACD, 0x0ACD }, { 0x0AE2, 0x0AE3 }, { 0x0AFA, 0x0AFF },
|
||||
{ 0x0B01, 0x0B01 }, { 0x0B3C, 0x0B3C }, { 0x0B3F, 0x0B3F },
|
||||
{ 0x0B41, 0x0B44 }, { 0x0B4D, 0x0B4D }, { 0x0B55, 0x0B56 },
|
||||
{ 0x0B62, 0x0B63 }, { 0x0B82, 0x0B82 }, { 0x0BC0, 0x0BC0 },
|
||||
{ 0x0BCD, 0x0BCD }, { 0x0C00, 0x0C00 }, { 0x0C04, 0x0C04 },
|
||||
{ 0x0C3C, 0x0C3C }, { 0x0C3E, 0x0C40 }, { 0x0C46, 0x0C48 },
|
||||
{ 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 }, { 0x0C62, 0x0C63 },
|
||||
{ 0x0C81, 0x0C81 }, { 0x0CBC, 0x0CBC }, { 0x0CBF, 0x0CBF },
|
||||
{ 0x0CC6, 0x0CC6 }, { 0x0CCC, 0x0CCD }, { 0x0CE2, 0x0CE3 },
|
||||
{ 0x0D00, 0x0D01 }, { 0x0D3B, 0x0D3C }, { 0x0D41, 0x0D44 },
|
||||
{ 0x0D4D, 0x0D4D }, { 0x0D62, 0x0D63 }, { 0x0D81, 0x0D81 },
|
||||
{ 0x0DCA, 0x0DCA }, { 0x0DD2, 0x0DD4 }, { 0x0DD6, 0x0DD6 },
|
||||
{ 0x0E31, 0x0E31 }, { 0x0E34, 0x0E3A }, { 0x0E47, 0x0E4E },
|
||||
{ 0x0EB1, 0x0EB1 }, { 0x0EB4, 0x0EBC }, { 0x0EC8, 0x0ECE },
|
||||
{ 0x0F18, 0x0F19 }, { 0x0F35, 0x0F35 }, { 0x0F37, 0x0F37 },
|
||||
{ 0x0F39, 0x0F39 }, { 0x0F71, 0x0F7E }, { 0x0F80, 0x0F84 },
|
||||
{ 0x0F86, 0x0F87 }, { 0x0F8D, 0x0F97 }, { 0x0F99, 0x0FBC },
|
||||
{ 0x0FC6, 0x0FC6 }, { 0x102D, 0x1030 }, { 0x1032, 0x1037 },
|
||||
{ 0x1039, 0x103A }, { 0x103D, 0x103E }, { 0x1058, 0x1059 },
|
||||
{ 0x105E, 0x1060 }, { 0x1071, 0x1074 }, { 0x1082, 0x1082 },
|
||||
{ 0x1085, 0x1086 }, { 0x108D, 0x108D }, { 0x109D, 0x109D },
|
||||
{ 0x1160, 0x11FF }, { 0x135D, 0x135F }, { 0x1712, 0x1714 },
|
||||
{ 0x1732, 0x1733 }, { 0x1752, 0x1753 }, { 0x1772, 0x1773 },
|
||||
{ 0x17B4, 0x17B5 }, { 0x17B7, 0x17BD }, { 0x17C6, 0x17C6 },
|
||||
{ 0x17C9, 0x17D3 }, { 0x17DD, 0x17DD }, { 0x180B, 0x180F },
|
||||
{ 0x1885, 0x1886 }, { 0x18A9, 0x18A9 }, { 0x1920, 0x1922 },
|
||||
{ 0x1927, 0x1928 }, { 0x1932, 0x1932 }, { 0x1939, 0x193B },
|
||||
{ 0x1A17, 0x1A18 }, { 0x1A1B, 0x1A1B }, { 0x1A56, 0x1A56 },
|
||||
{ 0x1A58, 0x1A5E }, { 0x1A60, 0x1A60 }, { 0x1A62, 0x1A62 },
|
||||
{ 0x1A65, 0x1A6C }, { 0x1A73, 0x1A7C }, { 0x1A7F, 0x1A7F },
|
||||
{ 0x1AB0, 0x1ACE }, { 0x1B00, 0x1B03 }, { 0x1B34, 0x1B34 },
|
||||
{ 0x1B36, 0x1B3A }, { 0x1B3C, 0x1B3C }, { 0x1B42, 0x1B42 },
|
||||
{ 0x1B6B, 0x1B73 }, { 0x1B80, 0x1B81 }, { 0x1BA2, 0x1BA5 },
|
||||
{ 0x1BA8, 0x1BA9 }, { 0x1BAB, 0x1BAD }, { 0x1BE6, 0x1BE6 },
|
||||
{ 0x1BE8, 0x1BE9 }, { 0x1BED, 0x1BED }, { 0x1BEF, 0x1BF1 },
|
||||
{ 0x1C2C, 0x1C33 }, { 0x1C36, 0x1C37 }, { 0x1CD0, 0x1CD2 },
|
||||
{ 0x1CD4, 0x1CE0 }, { 0x1CE2, 0x1CE8 }, { 0x1CED, 0x1CED },
|
||||
{ 0x1CF4, 0x1CF4 }, { 0x1CF8, 0x1CF9 }, { 0x1DC0, 0x1DFF },
|
||||
{ 0x200B, 0x200F }, { 0x202A, 0x202E }, { 0x2060, 0x2064 },
|
||||
{ 0x2066, 0x206F }, { 0x20D0, 0x20F0 }, { 0x2CEF, 0x2CF1 },
|
||||
{ 0x2D7F, 0x2D7F }, { 0x2DE0, 0x2DFF }, { 0x302A, 0x302D },
|
||||
{ 0x3099, 0x309A }, { 0xA66F, 0xA672 }, { 0xA674, 0xA67D },
|
||||
{ 0xA69E, 0xA69F }, { 0xA6F0, 0xA6F1 }, { 0xA802, 0xA802 },
|
||||
{ 0xA806, 0xA806 }, { 0xA80B, 0xA80B }, { 0xA825, 0xA826 },
|
||||
{ 0xA82C, 0xA82C }, { 0xA8C4, 0xA8C5 }, { 0xA8E0, 0xA8F1 },
|
||||
{ 0xA8FF, 0xA8FF }, { 0xA926, 0xA92D }, { 0xA947, 0xA951 },
|
||||
{ 0xA980, 0xA982 }, { 0xA9B3, 0xA9B3 }, { 0xA9B6, 0xA9B9 },
|
||||
{ 0xA9BC, 0xA9BD }, { 0xA9E5, 0xA9E5 }, { 0xAA29, 0xAA2E },
|
||||
{ 0xAA31, 0xAA32 }, { 0xAA35, 0xAA36 }, { 0xAA43, 0xAA43 },
|
||||
{ 0xAA4C, 0xAA4C }, { 0xAA7C, 0xAA7C }, { 0xAAB0, 0xAAB0 },
|
||||
{ 0xAAB2, 0xAAB4 }, { 0xAAB7, 0xAAB8 }, { 0xAABE, 0xAABF },
|
||||
{ 0xAAC1, 0xAAC1 }, { 0xAAEC, 0xAAED }, { 0xAAF6, 0xAAF6 },
|
||||
{ 0xABE5, 0xABE5 }, { 0xABE8, 0xABE8 }, { 0xABED, 0xABED },
|
||||
{ 0xD7B0, 0xD7C6 }, { 0xD7CB, 0xD7FB }, { 0xFB1E, 0xFB1E },
|
||||
{ 0xFE00, 0xFE0F }, { 0xFE20, 0xFE2F }, { 0xFEFF, 0xFEFF },
|
||||
{ 0xFFF9, 0xFFFB }, { 0x101FD, 0x101FD }, { 0x102E0, 0x102E0 },
|
||||
{ 0x10376, 0x1037A }, { 0x10A01, 0x10A03 }, { 0x10A05, 0x10A06 },
|
||||
{ 0x10A0C, 0x10A0F }, { 0x10A38, 0x10A3A }, { 0x10A3F, 0x10A3F },
|
||||
{ 0x10AE5, 0x10AE6 }, { 0x10D24, 0x10D27 }, { 0x10EAB, 0x10EAC },
|
||||
{ 0x10EFD, 0x10EFF }, { 0x10F46, 0x10F50 }, { 0x10F82, 0x10F85 },
|
||||
{ 0x11001, 0x11001 }, { 0x11038, 0x11046 }, { 0x11070, 0x11070 },
|
||||
{ 0x11073, 0x11074 }, { 0x1107F, 0x11081 }, { 0x110B3, 0x110B6 },
|
||||
{ 0x110B9, 0x110BA }, { 0x110BD, 0x110BD }, { 0x110C2, 0x110C2 },
|
||||
{ 0x110CD, 0x110CD }, { 0x11100, 0x11102 }, { 0x11127, 0x1112B },
|
||||
{ 0x1112D, 0x11134 }, { 0x11173, 0x11173 }, { 0x11180, 0x11181 },
|
||||
{ 0x111B6, 0x111BE }, { 0x111C9, 0x111CC }, { 0x111CF, 0x111CF },
|
||||
{ 0x1122F, 0x11231 }, { 0x11234, 0x11234 }, { 0x11236, 0x11237 },
|
||||
{ 0x1123E, 0x1123E }, { 0x11241, 0x11241 }, { 0x112DF, 0x112DF },
|
||||
{ 0x112E3, 0x112EA }, { 0x11300, 0x11301 }, { 0x1133B, 0x1133C },
|
||||
{ 0x11340, 0x11340 }, { 0x11366, 0x1136C }, { 0x11370, 0x11374 },
|
||||
{ 0x11438, 0x1143F }, { 0x11442, 0x11444 }, { 0x11446, 0x11446 },
|
||||
{ 0x1145E, 0x1145E }, { 0x114B3, 0x114B8 }, { 0x114BA, 0x114BA },
|
||||
{ 0x114BF, 0x114C0 }, { 0x114C2, 0x114C3 }, { 0x115B2, 0x115B5 },
|
||||
{ 0x115BC, 0x115BD }, { 0x115BF, 0x115C0 }, { 0x115DC, 0x115DD },
|
||||
{ 0x11633, 0x1163A }, { 0x1163D, 0x1163D }, { 0x1163F, 0x11640 },
|
||||
{ 0x116AB, 0x116AB }, { 0x116AD, 0x116AD }, { 0x116B0, 0x116B5 },
|
||||
{ 0x116B7, 0x116B7 }, { 0x1171D, 0x1171F }, { 0x11722, 0x11725 },
|
||||
{ 0x11727, 0x1172B }, { 0x1182F, 0x11837 }, { 0x11839, 0x1183A },
|
||||
{ 0x1193B, 0x1193C }, { 0x1193E, 0x1193E }, { 0x11943, 0x11943 },
|
||||
{ 0x119D4, 0x119D7 }, { 0x119DA, 0x119DB }, { 0x119E0, 0x119E0 },
|
||||
{ 0x11A01, 0x11A0A }, { 0x11A33, 0x11A38 }, { 0x11A3B, 0x11A3E },
|
||||
{ 0x11A47, 0x11A47 }, { 0x11A51, 0x11A56 }, { 0x11A59, 0x11A5B },
|
||||
{ 0x11A8A, 0x11A96 }, { 0x11A98, 0x11A99 }, { 0x11C30, 0x11C36 },
|
||||
{ 0x11C38, 0x11C3D }, { 0x11C3F, 0x11C3F }, { 0x11C92, 0x11CA7 },
|
||||
{ 0x11CAA, 0x11CB0 }, { 0x11CB2, 0x11CB3 }, { 0x11CB5, 0x11CB6 },
|
||||
{ 0x11D31, 0x11D36 }, { 0x11D3A, 0x11D3A }, { 0x11D3C, 0x11D3D },
|
||||
{ 0x11D3F, 0x11D45 }, { 0x11D47, 0x11D47 }, { 0x11D90, 0x11D91 },
|
||||
{ 0x11D95, 0x11D95 }, { 0x11D97, 0x11D97 }, { 0x11EF3, 0x11EF4 },
|
||||
{ 0x11F00, 0x11F01 }, { 0x11F36, 0x11F3A }, { 0x11F40, 0x11F40 },
|
||||
{ 0x11F42, 0x11F42 }, { 0x13430, 0x13440 }, { 0x13447, 0x13455 },
|
||||
{ 0x16AF0, 0x16AF4 }, { 0x16B30, 0x16B36 }, { 0x16F4F, 0x16F4F },
|
||||
{ 0x16F8F, 0x16F92 }, { 0x16FE4, 0x16FE4 }, { 0x1BC9D, 0x1BC9E },
|
||||
{ 0x1BCA0, 0x1BCA3 }, { 0x1CF00, 0x1CF2D }, { 0x1CF30, 0x1CF46 },
|
||||
{ 0x1D167, 0x1D169 }, { 0x1D173, 0x1D182 }, { 0x1D185, 0x1D18B },
|
||||
{ 0x1D1AA, 0x1D1AD }, { 0x1D242, 0x1D244 }, { 0x1DA00, 0x1DA36 },
|
||||
{ 0x1DA3B, 0x1DA6C }, { 0x1DA75, 0x1DA75 }, { 0x1DA84, 0x1DA84 },
|
||||
{ 0x1DA9B, 0x1DA9F }, { 0x1DAA1, 0x1DAAF }, { 0x1E000, 0x1E006 },
|
||||
{ 0x1E008, 0x1E018 }, { 0x1E01B, 0x1E021 }, { 0x1E023, 0x1E024 },
|
||||
{ 0x1E026, 0x1E02A }, { 0x1E08F, 0x1E08F }, { 0x1E130, 0x1E136 },
|
||||
{ 0x1E2AE, 0x1E2AE }, { 0x1E2EC, 0x1E2EF }, { 0x1E4EC, 0x1E4EF },
|
||||
{ 0x1E8D0, 0x1E8D6 }, { 0x1E944, 0x1E94A }, { 0xE0001, 0xE0001 },
|
||||
{ 0xE0020, 0xE007F }, { 0xE0100, 0xE01EF }
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
/* $OpenBSD: explicit_bzero.c,v 1.2 2014/06/10 04:17:37 deraadt Exp $ */
|
||||
/*
|
||||
* Public domain.
|
||||
* Written by Ted Unangst
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* explicit_bzero - don't let the compiler optimize away bzero
|
||||
*/
|
||||
void
|
||||
explicit_bzero(void *p, size_t n)
|
||||
{
|
||||
bzero(p, n);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*-
|
||||
* Copyright (c) 2017 embedded brains GmbH
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <strings.h>
|
||||
|
||||
int
|
||||
ffsl(long i)
|
||||
{
|
||||
|
||||
return (__builtin_ffsl(i));
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*-
|
||||
* Copyright (c) 2017 embedded brains GmbH
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <strings.h>
|
||||
|
||||
int
|
||||
ffsll(long long i)
|
||||
{
|
||||
|
||||
return (__builtin_ffsll(i));
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*-
|
||||
* Copyright (c) 2017 embedded brains GmbH
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <strings.h>
|
||||
#include <limits.h>
|
||||
|
||||
int
|
||||
fls(int i)
|
||||
{
|
||||
|
||||
if (i == 0)
|
||||
return 0;
|
||||
|
||||
return (sizeof(i) * CHAR_BIT - __builtin_clz(i));
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*-
|
||||
* Copyright (c) 2017 embedded brains GmbH
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <strings.h>
|
||||
#include <limits.h>
|
||||
|
||||
int
|
||||
flsl(long i)
|
||||
{
|
||||
|
||||
if (i == 0)
|
||||
return 0;
|
||||
|
||||
return (sizeof(i) * CHAR_BIT - __builtin_clzl(i));
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*-
|
||||
* Copyright (c) 2017 embedded brains GmbH
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <strings.h>
|
||||
#include <limits.h>
|
||||
|
||||
int
|
||||
flsll(long long i)
|
||||
{
|
||||
|
||||
if (i == 0)
|
||||
return 0;
|
||||
|
||||
return (sizeof(i) * CHAR_BIT - __builtin_clzll(i));
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef _NO_BASENAME
|
||||
/* Copyright 2015 Red Hat, Inc.
|
||||
* Permission to use, copy, modify, and distribute this software
|
||||
* is freely granted, provided that this notice is preserved.
|
||||
*/
|
||||
|
||||
/* The differences with the POSIX version (unix/basename.c):
|
||||
* - declared in <string.h> (instead of <libgen.h>);
|
||||
* - the argument is never modified, and therefore is marked const;
|
||||
* - the empty string is returned if path is an empty string, "/", or ends
|
||||
* with a trailing slash.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
__gnu_basename (const char *path)
|
||||
{
|
||||
char *p;
|
||||
if ((p = strrchr (path, '/')))
|
||||
return p + 1;
|
||||
return (char *) path;
|
||||
}
|
||||
|
||||
#endif /* !_NO_BASENAME */
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<index>>---search for character in string
|
||||
|
||||
INDEX
|
||||
index
|
||||
|
||||
SYNOPSIS
|
||||
#include <strings.h>
|
||||
char * index(const char *<[string]>, int <[c]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function finds the first occurence of <[c]> (converted to
|
||||
a char) in the string pointed to by <[string]> (including the
|
||||
terminating null character).
|
||||
|
||||
This function is identical to <<strchr>>.
|
||||
|
||||
RETURNS
|
||||
Returns a pointer to the located character, or a null pointer
|
||||
if <[c]> does not occur in <[string]>.
|
||||
|
||||
PORTABILITY
|
||||
<<index>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
index - pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
char *
|
||||
index (const char *s,
|
||||
int c)
|
||||
{
|
||||
return strchr (s, c);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#include <_ansi.h>
|
||||
#include "../ctype/local.h"
|
||||
|
||||
/* internal function to compute width of wide char. */
|
||||
int __wcwidth (wint_t);
|
||||
|
||||
/*
|
||||
Taken from glibc:
|
||||
Add the compiler optimization to inhibit loop transformation to library
|
||||
calls. This is used to avoid recursive calls in memset and memmove
|
||||
default implementations.
|
||||
*/
|
||||
#ifdef _HAVE_CC_INHIBIT_LOOP_TO_LIBCALL
|
||||
# define __inhibit_loop_to_libcall \
|
||||
__attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns")))
|
||||
#else
|
||||
# define __inhibit_loop_to_libcall
|
||||
#endif
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<memccpy>>---copy memory regions with end-token check
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
void* memccpy(void *restrict <[out]>, const void *restrict <[in]>,
|
||||
int <[endchar]>, size_t <[n]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function copies up to <[n]> bytes from the memory region
|
||||
pointed to by <[in]> to the memory region pointed to by
|
||||
<[out]>. If a byte matching the <[endchar]> is encountered,
|
||||
the byte is copied and copying stops.
|
||||
|
||||
If the regions overlap, the behavior is undefined.
|
||||
|
||||
RETURNS
|
||||
<<memccpy>> returns a pointer to the first byte following the
|
||||
<[endchar]> in the <[out]> region. If no byte matching
|
||||
<[endchar]> was copied, then <<NULL>> is returned.
|
||||
|
||||
PORTABILITY
|
||||
<<memccpy>> is a GNU extension.
|
||||
|
||||
<<memccpy>> requires no supporting OS subroutines.
|
||||
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
/* Nonzero if either X or Y is not aligned on a "long" boundary. */
|
||||
#define UNALIGNED(X, Y) \
|
||||
(((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
|
||||
|
||||
/* How many bytes are copied each iteration of the word copy loop. */
|
||||
#define LITTLEBLOCKSIZE (sizeof (long))
|
||||
|
||||
/* Threshhold for punting to the byte copier. */
|
||||
#define TOO_SMALL(LEN) ((LEN) < LITTLEBLOCKSIZE)
|
||||
|
||||
/* Macros for detecting endchar */
|
||||
#if LONG_MAX == 2147483647L
|
||||
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
|
||||
#else
|
||||
#if LONG_MAX == 9223372036854775807L
|
||||
/* Nonzero if X (a long int) contains a NULL byte. */
|
||||
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
|
||||
#else
|
||||
#error long int is not a 32bit or 64bit type.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
void *
|
||||
memccpy (void *__restrict dst0,
|
||||
const void *__restrict src0,
|
||||
int endchar0,
|
||||
size_t len0)
|
||||
{
|
||||
|
||||
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
|
||||
void *ptr = NULL;
|
||||
char *dst = (char *) dst0;
|
||||
char *src = (char *) src0;
|
||||
char endchar = endchar0 & 0xff;
|
||||
|
||||
while (len0--)
|
||||
{
|
||||
if ((*dst++ = *src++) == endchar)
|
||||
{
|
||||
ptr = dst;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ptr;
|
||||
#else
|
||||
void *ptr = NULL;
|
||||
unsigned char *dst = dst0;
|
||||
const unsigned char *src = src0;
|
||||
long *aligned_dst;
|
||||
const long *aligned_src;
|
||||
unsigned char endchar = endchar0 & 0xff;
|
||||
|
||||
/* If the size is small, or either SRC or DST is unaligned,
|
||||
then punt into the byte copy loop. This should be rare. */
|
||||
if (!TOO_SMALL(len0) && !UNALIGNED (src, dst))
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned long mask = 0;
|
||||
|
||||
aligned_dst = (long*)dst;
|
||||
aligned_src = (long*)src;
|
||||
|
||||
/* The fast code reads the ASCII one word at a time and only
|
||||
performs the bytewise search on word-sized segments if they
|
||||
contain the search character, which is detected by XORing
|
||||
the word-sized segment with a word-sized block of the search
|
||||
character and then detecting for the presence of NULL in the
|
||||
result. */
|
||||
for (i = 0; i < LITTLEBLOCKSIZE; i++)
|
||||
mask = (mask << 8) + endchar;
|
||||
|
||||
|
||||
/* Copy one long word at a time if possible. */
|
||||
while (len0 >= LITTLEBLOCKSIZE)
|
||||
{
|
||||
unsigned long buffer = (unsigned long)(*aligned_src);
|
||||
buffer ^= mask;
|
||||
if (DETECTNULL (buffer))
|
||||
break; /* endchar is found, go byte by byte from here */
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
len0 -= LITTLEBLOCKSIZE;
|
||||
}
|
||||
|
||||
/* Pick up any residual with a byte copier. */
|
||||
dst = (char*)aligned_dst;
|
||||
src = (char*)aligned_src;
|
||||
}
|
||||
|
||||
while (len0--)
|
||||
{
|
||||
if ((*dst++ = *src++) == endchar)
|
||||
{
|
||||
ptr = dst;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ptr;
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<memchr>>---find character in memory
|
||||
|
||||
INDEX
|
||||
memchr
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
void *memchr(const void *<[src]>, int <[c]>, size_t <[length]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function searches memory starting at <<*<[src]>>> for the
|
||||
character <[c]>. The search only ends with the first
|
||||
occurrence of <[c]>, or after <[length]> characters; in
|
||||
particular, <<NUL>> does not terminate the search.
|
||||
|
||||
RETURNS
|
||||
If the character <[c]> is found within <[length]> characters
|
||||
of <<*<[src]>>>, a pointer to the character is returned. If
|
||||
<[c]> is not found, then <<NULL>> is returned.
|
||||
|
||||
PORTABILITY
|
||||
<<memchr>> is ANSI C.
|
||||
|
||||
<<memchr>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
memchr ansi pure
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
/* Nonzero if either X or Y is not aligned on a "long" boundary. */
|
||||
#define UNALIGNED(X) ((long)X & (sizeof (long) - 1))
|
||||
|
||||
/* How many bytes are loaded each iteration of the word copy loop. */
|
||||
#define LBLOCKSIZE (sizeof (long))
|
||||
|
||||
/* Threshhold for punting to the bytewise iterator. */
|
||||
#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
|
||||
|
||||
#if LONG_MAX == 2147483647L
|
||||
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
|
||||
#else
|
||||
#if LONG_MAX == 9223372036854775807L
|
||||
/* Nonzero if X (a long int) contains a NULL byte. */
|
||||
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
|
||||
#else
|
||||
#error long int is not a 32bit or 64bit type.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DETECTNULL
|
||||
#error long int is not a 32bit or 64bit byte
|
||||
#endif
|
||||
|
||||
/* DETECTCHAR returns nonzero if (long)X contains the byte used
|
||||
to fill (long)MASK. */
|
||||
#define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK))
|
||||
|
||||
void *
|
||||
memchr (const void *src_void,
|
||||
int c,
|
||||
size_t length)
|
||||
{
|
||||
const unsigned char *src = (const unsigned char *) src_void;
|
||||
unsigned char d = c;
|
||||
|
||||
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
|
||||
unsigned long *asrc;
|
||||
unsigned long mask;
|
||||
unsigned int i;
|
||||
|
||||
while (UNALIGNED (src))
|
||||
{
|
||||
if (!length--)
|
||||
return NULL;
|
||||
if (*src == d)
|
||||
return (void *) src;
|
||||
src++;
|
||||
}
|
||||
|
||||
if (!TOO_SMALL (length))
|
||||
{
|
||||
/* If we get this far, we know that length is large and src is
|
||||
word-aligned. */
|
||||
/* The fast code reads the source one word at a time and only
|
||||
performs the bytewise search on word-sized segments if they
|
||||
contain the search character, which is detected by XORing
|
||||
the word-sized segment with a word-sized block of the search
|
||||
character and then detecting for the presence of NUL in the
|
||||
result. */
|
||||
asrc = (unsigned long *) src;
|
||||
mask = d << 8 | d;
|
||||
mask = mask << 16 | mask;
|
||||
for (i = 32; i < LBLOCKSIZE * 8; i <<= 1)
|
||||
mask = (mask << i) | mask;
|
||||
|
||||
while (length >= LBLOCKSIZE)
|
||||
{
|
||||
if (DETECTCHAR (*asrc, mask))
|
||||
break;
|
||||
length -= LBLOCKSIZE;
|
||||
asrc++;
|
||||
}
|
||||
|
||||
/* If there are fewer than LBLOCKSIZE characters left,
|
||||
then we resort to the bytewise loop. */
|
||||
|
||||
src = (unsigned char *) asrc;
|
||||
}
|
||||
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
|
||||
while (length--)
|
||||
{
|
||||
if (*src == d)
|
||||
return (void *) src;
|
||||
src++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<memcmp>>---compare two memory areas
|
||||
|
||||
INDEX
|
||||
memcmp
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
int memcmp(const void *<[s1]>, const void *<[s2]>, size_t <[n]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function compares not more than <[n]> characters of the
|
||||
object pointed to by <[s1]> with the object pointed to by <[s2]>.
|
||||
|
||||
|
||||
RETURNS
|
||||
The function returns an integer greater than, equal to or
|
||||
less than zero according to whether the object pointed to by
|
||||
<[s1]> is greater than, equal to or less than the object
|
||||
pointed to by <[s2]>.
|
||||
|
||||
PORTABILITY
|
||||
<<memcmp>> is ANSI C.
|
||||
|
||||
<<memcmp>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
memcmp ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/* Nonzero if either X or Y is not aligned on a "long" boundary. */
|
||||
#define UNALIGNED(X, Y) \
|
||||
(((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
|
||||
|
||||
/* How many bytes are copied each iteration of the word copy loop. */
|
||||
#define LBLOCKSIZE (sizeof (long))
|
||||
|
||||
/* Threshhold for punting to the byte copier. */
|
||||
#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
|
||||
|
||||
int
|
||||
memcmp (const void *m1,
|
||||
const void *m2,
|
||||
size_t n)
|
||||
{
|
||||
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
|
||||
unsigned char *s1 = (unsigned char *) m1;
|
||||
unsigned char *s2 = (unsigned char *) m2;
|
||||
|
||||
while (n--)
|
||||
{
|
||||
if (*s1 != *s2)
|
||||
{
|
||||
return *s1 - *s2;
|
||||
}
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
unsigned char *s1 = (unsigned char *) m1;
|
||||
unsigned char *s2 = (unsigned char *) m2;
|
||||
unsigned long *a1;
|
||||
unsigned long *a2;
|
||||
|
||||
/* If the size is too small, or either pointer is unaligned,
|
||||
then we punt to the byte compare loop. Hopefully this will
|
||||
not turn up in inner loops. */
|
||||
if (!TOO_SMALL(n) && !UNALIGNED(s1,s2))
|
||||
{
|
||||
/* Otherwise, load and compare the blocks of memory one
|
||||
word at a time. */
|
||||
a1 = (unsigned long*) s1;
|
||||
a2 = (unsigned long*) s2;
|
||||
while (n >= LBLOCKSIZE)
|
||||
{
|
||||
if (*a1 != *a2)
|
||||
break;
|
||||
a1++;
|
||||
a2++;
|
||||
n -= LBLOCKSIZE;
|
||||
}
|
||||
|
||||
/* check m mod LBLOCKSIZE remaining characters */
|
||||
|
||||
s1 = (unsigned char*)a1;
|
||||
s2 = (unsigned char*)a2;
|
||||
}
|
||||
|
||||
while (n--)
|
||||
{
|
||||
if (*s1 != *s2)
|
||||
return *s1 - *s2;
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<memcpy>>---copy memory regions
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
void* memcpy(void *restrict <[out]>, const void *restrict <[in]>,
|
||||
size_t <[n]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function copies <[n]> bytes from the memory region
|
||||
pointed to by <[in]> to the memory region pointed to by
|
||||
<[out]>.
|
||||
|
||||
If the regions overlap, the behavior is undefined.
|
||||
|
||||
RETURNS
|
||||
<<memcpy>> returns a pointer to the first byte of the <[out]>
|
||||
region.
|
||||
|
||||
PORTABILITY
|
||||
<<memcpy>> is ANSI C.
|
||||
|
||||
<<memcpy>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
memcpy ansi pure
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <string.h>
|
||||
#include "local.h"
|
||||
|
||||
/* Nonzero if either X or Y is not aligned on a "long" boundary. */
|
||||
#define UNALIGNED(X, Y) \
|
||||
(((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
|
||||
|
||||
/* How many bytes are copied each iteration of the 4X unrolled loop. */
|
||||
#define BIGBLOCKSIZE (sizeof (long) << 2)
|
||||
|
||||
/* How many bytes are copied each iteration of the word copy loop. */
|
||||
#define LITTLEBLOCKSIZE (sizeof (long))
|
||||
|
||||
/* Threshhold for punting to the byte copier. */
|
||||
#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE)
|
||||
|
||||
void *
|
||||
__inhibit_loop_to_libcall
|
||||
memcpy (void *__restrict dst0,
|
||||
const void *__restrict src0,
|
||||
size_t len0)
|
||||
{
|
||||
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
|
||||
char *dst = (char *) dst0;
|
||||
char *src = (char *) src0;
|
||||
|
||||
void *save = dst0;
|
||||
|
||||
while (len0--)
|
||||
{
|
||||
*dst++ = *src++;
|
||||
}
|
||||
|
||||
return save;
|
||||
#else
|
||||
char *dst = dst0;
|
||||
const char *src = src0;
|
||||
long *aligned_dst;
|
||||
const long *aligned_src;
|
||||
|
||||
/* If the size is small, or either SRC or DST is unaligned,
|
||||
then punt into the byte copy loop. This should be rare. */
|
||||
if (!TOO_SMALL(len0) && !UNALIGNED (src, dst))
|
||||
{
|
||||
aligned_dst = (long*)dst;
|
||||
aligned_src = (long*)src;
|
||||
|
||||
/* Copy 4X long words at a time if possible. */
|
||||
while (len0 >= BIGBLOCKSIZE)
|
||||
{
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
len0 -= BIGBLOCKSIZE;
|
||||
}
|
||||
|
||||
/* Copy one long word at a time if possible. */
|
||||
while (len0 >= LITTLEBLOCKSIZE)
|
||||
{
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
len0 -= LITTLEBLOCKSIZE;
|
||||
}
|
||||
|
||||
/* Pick up any residual with a byte copier. */
|
||||
dst = (char*)aligned_dst;
|
||||
src = (char*)aligned_src;
|
||||
}
|
||||
|
||||
while (len0--)
|
||||
*dst++ = *src++;
|
||||
|
||||
return dst0;
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
/* Optimized memmem function.
|
||||
Copyright (c) 2018 Arm Ltd. All rights reserved.
|
||||
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. The name of the company may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
||||
|
||||
/*
|
||||
FUNCTION
|
||||
<<memmem>>---find memory segment
|
||||
|
||||
INDEX
|
||||
memmem
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
void *memmem(const void *<[s1]>, size_t <[l1]>, const void *<[s2]>,
|
||||
size_t <[l2]>);
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
Locates the first occurrence in the memory region pointed to
|
||||
by <[s1]> with length <[l1]> of the sequence of bytes pointed
|
||||
to by <[s2]> of length <[l2]>. If you already know the
|
||||
lengths of your haystack and needle, <<memmem>> is much faster
|
||||
than <<strstr>>.
|
||||
|
||||
RETURNS
|
||||
Returns a pointer to the located segment, or a null pointer if
|
||||
<[s2]> is not found. If <[l2]> is 0, <[s1]> is returned.
|
||||
|
||||
PORTABILITY
|
||||
<<memmem>> is a newlib extension.
|
||||
|
||||
<<memmem>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
memmem pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
|
||||
|
||||
/* Small and efficient memmem implementation (quadratic worst-case). */
|
||||
void *
|
||||
memmem (const void *haystack, size_t hs_len, const void *needle, size_t ne_len)
|
||||
{
|
||||
const char *hs = haystack;
|
||||
const char *ne = needle;
|
||||
|
||||
if (ne_len == 0)
|
||||
return (void *)hs;
|
||||
int i;
|
||||
int c = ne[0];
|
||||
const char *end = hs + hs_len - ne_len;
|
||||
|
||||
for ( ; hs <= end; hs++)
|
||||
{
|
||||
if (hs[0] != c)
|
||||
continue;
|
||||
for (i = ne_len - 1; i != 0; i--)
|
||||
if (hs[i] != ne[i])
|
||||
break;
|
||||
if (i == 0)
|
||||
return (void *)hs;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
# define RETURN_TYPE void *
|
||||
# define AVAILABLE(h, h_l, j, n_l) ((j) <= (h_l) - (n_l))
|
||||
# include "str-two-way.h"
|
||||
|
||||
#define hash2(p) (((size_t)(p)[0] - ((size_t)(p)[-1] << 3)) % sizeof (shift))
|
||||
|
||||
/* Fast memmem algorithm with guaranteed linear-time performance.
|
||||
Small needles up to size 2 use a dedicated linear search. Longer needles
|
||||
up to size 256 use a novel modified Horspool algorithm. It hashes pairs
|
||||
of characters to quickly skip past mismatches. The main search loop only
|
||||
exits if the last 2 characters match, avoiding unnecessary calls to memcmp
|
||||
and allowing for a larger skip if there is no match. A self-adapting
|
||||
filtering check is used to quickly detect mismatches in long needles.
|
||||
By limiting the needle length to 256, the shift table can be reduced to 8
|
||||
bits per entry, lowering preprocessing overhead and minimizing cache effects.
|
||||
The limit also implies worst-case performance is linear.
|
||||
Needles larger than 256 characters use the linear-time Two-Way algorithm. */
|
||||
void *
|
||||
memmem (const void *haystack, size_t hs_len, const void *needle, size_t ne_len)
|
||||
{
|
||||
const unsigned char *hs = haystack;
|
||||
const unsigned char *ne = needle;
|
||||
|
||||
if (ne_len == 0)
|
||||
return (void *) hs;
|
||||
if (ne_len == 1)
|
||||
return (void *) memchr (hs, ne[0], hs_len);
|
||||
|
||||
/* Ensure haystack length is >= needle length. */
|
||||
if (hs_len < ne_len)
|
||||
return NULL;
|
||||
|
||||
const unsigned char *end = hs + hs_len - ne_len;
|
||||
|
||||
if (ne_len == 2)
|
||||
{
|
||||
uint32_t nw = ne[0] << 16 | ne[1], hw = hs[0] << 16 | hs[1];
|
||||
for (hs++; hs <= end && hw != nw; )
|
||||
hw = hw << 16 | *++hs;
|
||||
return hw == nw ? (void *)(hs - 1) : NULL;
|
||||
}
|
||||
|
||||
/* Use Two-Way algorithm for very long needles. */
|
||||
if (__builtin_expect (ne_len > 256, 0))
|
||||
return two_way_long_needle (hs, hs_len, ne, ne_len);
|
||||
|
||||
uint8_t shift[256];
|
||||
size_t tmp, shift1;
|
||||
size_t m1 = ne_len - 1;
|
||||
size_t offset = 0;
|
||||
int i;
|
||||
|
||||
/* Initialize bad character shift hash table. */
|
||||
memset (shift, 0, sizeof (shift));
|
||||
for (i = 1; i < m1; i++)
|
||||
shift[hash2 (ne + i)] = i;
|
||||
shift1 = m1 - shift[hash2 (ne + m1)];
|
||||
shift[hash2 (ne + m1)] = m1;
|
||||
|
||||
for ( ; hs <= end; )
|
||||
{
|
||||
/* Skip past character pairs not in the needle. */
|
||||
do
|
||||
{
|
||||
hs += m1;
|
||||
tmp = shift[hash2 (hs)];
|
||||
}
|
||||
while (hs <= end && tmp == 0);
|
||||
|
||||
/* If the match is not at the end of the needle, shift to the end
|
||||
and continue until we match the last 2 characters. */
|
||||
hs -= tmp;
|
||||
if (tmp < m1)
|
||||
continue;
|
||||
|
||||
/* The last 2 characters match. If the needle is long, check a
|
||||
fixed number of characters first to quickly filter out mismatches. */
|
||||
if (m1 <= 15 || memcmp (hs + offset, ne + offset, sizeof (long)) == 0)
|
||||
{
|
||||
if (memcmp (hs, ne, m1) == 0)
|
||||
return (void *) hs;
|
||||
|
||||
/* Adjust filter offset when it doesn't find the mismatch. */
|
||||
offset = (offset >= sizeof (long) ? offset : m1) - sizeof (long);
|
||||
}
|
||||
|
||||
/* Skip based on matching the last 2 characters. */
|
||||
hs += shift1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif /* Compilation for speed. */
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<memmove>>---move possibly overlapping memory
|
||||
|
||||
INDEX
|
||||
memmove
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
void *memmove(void *<[dst]>, const void *<[src]>, size_t <[length]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function moves <[length]> characters from the block of
|
||||
memory starting at <<*<[src]>>> to the memory starting at
|
||||
<<*<[dst]>>>. <<memmove>> reproduces the characters correctly
|
||||
at <<*<[dst]>>> even if the two areas overlap.
|
||||
|
||||
|
||||
RETURNS
|
||||
The function returns <[dst]> as passed.
|
||||
|
||||
PORTABILITY
|
||||
<<memmove>> is ANSI C.
|
||||
|
||||
<<memmove>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
memmove ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <_ansi.h>
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
#include "local.h"
|
||||
|
||||
/* Nonzero if either X or Y is not aligned on a "long" boundary. */
|
||||
#define UNALIGNED(X, Y) \
|
||||
(((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
|
||||
|
||||
/* How many bytes are copied each iteration of the 4X unrolled loop. */
|
||||
#define BIGBLOCKSIZE (sizeof (long) << 2)
|
||||
|
||||
/* How many bytes are copied each iteration of the word copy loop. */
|
||||
#define LITTLEBLOCKSIZE (sizeof (long))
|
||||
|
||||
/* Threshhold for punting to the byte copier. */
|
||||
#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE)
|
||||
|
||||
/*SUPPRESS 20*/
|
||||
void *
|
||||
__inhibit_loop_to_libcall
|
||||
memmove (void *dst_void,
|
||||
const void *src_void,
|
||||
size_t length)
|
||||
{
|
||||
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
|
||||
char *dst = dst_void;
|
||||
const char *src = src_void;
|
||||
|
||||
if (src < dst && dst < src + length)
|
||||
{
|
||||
/* Have to copy backwards */
|
||||
src += length;
|
||||
dst += length;
|
||||
while (length--)
|
||||
{
|
||||
*--dst = *--src;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (length--)
|
||||
{
|
||||
*dst++ = *src++;
|
||||
}
|
||||
}
|
||||
|
||||
return dst_void;
|
||||
#else
|
||||
char *dst = dst_void;
|
||||
const char *src = src_void;
|
||||
long *aligned_dst;
|
||||
const long *aligned_src;
|
||||
|
||||
if (src < dst && dst < src + length)
|
||||
{
|
||||
/* Destructive overlap...have to copy backwards */
|
||||
src += length;
|
||||
dst += length;
|
||||
while (length--)
|
||||
{
|
||||
*--dst = *--src;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Use optimizing algorithm for a non-destructive copy to closely
|
||||
match memcpy. If the size is small or either SRC or DST is unaligned,
|
||||
then punt into the byte copy loop. This should be rare. */
|
||||
if (!TOO_SMALL(length) && !UNALIGNED (src, dst))
|
||||
{
|
||||
aligned_dst = (long*)dst;
|
||||
aligned_src = (long*)src;
|
||||
|
||||
/* Copy 4X long words at a time if possible. */
|
||||
while (length >= BIGBLOCKSIZE)
|
||||
{
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
length -= BIGBLOCKSIZE;
|
||||
}
|
||||
|
||||
/* Copy one long word at a time if possible. */
|
||||
while (length >= LITTLEBLOCKSIZE)
|
||||
{
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
length -= LITTLEBLOCKSIZE;
|
||||
}
|
||||
|
||||
/* Pick up any residual with a byte copier. */
|
||||
dst = (char*)aligned_dst;
|
||||
src = (char*)aligned_src;
|
||||
}
|
||||
|
||||
while (length--)
|
||||
{
|
||||
*dst++ = *src++;
|
||||
}
|
||||
}
|
||||
|
||||
return dst_void;
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<mempcpy>>---copy memory regions and return end pointer
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
void* mempcpy(void *<[out]>, const void *<[in]>, size_t <[n]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function copies <[n]> bytes from the memory region
|
||||
pointed to by <[in]> to the memory region pointed to by
|
||||
<[out]>.
|
||||
|
||||
If the regions overlap, the behavior is undefined.
|
||||
|
||||
RETURNS
|
||||
<<mempcpy>> returns a pointer to the byte following the
|
||||
last byte copied to the <[out]> region.
|
||||
|
||||
PORTABILITY
|
||||
<<mempcpy>> is a GNU extension.
|
||||
|
||||
<<mempcpy>> requires no supporting OS subroutines.
|
||||
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Nonzero if either X or Y is not aligned on a "long" boundary. */
|
||||
#define UNALIGNED(X, Y) \
|
||||
(((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
|
||||
|
||||
/* How many bytes are copied each iteration of the 4X unrolled loop. */
|
||||
#define BIGBLOCKSIZE (sizeof (long) << 2)
|
||||
|
||||
/* How many bytes are copied each iteration of the word copy loop. */
|
||||
#define LITTLEBLOCKSIZE (sizeof (long))
|
||||
|
||||
/* Threshhold for punting to the byte copier. */
|
||||
#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE)
|
||||
|
||||
void *
|
||||
mempcpy (void *dst0,
|
||||
const void *src0,
|
||||
size_t len0)
|
||||
{
|
||||
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
|
||||
char *dst = (char *) dst0;
|
||||
char *src = (char *) src0;
|
||||
|
||||
while (len0--)
|
||||
{
|
||||
*dst++ = *src++;
|
||||
}
|
||||
|
||||
return dst;
|
||||
#else
|
||||
char *dst = dst0;
|
||||
const char *src = src0;
|
||||
long *aligned_dst;
|
||||
const long *aligned_src;
|
||||
|
||||
/* If the size is small, or either SRC or DST is unaligned,
|
||||
then punt into the byte copy loop. This should be rare. */
|
||||
if (!TOO_SMALL(len0) && !UNALIGNED (src, dst))
|
||||
{
|
||||
aligned_dst = (long*)dst;
|
||||
aligned_src = (long*)src;
|
||||
|
||||
/* Copy 4X long words at a time if possible. */
|
||||
while (len0 >= BIGBLOCKSIZE)
|
||||
{
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
len0 -= BIGBLOCKSIZE;
|
||||
}
|
||||
|
||||
/* Copy one long word at a time if possible. */
|
||||
while (len0 >= LITTLEBLOCKSIZE)
|
||||
{
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
len0 -= LITTLEBLOCKSIZE;
|
||||
}
|
||||
|
||||
/* Pick up any residual with a byte copier. */
|
||||
dst = (char*)aligned_dst;
|
||||
src = (char*)aligned_src;
|
||||
}
|
||||
|
||||
while (len0--)
|
||||
*dst++ = *src++;
|
||||
|
||||
return dst;
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<memrchr>>---reverse search for character in memory
|
||||
|
||||
INDEX
|
||||
memrchr
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
void *memrchr(const void *<[src]>, int <[c]>, size_t <[length]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function searches memory starting at <[length]> bytes
|
||||
beyond <<*<[src]>>> backwards for the character <[c]>.
|
||||
The search only ends with the first occurrence of <[c]>; in
|
||||
particular, <<NUL>> does not terminate the search.
|
||||
|
||||
RETURNS
|
||||
If the character <[c]> is found within <[length]> characters
|
||||
of <<*<[src]>>>, a pointer to the character is returned. If
|
||||
<[c]> is not found, then <<NULL>> is returned.
|
||||
|
||||
PORTABILITY
|
||||
<<memrchr>> is a GNU extension.
|
||||
|
||||
<<memrchr>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
memrchr
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
/* Nonzero if X is not aligned on a "long" boundary. */
|
||||
#define UNALIGNED(X) ((long)(X + 1) & (sizeof (long) - 1))
|
||||
|
||||
/* How many bytes are loaded each iteration of the word copy loop. */
|
||||
#define LBLOCKSIZE (sizeof (long))
|
||||
|
||||
/* Threshhold for punting to the bytewise iterator. */
|
||||
#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
|
||||
|
||||
#if LONG_MAX == 2147483647L
|
||||
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
|
||||
#else
|
||||
#if LONG_MAX == 9223372036854775807L
|
||||
/* Nonzero if X (a long int) contains a NULL byte. */
|
||||
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
|
||||
#else
|
||||
#error long int is not a 32bit or 64bit type.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DETECTNULL
|
||||
#error long int is not a 32bit or 64bit byte
|
||||
#endif
|
||||
|
||||
/* DETECTCHAR returns nonzero if (long)X contains the byte used
|
||||
to fill (long)MASK. */
|
||||
#define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK))
|
||||
|
||||
void *
|
||||
memrchr (const void *src_void,
|
||||
int c,
|
||||
size_t length)
|
||||
{
|
||||
const unsigned char *src = (const unsigned char *) src_void + length - 1;
|
||||
unsigned char d = c;
|
||||
|
||||
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
|
||||
unsigned long *asrc;
|
||||
unsigned long mask;
|
||||
unsigned int i;
|
||||
|
||||
while (UNALIGNED (src))
|
||||
{
|
||||
if (!length--)
|
||||
return NULL;
|
||||
if (*src == d)
|
||||
return (void *) src;
|
||||
src--;
|
||||
}
|
||||
|
||||
if (!TOO_SMALL (length))
|
||||
{
|
||||
/* If we get this far, we know that length is large and src is
|
||||
word-aligned. */
|
||||
/* The fast code reads the source one word at a time and only
|
||||
performs the bytewise search on word-sized segments if they
|
||||
contain the search character, which is detected by XORing
|
||||
the word-sized segment with a word-sized block of the search
|
||||
character and then detecting for the presence of NUL in the
|
||||
result. */
|
||||
asrc = (unsigned long *) (src - LBLOCKSIZE + 1);
|
||||
mask = d << 8 | d;
|
||||
mask = mask << 16 | mask;
|
||||
for (i = 32; i < LBLOCKSIZE * 8; i <<= 1)
|
||||
mask = (mask << i) | mask;
|
||||
|
||||
while (length >= LBLOCKSIZE)
|
||||
{
|
||||
if (DETECTCHAR (*asrc, mask))
|
||||
break;
|
||||
length -= LBLOCKSIZE;
|
||||
asrc--;
|
||||
}
|
||||
|
||||
/* If there are fewer than LBLOCKSIZE characters left,
|
||||
then we resort to the bytewise loop. */
|
||||
|
||||
src = (unsigned char *) asrc + LBLOCKSIZE - 1;
|
||||
}
|
||||
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
|
||||
while (length--)
|
||||
{
|
||||
if (*src == d)
|
||||
return (void *) src;
|
||||
src--;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<memset>>---set an area of memory
|
||||
|
||||
INDEX
|
||||
memset
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
void *memset(void *<[dst]>, int <[c]>, size_t <[length]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function converts the argument <[c]> into an unsigned
|
||||
char and fills the first <[length]> characters of the array
|
||||
pointed to by <[dst]> to the value.
|
||||
|
||||
RETURNS
|
||||
<<memset>> returns the value of <[dst]>.
|
||||
|
||||
PORTABILITY
|
||||
<<memset>> is ANSI C.
|
||||
|
||||
<<memset>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
memset ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "local.h"
|
||||
|
||||
#define LBLOCKSIZE (sizeof(long))
|
||||
#define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1))
|
||||
#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
|
||||
|
||||
void *
|
||||
__inhibit_loop_to_libcall
|
||||
memset (void *m,
|
||||
int c,
|
||||
size_t n)
|
||||
{
|
||||
char *s = (char *) m;
|
||||
|
||||
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
|
||||
unsigned int i;
|
||||
unsigned long buffer;
|
||||
unsigned long *aligned_addr;
|
||||
unsigned int d = c & 0xff; /* To avoid sign extension, copy C to an
|
||||
unsigned variable. */
|
||||
|
||||
while (UNALIGNED (s))
|
||||
{
|
||||
if (n--)
|
||||
*s++ = (char) c;
|
||||
else
|
||||
return m;
|
||||
}
|
||||
|
||||
if (!TOO_SMALL (n))
|
||||
{
|
||||
/* If we get this far, we know that n is large and s is word-aligned. */
|
||||
aligned_addr = (unsigned long *) s;
|
||||
|
||||
/* Store D into each char sized location in BUFFER so that
|
||||
we can set large blocks quickly. */
|
||||
buffer = (d << 8) | d;
|
||||
buffer |= (buffer << 16);
|
||||
for (i = 32; i < LBLOCKSIZE * 8; i <<= 1)
|
||||
buffer = (buffer << i) | buffer;
|
||||
|
||||
/* Unroll the loop. */
|
||||
while (n >= LBLOCKSIZE*4)
|
||||
{
|
||||
*aligned_addr++ = buffer;
|
||||
*aligned_addr++ = buffer;
|
||||
*aligned_addr++ = buffer;
|
||||
*aligned_addr++ = buffer;
|
||||
n -= 4*LBLOCKSIZE;
|
||||
}
|
||||
|
||||
while (n >= LBLOCKSIZE)
|
||||
{
|
||||
*aligned_addr++ = buffer;
|
||||
n -= LBLOCKSIZE;
|
||||
}
|
||||
/* Pick up the remainder with a bytewise loop. */
|
||||
s = (char*)aligned_addr;
|
||||
}
|
||||
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
|
||||
while (n--)
|
||||
*s++ = (char) c;
|
||||
|
||||
return m;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
#! /bin/sh
|
||||
|
||||
echo Generating Unicode width data for newlib/libc/string/wcwidth.c
|
||||
|
||||
cd `dirname $0`
|
||||
PATH="$PATH":. # ensure access to uniset tool
|
||||
|
||||
#############################################################################
|
||||
# checks and (with option -u) downloads
|
||||
|
||||
case "$1" in
|
||||
-h) echo "Usage: $0 [-h|-u|-i]"
|
||||
echo "Generate width data tables ambiguous.t, combining.t, wide.t"
|
||||
echo "from local Unicode files UnicodeData.txt, Blocks.txt, EastAsianWidth.txt."
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -u download files from unicode.org first, download uniset tool"
|
||||
echo " -i copy files from /usr/share/unicode/ucd first"
|
||||
echo " -h show this"
|
||||
exit
|
||||
;;
|
||||
-u)
|
||||
wget () {
|
||||
ref=`basename $1`
|
||||
ref=`ls "$ref" 2> /dev/null || echo 01-Jan-1970`
|
||||
curl -R -O --connect-timeout 55 -z "$ref" "$1"
|
||||
}
|
||||
|
||||
echo downloading uniset tool
|
||||
wget https://www.cl.cam.ac.uk/~mgk25/download/uniset.tar.gz
|
||||
gzip -dc uniset.tar.gz | tar xvf - uniset
|
||||
|
||||
echo downloading data from unicode.org
|
||||
for data in UnicodeData.txt Blocks.txt EastAsianWidth.txt
|
||||
do wget http://unicode.org/Public/UNIDATA/$data
|
||||
done
|
||||
;;
|
||||
-i)
|
||||
echo copying data from /usr/share/unicode/ucd
|
||||
for data in UnicodeData.txt Blocks.txt EastAsianWidth.txt
|
||||
do cp /usr/share/unicode/ucd/$data .
|
||||
done
|
||||
;;
|
||||
esac
|
||||
|
||||
echo checking uniset tool
|
||||
type uniset || exit 9
|
||||
|
||||
echo checking Unicode data files
|
||||
for data in UnicodeData.txt Blocks.txt EastAsianWidth.txt
|
||||
do if [ -r $data ]
|
||||
then true
|
||||
else echo $data not available, skipping table generation
|
||||
exit
|
||||
fi
|
||||
done
|
||||
|
||||
echo generating from Unicode version `sed -e 's,[^.0-9],,g' -e 1q Blocks.txt`
|
||||
|
||||
#############################################################################
|
||||
# table generation
|
||||
|
||||
echo generating combining characters table
|
||||
uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B +D7B0-D7C6 +D7CB-D7FB c > combining.t
|
||||
|
||||
echo generating ambiguous width characters table
|
||||
sh ./mkwidthA && uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c > ambiguous.t
|
||||
|
||||
echo generating wide characters table
|
||||
sh ./mkwide
|
||||
|
||||
#############################################################################
|
||||
# end
|
||||
@@ -0,0 +1,49 @@
|
||||
#! /bin/sh
|
||||
|
||||
# generate list of wide characters, with convex closure
|
||||
|
||||
skipcheck=false
|
||||
|
||||
if [ ! -r EastAsianWidth.txt ]
|
||||
then ln -s /usr/share/unicode/ucd/EastAsianWidth.txt . || exit 1
|
||||
fi
|
||||
if [ ! -r UnicodeData.txt ]
|
||||
then ln -s /usr/share/unicode/ucd/UnicodeData.txt . || exit 1
|
||||
fi
|
||||
if [ ! -r Blocks.txt ]
|
||||
then ln -s /usr/share/unicode/ucd/Blocks.txt . || exit 1
|
||||
fi
|
||||
|
||||
sed -e "s,^\([^;]*\);[NAH],\1," -e t -e d EastAsianWidth.txt > wide.na
|
||||
sed -e "s,^\([^;]*\);[WF],\1," -e t -e d EastAsianWidth.txt > wide.fw
|
||||
|
||||
PATH="$PATH:." # for uniset
|
||||
|
||||
nrfw=`uniset +wide.fw nr | sed -e 's,.*:,,'`
|
||||
echo FW $nrfw
|
||||
nrna=`uniset +wide.na nr | sed -e 's,.*:,,'`
|
||||
echo NAH $nrna
|
||||
|
||||
extrablocks="2E80-303E"
|
||||
|
||||
# check all blocks
|
||||
includes () {
|
||||
nr=`uniset +wide.$2 -$1 nr | sed -e 's,.*:,,'`
|
||||
test $nr != $3
|
||||
}
|
||||
echo "adding compact closure of wide ranges, this may take ~10min"
|
||||
for b in $extrablocks `sed -e 's,^\([0-9A-F]*\)\.\.\([0-9A-F]*\).*,\1-\2,' -e t -e d Blocks.txt`
|
||||
do range=$b
|
||||
echo checking $range $* >&2
|
||||
if includes $range fw $nrfw && ! includes $range na $nrna
|
||||
then echo $range
|
||||
fi
|
||||
done > wide.blocks
|
||||
|
||||
(
|
||||
sed -e "s,^,//," -e 1q EastAsianWidth.txt
|
||||
sed -e "s,^,//," -e 1q Blocks.txt
|
||||
uniset `sed -e 's,^,+,' wide.blocks` +wide.fw c
|
||||
) > wide.t
|
||||
|
||||
rm -f wide.na wide.fw wide.blocks
|
||||
@@ -0,0 +1,20 @@
|
||||
#! /bin/sh
|
||||
|
||||
# generate WIDTH-A file, listing Unicode characters with width property
|
||||
# Ambiguous, from EastAsianWidth.txt
|
||||
|
||||
if [ ! -r EastAsianWidth.txt ]
|
||||
then ln -s /usr/share/unicode/ucd/EastAsianWidth.txt . || exit 1
|
||||
fi
|
||||
if [ ! -r UnicodeData.txt ]
|
||||
then ln -s /usr/share/unicode/ucd/UnicodeData.txt . || exit 1
|
||||
fi
|
||||
if [ ! -r Blocks.txt ]
|
||||
then ln -s /usr/share/unicode/ucd/Blocks.txt . || exit 1
|
||||
fi
|
||||
|
||||
sed -e "s,^\([^;]*\);A,\1," -e t -e d EastAsianWidth.txt > width-a-new
|
||||
rm -f WIDTH-A
|
||||
echo "# UAX #11: East Asian Ambiguous" > WIDTH-A
|
||||
PATH="$PATH:." uniset +width-a-new compact >> WIDTH-A
|
||||
rm -f width-a-new
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<rawmemchr>>---find character in memory
|
||||
|
||||
INDEX
|
||||
rawmemchr
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
void *rawmemchr(const void *<[src]>, int <[c]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function searches memory starting at <<*<[src]>>> for the
|
||||
character <[c]>. The search only ends with the first occurrence
|
||||
of <[c]>; in particular, <<NUL>> does not terminate the search.
|
||||
No bounds checking is performed, so this function should only
|
||||
be used when it is certain that the character <[c]> will be found.
|
||||
|
||||
RETURNS
|
||||
A pointer to the first occurance of character <[c]>.
|
||||
|
||||
PORTABILITY
|
||||
<<rawmemchr>> is a GNU extension.
|
||||
|
||||
<<rawmemchr>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
rawmemchr
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
/* Nonzero if X is not aligned on a "long" boundary. */
|
||||
#define UNALIGNED(X) ((long)X & (sizeof (long) - 1))
|
||||
|
||||
/* How many bytes are loaded each iteration of the word copy loop. */
|
||||
#define LBLOCKSIZE (sizeof (long))
|
||||
|
||||
/* Threshhold for punting to the bytewise iterator. */
|
||||
#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
|
||||
|
||||
#if LONG_MAX == 2147483647L
|
||||
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
|
||||
#else
|
||||
#if LONG_MAX == 9223372036854775807L
|
||||
/* Nonzero if X (a long int) contains a NULL byte. */
|
||||
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
|
||||
#else
|
||||
#error long int is not a 32bit or 64bit type.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DETECTNULL
|
||||
#error long int is not a 32bit or 64bit byte
|
||||
#endif
|
||||
|
||||
/* DETECTCHAR returns nonzero if (long)X contains the byte used
|
||||
to fill (long)MASK. */
|
||||
#define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK))
|
||||
|
||||
void *
|
||||
rawmemchr (const void *src_void,
|
||||
int c)
|
||||
{
|
||||
const unsigned char *src = (const unsigned char *) src_void;
|
||||
unsigned char d = c;
|
||||
|
||||
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
|
||||
unsigned long *asrc;
|
||||
unsigned long mask;
|
||||
unsigned int i;
|
||||
|
||||
while (UNALIGNED (src))
|
||||
{
|
||||
if (*src == d)
|
||||
return (void *) src;
|
||||
src++;
|
||||
}
|
||||
|
||||
/* If we get this far, we know that src is word-aligned. */
|
||||
/* The fast code reads the source one word at a time and only
|
||||
performs the bytewise search on word-sized segments if they
|
||||
contain the search character, which is detected by XORing
|
||||
the word-sized segment with a word-sized block of the search
|
||||
character and then detecting for the presence of NUL in the
|
||||
result. */
|
||||
asrc = (unsigned long *) src;
|
||||
mask = d << 8 | d;
|
||||
mask = mask << 16 | mask;
|
||||
for (i = 32; i < LBLOCKSIZE * 8; i <<= 1)
|
||||
mask = (mask << i) | mask;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (DETECTCHAR (*asrc, mask))
|
||||
break;
|
||||
asrc++;
|
||||
}
|
||||
|
||||
/* We have the matching word, now we resort to a bytewise loop. */
|
||||
|
||||
src = (unsigned char *) asrc;
|
||||
|
||||
#endif /* !PREFER_SIZE_OVER_SPEED && !__OPTIMIZE_SIZE__ */
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (*src == d)
|
||||
return (void *) src;
|
||||
src++;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<rindex>>---reverse search for character in string
|
||||
|
||||
INDEX
|
||||
rindex
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
char * rindex(const char *<[string]>, int <[c]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function finds the last occurence of <[c]> (converted to
|
||||
a char) in the string pointed to by <[string]> (including the
|
||||
terminating null character).
|
||||
|
||||
This function is identical to <<strrchr>>.
|
||||
|
||||
RETURNS
|
||||
Returns a pointer to the located character, or a null pointer
|
||||
if <[c]> does not occur in <[string]>.
|
||||
|
||||
PORTABILITY
|
||||
<<rindex>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
rindex - pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
char *
|
||||
rindex (const char *s,
|
||||
int c)
|
||||
{
|
||||
return strrchr (s, c);
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<stpcpy>>---copy string returning a pointer to its end
|
||||
|
||||
INDEX
|
||||
stpcpy
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
char *stpcpy(char *restrict <[dst]>, const char *restrict <[src]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<stpcpy>> copies the string pointed to by <[src]>
|
||||
(including the terminating null character) to the array
|
||||
pointed to by <[dst]>.
|
||||
|
||||
RETURNS
|
||||
This function returns a pointer to the end of the destination string,
|
||||
thus pointing to the trailing '\0'.
|
||||
|
||||
PORTABILITY
|
||||
<<stpcpy>> is a GNU extension, candidate for inclusion into POSIX/SUSv4.
|
||||
|
||||
<<stpcpy>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
stpcpy gnu
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
/*SUPPRESS 560*/
|
||||
/*SUPPRESS 530*/
|
||||
|
||||
/* Nonzero if either X or Y is not aligned on a "long" boundary. */
|
||||
#define UNALIGNED(X, Y) \
|
||||
(((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
|
||||
|
||||
#if LONG_MAX == 2147483647L
|
||||
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
|
||||
#else
|
||||
#if LONG_MAX == 9223372036854775807L
|
||||
/* Nonzero if X (a long int) contains a NULL byte. */
|
||||
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
|
||||
#else
|
||||
#error long int is not a 32bit or 64bit type.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DETECTNULL
|
||||
#error long int is not a 32bit or 64bit byte
|
||||
#endif
|
||||
|
||||
char*
|
||||
stpcpy (char *__restrict dst,
|
||||
const char *__restrict src)
|
||||
{
|
||||
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
|
||||
long *aligned_dst;
|
||||
const long *aligned_src;
|
||||
|
||||
/* If SRC or DEST is unaligned, then copy bytes. */
|
||||
if (!UNALIGNED (src, dst))
|
||||
{
|
||||
aligned_dst = (long*)dst;
|
||||
aligned_src = (long*)src;
|
||||
|
||||
/* SRC and DEST are both "long int" aligned, try to do "long int"
|
||||
sized copies. */
|
||||
while (!DETECTNULL(*aligned_src))
|
||||
{
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
}
|
||||
|
||||
dst = (char*)aligned_dst;
|
||||
src = (char*)aligned_src;
|
||||
}
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
|
||||
while ((*dst++ = *src++))
|
||||
;
|
||||
return --dst;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<stpncpy>>---counted copy string returning a pointer to its end
|
||||
|
||||
INDEX
|
||||
stpncpy
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
char *stpncpy(char *restrict <[dst]>, const char *restrict <[src]>,
|
||||
size_t <[length]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<stpncpy>> copies not more than <[length]> characters from the
|
||||
the string pointed to by <[src]> (including the terminating
|
||||
null character) to the array pointed to by <[dst]>. If the
|
||||
string pointed to by <[src]> is shorter than <[length]>
|
||||
characters, null characters are appended to the destination
|
||||
array until a total of <[length]> characters have been
|
||||
written.
|
||||
|
||||
RETURNS
|
||||
This function returns a pointer to the end of the destination string,
|
||||
thus pointing to the trailing '\0', or, if the destination string is
|
||||
not null-terminated, pointing to dst + n.
|
||||
|
||||
PORTABILITY
|
||||
<<stpncpy>> is a GNU extension, candidate for inclusion into POSIX/SUSv4.
|
||||
|
||||
<<stpncpy>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
stpncpy gnu
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
/*SUPPRESS 560*/
|
||||
/*SUPPRESS 530*/
|
||||
|
||||
/* Nonzero if either X or Y is not aligned on a "long" boundary. */
|
||||
#define UNALIGNED(X, Y) \
|
||||
(((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
|
||||
|
||||
#if LONG_MAX == 2147483647L
|
||||
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
|
||||
#else
|
||||
#if LONG_MAX == 9223372036854775807L
|
||||
/* Nonzero if X (a long int) contains a NULL byte. */
|
||||
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
|
||||
#else
|
||||
#error long int is not a 32bit or 64bit type.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DETECTNULL
|
||||
#error long int is not a 32bit or 64bit byte
|
||||
#endif
|
||||
|
||||
#define TOO_SMALL(LEN) ((LEN) < sizeof (long))
|
||||
|
||||
char *
|
||||
stpncpy (char *__restrict dst,
|
||||
const char *__restrict src,
|
||||
size_t count)
|
||||
{
|
||||
char *ret = NULL;
|
||||
|
||||
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
|
||||
long *aligned_dst;
|
||||
const long *aligned_src;
|
||||
|
||||
/* If SRC and DEST is aligned and count large enough, then copy words. */
|
||||
if (!UNALIGNED (src, dst) && !TOO_SMALL (count))
|
||||
{
|
||||
aligned_dst = (long*)dst;
|
||||
aligned_src = (long*)src;
|
||||
|
||||
/* SRC and DEST are both "long int" aligned, try to do "long int"
|
||||
sized copies. */
|
||||
while (count >= sizeof (long int) && !DETECTNULL(*aligned_src))
|
||||
{
|
||||
count -= sizeof (long int);
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
}
|
||||
|
||||
dst = (char*)aligned_dst;
|
||||
src = (char*)aligned_src;
|
||||
}
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
--count;
|
||||
if ((*dst++ = *src++) == '\0')
|
||||
{
|
||||
ret = dst - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (count-- > 0)
|
||||
*dst++ = '\0';
|
||||
|
||||
return ret ? ret : dst;
|
||||
}
|
||||
@@ -0,0 +1,416 @@
|
||||
/* Byte-wise substring search, using the Two-Way algorithm.
|
||||
* Copyright (C) 2008, 2010 Eric Blake
|
||||
* Permission to use, copy, modify, and distribute this software
|
||||
* is freely granted, provided that this notice is preserved.
|
||||
*/
|
||||
|
||||
|
||||
/* Before including this file, you need to include <string.h>, and define:
|
||||
RESULT_TYPE A macro that expands to the return type.
|
||||
AVAILABLE(h, h_l, j, n_l) A macro that returns nonzero if there are
|
||||
at least N_L bytes left starting at
|
||||
H[J]. H is 'unsigned char *', H_L, J,
|
||||
and N_L are 'size_t'; H_L is an
|
||||
lvalue. For NUL-terminated searches,
|
||||
H_L can be modified each iteration to
|
||||
avoid having to compute the end of H
|
||||
up front.
|
||||
|
||||
For case-insensitivity, you may optionally define:
|
||||
CMP_FUNC(p1, p2, l) A macro that returns 0 iff the first L
|
||||
characters of P1 and P2 are equal.
|
||||
CANON_ELEMENT(c) A macro that canonicalizes an element
|
||||
right after it has been fetched from
|
||||
one of the two strings. The argument
|
||||
is an 'unsigned char'; the result must
|
||||
be an 'unsigned char' as well.
|
||||
|
||||
This file undefines the macros documented above, and defines
|
||||
LONG_NEEDLE_THRESHOLD.
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <_ansi.h>
|
||||
|
||||
/* We use the Two-Way string matching algorithm, which guarantees
|
||||
linear complexity with constant space. Additionally, for long
|
||||
needles, we also use a bad character shift table similar to the
|
||||
Boyer-Moore algorithm to achieve improved (potentially sub-linear)
|
||||
performance.
|
||||
|
||||
See http://www-igm.univ-mlv.fr/~lecroq/string/node26.html#SECTION00260
|
||||
and http://en.wikipedia.org/wiki/Boyer-Moore_string_search_algorithm
|
||||
*/
|
||||
|
||||
/* Point at which computing a bad-byte shift table is likely to be
|
||||
worthwhile. Small needles should not compute a table, since it
|
||||
adds (1 << CHAR_BIT) + NEEDLE_LEN computations of preparation for a
|
||||
speedup no greater than a factor of NEEDLE_LEN. The larger the
|
||||
needle, the better the potential performance gain. On the other
|
||||
hand, on non-POSIX systems with CHAR_BIT larger than eight, the
|
||||
memory required for the table is prohibitive. */
|
||||
#if CHAR_BIT < 10
|
||||
# define LONG_NEEDLE_THRESHOLD 32U
|
||||
#else
|
||||
# define LONG_NEEDLE_THRESHOLD SIZE_MAX
|
||||
#endif
|
||||
|
||||
#define MAX(a, b) ((a < b) ? (b) : (a))
|
||||
|
||||
#ifndef CANON_ELEMENT
|
||||
# define CANON_ELEMENT(c) c
|
||||
#endif
|
||||
#ifndef CMP_FUNC
|
||||
# define CMP_FUNC memcmp
|
||||
#endif
|
||||
|
||||
/* Perform a critical factorization of NEEDLE, of length NEEDLE_LEN.
|
||||
Return the index of the first byte in the right half, and set
|
||||
*PERIOD to the global period of the right half.
|
||||
|
||||
The global period of a string is the smallest index (possibly its
|
||||
length) at which all remaining bytes in the string are repetitions
|
||||
of the prefix (the last repetition may be a subset of the prefix).
|
||||
|
||||
When NEEDLE is factored into two halves, a local period is the
|
||||
length of the smallest word that shares a suffix with the left half
|
||||
and shares a prefix with the right half. All factorizations of a
|
||||
non-empty NEEDLE have a local period of at least 1 and no greater
|
||||
than NEEDLE_LEN.
|
||||
|
||||
A critical factorization has the property that the local period
|
||||
equals the global period. All strings have at least one critical
|
||||
factorization with the left half smaller than the global period.
|
||||
|
||||
Given an ordered alphabet, a critical factorization can be computed
|
||||
in linear time, with 2 * NEEDLE_LEN comparisons, by computing the
|
||||
larger of two ordered maximal suffixes. The ordered maximal
|
||||
suffixes are determined by lexicographic comparison of
|
||||
periodicity. */
|
||||
static size_t
|
||||
critical_factorization (const unsigned char *needle, size_t needle_len,
|
||||
size_t *period)
|
||||
{
|
||||
/* Index of last byte of left half, or SIZE_MAX. */
|
||||
size_t max_suffix, max_suffix_rev;
|
||||
size_t j; /* Index into NEEDLE for current candidate suffix. */
|
||||
size_t k; /* Offset into current period. */
|
||||
size_t p; /* Intermediate period. */
|
||||
unsigned char a, b; /* Current comparison bytes. */
|
||||
|
||||
/* Invariants:
|
||||
0 <= j < NEEDLE_LEN - 1
|
||||
-1 <= max_suffix{,_rev} < j (treating SIZE_MAX as if it were signed)
|
||||
min(max_suffix, max_suffix_rev) < global period of NEEDLE
|
||||
1 <= p <= global period of NEEDLE
|
||||
p == global period of the substring NEEDLE[max_suffix{,_rev}+1...j]
|
||||
1 <= k <= p
|
||||
*/
|
||||
|
||||
/* Perform lexicographic search. */
|
||||
max_suffix = SIZE_MAX;
|
||||
j = 0;
|
||||
k = p = 1;
|
||||
while (j + k < needle_len)
|
||||
{
|
||||
a = CANON_ELEMENT (needle[j + k]);
|
||||
b = CANON_ELEMENT (needle[(size_t)(max_suffix + k)]);
|
||||
if (a < b)
|
||||
{
|
||||
/* Suffix is smaller, period is entire prefix so far. */
|
||||
j += k;
|
||||
k = 1;
|
||||
p = j - max_suffix;
|
||||
}
|
||||
else if (a == b)
|
||||
{
|
||||
/* Advance through repetition of the current period. */
|
||||
if (k != p)
|
||||
++k;
|
||||
else
|
||||
{
|
||||
j += p;
|
||||
k = 1;
|
||||
}
|
||||
}
|
||||
else /* b < a */
|
||||
{
|
||||
/* Suffix is larger, start over from current location. */
|
||||
max_suffix = j++;
|
||||
k = p = 1;
|
||||
}
|
||||
}
|
||||
*period = p;
|
||||
|
||||
/* Perform reverse lexicographic search. */
|
||||
max_suffix_rev = SIZE_MAX;
|
||||
j = 0;
|
||||
k = p = 1;
|
||||
while (j + k < needle_len)
|
||||
{
|
||||
a = CANON_ELEMENT (needle[j + k]);
|
||||
b = CANON_ELEMENT (needle[max_suffix_rev + k]);
|
||||
if (b < a)
|
||||
{
|
||||
/* Suffix is smaller, period is entire prefix so far. */
|
||||
j += k;
|
||||
k = 1;
|
||||
p = j - max_suffix_rev;
|
||||
}
|
||||
else if (a == b)
|
||||
{
|
||||
/* Advance through repetition of the current period. */
|
||||
if (k != p)
|
||||
++k;
|
||||
else
|
||||
{
|
||||
j += p;
|
||||
k = 1;
|
||||
}
|
||||
}
|
||||
else /* a < b */
|
||||
{
|
||||
/* Suffix is larger, start over from current location. */
|
||||
max_suffix_rev = j++;
|
||||
k = p = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Choose the longer suffix. Return the first byte of the right
|
||||
half, rather than the last byte of the left half. */
|
||||
if (max_suffix_rev + 1 < max_suffix + 1)
|
||||
return max_suffix + 1;
|
||||
*period = p;
|
||||
return max_suffix_rev + 1;
|
||||
}
|
||||
|
||||
/* Return the first location of non-empty NEEDLE within HAYSTACK, or
|
||||
NULL. HAYSTACK_LEN is the minimum known length of HAYSTACK. This
|
||||
method is optimized for NEEDLE_LEN < LONG_NEEDLE_THRESHOLD.
|
||||
Performance is guaranteed to be linear, with an initialization cost
|
||||
of 2 * NEEDLE_LEN comparisons.
|
||||
|
||||
If AVAILABLE does not modify HAYSTACK_LEN (as in memmem), then at
|
||||
most 2 * HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching.
|
||||
If AVAILABLE modifies HAYSTACK_LEN (as in strstr), then at most 3 *
|
||||
HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching. */
|
||||
static RETURN_TYPE __attribute__ ((__used__))
|
||||
two_way_short_needle (const unsigned char *haystack, size_t haystack_len,
|
||||
const unsigned char *needle, size_t needle_len)
|
||||
{
|
||||
size_t i; /* Index into current byte of NEEDLE. */
|
||||
size_t j; /* Index into current window of HAYSTACK. */
|
||||
size_t period; /* The period of the right half of needle. */
|
||||
size_t suffix; /* The index of the right half of needle. */
|
||||
|
||||
/* Factor the needle into two halves, such that the left half is
|
||||
smaller than the global period, and the right half is
|
||||
periodic (with a period as large as NEEDLE_LEN - suffix). */
|
||||
suffix = critical_factorization (needle, needle_len, &period);
|
||||
|
||||
/* Perform the search. Each iteration compares the right half
|
||||
first. */
|
||||
if (CMP_FUNC (needle, needle + period, suffix) == 0)
|
||||
{
|
||||
/* Entire needle is periodic; a mismatch can only advance by the
|
||||
period, so use memory to avoid rescanning known occurrences
|
||||
of the period. */
|
||||
size_t memory = 0;
|
||||
j = 0;
|
||||
while (AVAILABLE (haystack, haystack_len, j, needle_len))
|
||||
{
|
||||
/* Scan for matches in right half. */
|
||||
i = MAX (suffix, memory);
|
||||
while (i < needle_len && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
++i;
|
||||
if (needle_len <= i)
|
||||
{
|
||||
/* Scan for matches in left half. */
|
||||
i = suffix - 1;
|
||||
while (memory < i + 1 && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
--i;
|
||||
if (i + 1 < memory + 1)
|
||||
return (RETURN_TYPE) (haystack + j);
|
||||
/* No match, so remember how many repetitions of period
|
||||
on the right half were scanned. */
|
||||
j += period;
|
||||
memory = needle_len - period;
|
||||
}
|
||||
else
|
||||
{
|
||||
j += i - suffix + 1;
|
||||
memory = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The two halves of needle are distinct; no extra memory is
|
||||
required, and any mismatch results in a maximal shift. */
|
||||
period = MAX (suffix, needle_len - suffix) + 1;
|
||||
j = 0;
|
||||
while (AVAILABLE (haystack, haystack_len, j, needle_len))
|
||||
{
|
||||
/* Scan for matches in right half. */
|
||||
i = suffix;
|
||||
while (i < needle_len && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
++i;
|
||||
if (needle_len <= i)
|
||||
{
|
||||
/* Scan for matches in left half. */
|
||||
i = suffix - 1;
|
||||
while (i != SIZE_MAX && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
--i;
|
||||
if (i == SIZE_MAX)
|
||||
return (RETURN_TYPE) (haystack + j);
|
||||
j += period;
|
||||
}
|
||||
else
|
||||
j += i - suffix + 1;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Return the first location of non-empty NEEDLE within HAYSTACK, or
|
||||
NULL. HAYSTACK_LEN is the minimum known length of HAYSTACK. This
|
||||
method is optimized for LONG_NEEDLE_THRESHOLD <= NEEDLE_LEN.
|
||||
Performance is guaranteed to be linear, with an initialization cost
|
||||
of 3 * NEEDLE_LEN + (1 << CHAR_BIT) operations.
|
||||
|
||||
If AVAILABLE does not modify HAYSTACK_LEN (as in memmem), then at
|
||||
most 2 * HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching,
|
||||
and sublinear performance O(HAYSTACK_LEN / NEEDLE_LEN) is possible.
|
||||
If AVAILABLE modifies HAYSTACK_LEN (as in strstr), then at most 3 *
|
||||
HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching, and
|
||||
sublinear performance is not possible. */
|
||||
_NOINLINE_STATIC RETURN_TYPE __attribute__ ((__used__))
|
||||
two_way_long_needle (const unsigned char *haystack, size_t haystack_len,
|
||||
const unsigned char *needle, size_t needle_len)
|
||||
{
|
||||
size_t i; /* Index into current byte of NEEDLE. */
|
||||
size_t j; /* Index into current window of HAYSTACK. */
|
||||
size_t period; /* The period of the right half of needle. */
|
||||
size_t suffix; /* The index of the right half of needle. */
|
||||
size_t shift_table[1U << CHAR_BIT]; /* See below. */
|
||||
|
||||
/* Factor the needle into two halves, such that the left half is
|
||||
smaller than the global period, and the right half is
|
||||
periodic (with a period as large as NEEDLE_LEN - suffix). */
|
||||
suffix = critical_factorization (needle, needle_len, &period);
|
||||
|
||||
/* Populate shift_table. For each possible byte value c,
|
||||
shift_table[c] is the distance from the last occurrence of c to
|
||||
the end of NEEDLE, or NEEDLE_LEN if c is absent from the NEEDLE.
|
||||
shift_table[NEEDLE[NEEDLE_LEN - 1]] contains the only 0. */
|
||||
for (i = 0; i < 1U << CHAR_BIT; i++)
|
||||
shift_table[i] = needle_len;
|
||||
for (i = 0; i < needle_len; i++)
|
||||
shift_table[CANON_ELEMENT (needle[i])] = needle_len - i - 1;
|
||||
|
||||
/* Perform the search. Each iteration compares the right half
|
||||
first. */
|
||||
if (CMP_FUNC (needle, needle + period, suffix) == 0)
|
||||
{
|
||||
/* Entire needle is periodic; a mismatch can only advance by the
|
||||
period, so use memory to avoid rescanning known occurrences
|
||||
of the period. */
|
||||
size_t memory = 0;
|
||||
size_t shift;
|
||||
j = 0;
|
||||
while (AVAILABLE (haystack, haystack_len, j, needle_len))
|
||||
{
|
||||
/* Check the last byte first; if it does not match, then
|
||||
shift to the next possible match location. */
|
||||
shift = shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])];
|
||||
if (0 < shift)
|
||||
{
|
||||
if (memory && shift < period)
|
||||
{
|
||||
/* Since needle is periodic, but the last period has
|
||||
a byte out of place, there can be no match until
|
||||
after the mismatch. */
|
||||
shift = needle_len - period;
|
||||
}
|
||||
memory = 0;
|
||||
j += shift;
|
||||
continue;
|
||||
}
|
||||
/* Scan for matches in right half. The last byte has
|
||||
already been matched, by virtue of the shift table. */
|
||||
i = MAX (suffix, memory);
|
||||
while (i < needle_len - 1 && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
++i;
|
||||
if (needle_len - 1 <= i)
|
||||
{
|
||||
/* Scan for matches in left half. */
|
||||
i = suffix - 1;
|
||||
while (memory < i + 1 && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
--i;
|
||||
if (i + 1 < memory + 1)
|
||||
return (RETURN_TYPE) (haystack + j);
|
||||
/* No match, so remember how many repetitions of period
|
||||
on the right half were scanned. */
|
||||
j += period;
|
||||
memory = needle_len - period;
|
||||
}
|
||||
else
|
||||
{
|
||||
j += i - suffix + 1;
|
||||
memory = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The two halves of needle are distinct; no extra memory is
|
||||
required, and any mismatch results in a maximal shift. */
|
||||
size_t shift;
|
||||
period = MAX (suffix, needle_len - suffix) + 1;
|
||||
j = 0;
|
||||
while (AVAILABLE (haystack, haystack_len, j, needle_len))
|
||||
{
|
||||
/* Check the last byte first; if it does not match, then
|
||||
shift to the next possible match location. */
|
||||
shift = shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])];
|
||||
if (0 < shift)
|
||||
{
|
||||
j += shift;
|
||||
continue;
|
||||
}
|
||||
/* Scan for matches in right half. The last byte has
|
||||
already been matched, by virtue of the shift table. */
|
||||
i = suffix;
|
||||
while (i < needle_len - 1 && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
++i;
|
||||
if (needle_len - 1 <= i)
|
||||
{
|
||||
/* Scan for matches in left half. */
|
||||
i = suffix - 1;
|
||||
while (i != SIZE_MAX && (CANON_ELEMENT (needle[i])
|
||||
== CANON_ELEMENT (haystack[i + j])))
|
||||
--i;
|
||||
if (i == SIZE_MAX)
|
||||
return (RETURN_TYPE) (haystack + j);
|
||||
j += period;
|
||||
}
|
||||
else
|
||||
j += i - suffix + 1;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#undef AVAILABLE
|
||||
#undef CANON_ELEMENT
|
||||
#undef CMP_FUNC
|
||||
#undef MAX
|
||||
#undef RETURN_TYPE
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strcasecmp>>---case-insensitive character string compare
|
||||
|
||||
INDEX
|
||||
strcasecmp
|
||||
|
||||
SYNOPSIS
|
||||
#include <strings.h>
|
||||
int strcasecmp(const char *<[a]>, const char *<[b]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<strcasecmp>> compares the string at <[a]> to
|
||||
the string at <[b]> in a case-insensitive manner.
|
||||
|
||||
RETURNS
|
||||
|
||||
If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after
|
||||
both are converted to lowercase), <<strcasecmp>> returns a
|
||||
number greater than zero. If the two strings match,
|
||||
<<strcasecmp>> returns zero. If <<*<[a]>>> sorts
|
||||
lexicographically before <<*<[b]>>>, <<strcasecmp>> returns a
|
||||
number less than zero.
|
||||
|
||||
PORTABILITY
|
||||
<<strcasecmp>> is in the Berkeley Software Distribution.
|
||||
|
||||
<<strcasecmp>> requires no supporting OS subroutines. It uses
|
||||
tolower() from elsewhere in this library.
|
||||
|
||||
QUICKREF
|
||||
strcasecmp
|
||||
*/
|
||||
|
||||
#include <strings.h>
|
||||
#include <ctype.h>
|
||||
|
||||
int
|
||||
strcasecmp (const char *s1,
|
||||
const char *s2)
|
||||
{
|
||||
int d = 0;
|
||||
for ( ; ; )
|
||||
{
|
||||
const int c1 = tolower(*s1++);
|
||||
const int c2 = tolower(*s2++);
|
||||
if (((d = c1 - c2) != 0) || (c2 == '\0'))
|
||||
break;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strcasecmp_l>>---case-insensitive character string compare
|
||||
|
||||
INDEX
|
||||
strcasecmp_l
|
||||
|
||||
SYNOPSIS
|
||||
#include <strings.h>
|
||||
int strcasecmp_l(const char *<[a]>, const char *<[b]>,
|
||||
locale_t <[locale]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<strcasecmp_l>> compares the string at <[a]> to
|
||||
the string at <[b]> in a case-insensitive manner.
|
||||
|
||||
if <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the
|
||||
behaviour is undefined.
|
||||
|
||||
RETURNS
|
||||
|
||||
If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after
|
||||
both are converted to lowercase), <<strcasecmp_l>> returns a
|
||||
number greater than zero. If the two strings match,
|
||||
<<strcasecmp_l>> returns zero. If <<*<[a]>>> sorts
|
||||
lexicographically before <<*<[b]>>>, <<strcasecmp_l>> returns a
|
||||
number less than zero.
|
||||
|
||||
PORTABILITY
|
||||
<<strcasecmp_l>> is POSIX-1.2008.
|
||||
|
||||
<<strcasecmp_l>> requires no supporting OS subroutines. It uses
|
||||
tolower_l() from elsewhere in this library.
|
||||
|
||||
QUICKREF
|
||||
strcasecmp_l
|
||||
*/
|
||||
|
||||
#include <strings.h>
|
||||
#include <ctype.h>
|
||||
|
||||
int
|
||||
strcasecmp_l (const char *s1, const char *s2, struct __locale_t *locale)
|
||||
{
|
||||
int d = 0;
|
||||
for ( ; ; )
|
||||
{
|
||||
const int c1 = tolower_l (*s1++, locale);
|
||||
const int c2 = tolower_l (*s2++, locale);
|
||||
if (((d = c1 - c2) != 0) || (c2 == '\0'))
|
||||
break;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strcasestr>>---case-insensitive character string search
|
||||
|
||||
INDEX
|
||||
strcasestr
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strcasestr(const char *<[s]>, const char *<[find]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<strcasestr>> searchs the string <[s]> for
|
||||
the first occurrence of the sequence <[find]>. <<strcasestr>>
|
||||
is identical to <<strstr>> except the search is
|
||||
case-insensitive.
|
||||
|
||||
RETURNS
|
||||
|
||||
A pointer to the first case-insensitive occurrence of the sequence
|
||||
<[find]> or <<NULL>> if no match was found.
|
||||
|
||||
PORTABILITY
|
||||
<<strcasestr>> is in the Berkeley Software Distribution.
|
||||
|
||||
<<strcasestr>> requires no supporting OS subroutines. It uses
|
||||
tolower() from elsewhere in this library.
|
||||
|
||||
QUICKREF
|
||||
strcasestr
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* The quadratic code is derived from software contributed to Berkeley by
|
||||
* Chris Torek.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
/* Linear algorithm Copyright (C) 2008 Eric Blake
|
||||
* Permission to use, copy, modify, and distribute the linear portion of
|
||||
* software is freely granted, provided that this notice is preserved.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
|
||||
# define RETURN_TYPE char *
|
||||
# define AVAILABLE(h, h_l, j, n_l) \
|
||||
(!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \
|
||||
&& ((h_l) = (j) + (n_l)))
|
||||
# define CANON_ELEMENT(c) tolower (c)
|
||||
#if __GNUC_PREREQ (4, 2)
|
||||
/* strncasecmp uses signed char, CMP_FUNC is expected to use unsigned char. */
|
||||
#pragma GCC diagnostic ignored "-Wpointer-sign"
|
||||
#endif
|
||||
# define CMP_FUNC strncasecmp
|
||||
# include "str-two-way.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Find the first occurrence of find in s, ignore case.
|
||||
*/
|
||||
char *
|
||||
strcasestr (const char *s,
|
||||
const char *find)
|
||||
{
|
||||
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
|
||||
|
||||
/* Less code size, but quadratic performance in the worst case. */
|
||||
char c, sc;
|
||||
size_t len;
|
||||
|
||||
if ((c = *find++) != 0) {
|
||||
c = tolower((unsigned char)c);
|
||||
len = strlen(find);
|
||||
do {
|
||||
do {
|
||||
if ((sc = *s++) == 0)
|
||||
return (NULL);
|
||||
} while ((char)tolower((unsigned char)sc) != c);
|
||||
} while (strncasecmp(s, find, len) != 0);
|
||||
s--;
|
||||
}
|
||||
return ((char *)s);
|
||||
|
||||
#else /* compilation for speed */
|
||||
|
||||
/* Larger code size, but guaranteed linear performance. */
|
||||
const char *haystack = s;
|
||||
const char *needle = find;
|
||||
size_t needle_len; /* Length of NEEDLE. */
|
||||
size_t haystack_len; /* Known minimum length of HAYSTACK. */
|
||||
int ok = 1; /* True if NEEDLE is prefix of HAYSTACK. */
|
||||
|
||||
/* Determine length of NEEDLE, and in the process, make sure
|
||||
HAYSTACK is at least as long (no point processing all of a long
|
||||
NEEDLE if HAYSTACK is too short). */
|
||||
while (*haystack && *needle)
|
||||
ok &= (tolower ((unsigned char) *haystack++)
|
||||
== tolower ((unsigned char) *needle++));
|
||||
if (*needle)
|
||||
return NULL;
|
||||
if (ok)
|
||||
return (char *) s;
|
||||
needle_len = needle - find;
|
||||
haystack = s + 1;
|
||||
haystack_len = needle_len - 1;
|
||||
|
||||
/* Perform the search. */
|
||||
if (needle_len < LONG_NEEDLE_THRESHOLD)
|
||||
return two_way_short_needle ((const unsigned char *) haystack,
|
||||
haystack_len,
|
||||
(const unsigned char *) find, needle_len);
|
||||
return two_way_long_needle ((const unsigned char *) haystack, haystack_len,
|
||||
(const unsigned char *) find, needle_len);
|
||||
#endif /* compilation for speed */
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strcat>>---concatenate strings
|
||||
|
||||
INDEX
|
||||
strcat
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strcat(char *restrict <[dst]>, const char *restrict <[src]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<strcat>> appends a copy of the string pointed to by <[src]>
|
||||
(including the terminating null character) to the end of the
|
||||
string pointed to by <[dst]>. The initial character of
|
||||
<[src]> overwrites the null character at the end of <[dst]>.
|
||||
|
||||
RETURNS
|
||||
This function returns the initial value of <[dst]>
|
||||
|
||||
PORTABILITY
|
||||
<<strcat>> is ANSI C.
|
||||
|
||||
<<strcat>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strcat ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
/* Nonzero if X is aligned on a "long" boundary. */
|
||||
#define ALIGNED(X) \
|
||||
(((long)X & (sizeof (long) - 1)) == 0)
|
||||
|
||||
#if LONG_MAX == 2147483647L
|
||||
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
|
||||
#else
|
||||
#if LONG_MAX == 9223372036854775807L
|
||||
/* Nonzero if X (a long int) contains a NULL byte. */
|
||||
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
|
||||
#else
|
||||
#error long int is not a 32bit or 64bit type.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DETECTNULL
|
||||
#error long int is not a 32bit or 64bit byte
|
||||
#endif
|
||||
|
||||
|
||||
/*SUPPRESS 560*/
|
||||
/*SUPPRESS 530*/
|
||||
|
||||
char *
|
||||
strcat (char *__restrict s1,
|
||||
const char *__restrict s2)
|
||||
{
|
||||
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
|
||||
char *s = s1;
|
||||
|
||||
while (*s1)
|
||||
s1++;
|
||||
|
||||
while (*s1++ = *s2++)
|
||||
;
|
||||
return s;
|
||||
#else
|
||||
char *s = s1;
|
||||
|
||||
|
||||
/* Skip over the data in s1 as quickly as possible. */
|
||||
if (ALIGNED (s1))
|
||||
{
|
||||
unsigned long *aligned_s1 = (unsigned long *)s1;
|
||||
while (!DETECTNULL (*aligned_s1))
|
||||
aligned_s1++;
|
||||
|
||||
s1 = (char *)aligned_s1;
|
||||
}
|
||||
|
||||
while (*s1)
|
||||
s1++;
|
||||
|
||||
/* s1 now points to the its trailing null character, we can
|
||||
just use strcpy to do the work for us now.
|
||||
|
||||
?!? We might want to just include strcpy here.
|
||||
Also, this will cause many more unaligned string copies because
|
||||
s1 is much less likely to be aligned. I don't know if its worth
|
||||
tweaking strcpy to handle this better. */
|
||||
strcpy (s1, s2);
|
||||
|
||||
return s;
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strchr>>---search for character in string
|
||||
|
||||
INDEX
|
||||
strchr
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
char * strchr(const char *<[string]>, int <[c]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function finds the first occurence of <[c]> (converted to
|
||||
a char) in the string pointed to by <[string]> (including the
|
||||
terminating null character).
|
||||
|
||||
RETURNS
|
||||
Returns a pointer to the located character, or a null pointer
|
||||
if <[c]> does not occur in <[string]>.
|
||||
|
||||
PORTABILITY
|
||||
<<strchr>> is ANSI C.
|
||||
|
||||
<<strchr>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strchr ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
/* Nonzero if X is not aligned on a "long" boundary. */
|
||||
#define UNALIGNED(X) ((long)X & (sizeof (long) - 1))
|
||||
|
||||
/* How many bytes are loaded each iteration of the word copy loop. */
|
||||
#define LBLOCKSIZE (sizeof (long))
|
||||
|
||||
#if LONG_MAX == 2147483647L
|
||||
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
|
||||
#else
|
||||
#if LONG_MAX == 9223372036854775807L
|
||||
/* Nonzero if X (a long int) contains a NULL byte. */
|
||||
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
|
||||
#else
|
||||
#error long int is not a 32bit or 64bit type.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* DETECTCHAR returns nonzero if (long)X contains the byte used
|
||||
to fill (long)MASK. */
|
||||
#define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK))
|
||||
|
||||
char *
|
||||
strchr (const char *s1,
|
||||
int i)
|
||||
{
|
||||
const unsigned char *s = (const unsigned char *)s1;
|
||||
unsigned char c = i;
|
||||
|
||||
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
|
||||
unsigned long mask,j;
|
||||
unsigned long *aligned_addr;
|
||||
|
||||
/* Special case for finding 0. */
|
||||
if (!c)
|
||||
{
|
||||
while (UNALIGNED (s))
|
||||
{
|
||||
if (!*s)
|
||||
return (char *) s;
|
||||
s++;
|
||||
}
|
||||
/* Operate a word at a time. */
|
||||
aligned_addr = (unsigned long *) s;
|
||||
while (!DETECTNULL (*aligned_addr))
|
||||
aligned_addr++;
|
||||
/* Found the end of string. */
|
||||
s = (const unsigned char *) aligned_addr;
|
||||
while (*s)
|
||||
s++;
|
||||
return (char *) s;
|
||||
}
|
||||
|
||||
/* All other bytes. Align the pointer, then search a long at a time. */
|
||||
while (UNALIGNED (s))
|
||||
{
|
||||
if (!*s)
|
||||
return NULL;
|
||||
if (*s == c)
|
||||
return (char *) s;
|
||||
s++;
|
||||
}
|
||||
|
||||
mask = c;
|
||||
for (j = 8; j < LBLOCKSIZE * 8; j <<= 1)
|
||||
mask = (mask << j) | mask;
|
||||
|
||||
aligned_addr = (unsigned long *) s;
|
||||
while (!DETECTNULL (*aligned_addr) && !DETECTCHAR (*aligned_addr, mask))
|
||||
aligned_addr++;
|
||||
|
||||
/* The block of bytes currently pointed to by aligned_addr
|
||||
contains either a null or the target char, or both. We
|
||||
catch it using the bytewise search. */
|
||||
|
||||
s = (unsigned char *) aligned_addr;
|
||||
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
|
||||
while (*s && *s != c)
|
||||
s++;
|
||||
if (*s == c)
|
||||
return (char *)s;
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strchrnul>>---search for character in string
|
||||
|
||||
INDEX
|
||||
strchrnul
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
char * strchrnul(const char *<[string]>, int <[c]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function finds the first occurence of <[c]> (converted to
|
||||
a char) in the string pointed to by <[string]> (including the
|
||||
terminating null character).
|
||||
|
||||
RETURNS
|
||||
Returns a pointer to the located character, or a pointer
|
||||
to the concluding null byte if <[c]> does not occur in <[string]>.
|
||||
|
||||
PORTABILITY
|
||||
<<strchrnul>> is a GNU extension.
|
||||
|
||||
<<strchrnul>> requires no supporting OS subroutines. It uses
|
||||
strchr() and strlen() from elsewhere in this library.
|
||||
|
||||
QUICKREF
|
||||
strchrnul
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strchrnul (const char *s1,
|
||||
int i)
|
||||
{
|
||||
char *s = strchr(s1, i);
|
||||
|
||||
return s ? s : (char *)s1 + strlen(s1);
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strcmp>>---character string compare
|
||||
|
||||
INDEX
|
||||
strcmp
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
int strcmp(const char *<[a]>, const char *<[b]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<strcmp>> compares the string at <[a]> to
|
||||
the string at <[b]>.
|
||||
|
||||
RETURNS
|
||||
If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>,
|
||||
<<strcmp>> returns a number greater than zero. If the two
|
||||
strings match, <<strcmp>> returns zero. If <<*<[a]>>>
|
||||
sorts lexicographically before <<*<[b]>>>, <<strcmp>> returns a
|
||||
number less than zero.
|
||||
|
||||
PORTABILITY
|
||||
<<strcmp>> is ANSI C.
|
||||
|
||||
<<strcmp>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strcmp ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
/* Nonzero if either X or Y is not aligned on a "long" boundary. */
|
||||
#define UNALIGNED(X, Y) \
|
||||
(((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
|
||||
|
||||
/* DETECTNULL returns nonzero if (long)X contains a NULL byte. */
|
||||
#if LONG_MAX == 2147483647L
|
||||
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
|
||||
#else
|
||||
#if LONG_MAX == 9223372036854775807L
|
||||
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
|
||||
#else
|
||||
#error long int is not a 32bit or 64bit type.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DETECTNULL
|
||||
#error long int is not a 32bit or 64bit byte
|
||||
#endif
|
||||
|
||||
int
|
||||
strcmp (const char *s1,
|
||||
const char *s2)
|
||||
{
|
||||
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
|
||||
while (*s1 != '\0' && *s1 == *s2)
|
||||
{
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return (*(unsigned char *) s1) - (*(unsigned char *) s2);
|
||||
#else
|
||||
unsigned long *a1;
|
||||
unsigned long *a2;
|
||||
|
||||
/* If s1 or s2 are unaligned, then compare bytes. */
|
||||
if (!UNALIGNED (s1, s2))
|
||||
{
|
||||
/* If s1 and s2 are word-aligned, compare them a word at a time. */
|
||||
a1 = (unsigned long*)s1;
|
||||
a2 = (unsigned long*)s2;
|
||||
while (*a1 == *a2)
|
||||
{
|
||||
/* To get here, *a1 == *a2, thus if we find a null in *a1,
|
||||
then the strings must be equal, so return zero. */
|
||||
if (DETECTNULL (*a1))
|
||||
return 0;
|
||||
|
||||
a1++;
|
||||
a2++;
|
||||
}
|
||||
|
||||
/* A difference was detected in last few bytes of s1, so search bytewise */
|
||||
s1 = (char*)a1;
|
||||
s2 = (char*)a2;
|
||||
}
|
||||
|
||||
while (*s1 != '\0' && *s1 == *s2)
|
||||
{
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
return (*(unsigned char *) s1) - (*(unsigned char *) s2);
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strcoll>>---locale-specific character string compare
|
||||
|
||||
INDEX
|
||||
strcoll
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
int strcoll(const char *<[stra]>, const char * <[strb]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<strcoll>> compares the string pointed to by <[stra]> to
|
||||
the string pointed to by <[strb]>, using an interpretation
|
||||
appropriate to the current <<LC_COLLATE>> state.
|
||||
|
||||
(NOT Cygwin:) The current implementation of <<strcoll>> simply
|
||||
uses <<strcmp>> and does not support any language-specific sorting.
|
||||
|
||||
RETURNS
|
||||
If the first string is greater than the second string,
|
||||
<<strcoll>> returns a number greater than zero. If the two
|
||||
strings are equivalent, <<strcoll>> returns zero. If the first
|
||||
string is less than the second string, <<strcoll>> returns a
|
||||
number less than zero.
|
||||
|
||||
PORTABILITY
|
||||
<<strcoll>> is ANSI C.
|
||||
|
||||
<<strcoll>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strcoll ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
strcoll (const char *a,
|
||||
const char *b)
|
||||
|
||||
{
|
||||
return strcmp (a, b);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strcoll_l>>---locale-specific character string compare
|
||||
|
||||
INDEX
|
||||
strcoll_l
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
int strcoll_l(const char *<[stra]>, const char * <[strb]>,
|
||||
locale_t <[locale]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<strcoll_l>> compares the string pointed to by <[stra]> to
|
||||
the string pointed to by <[strb]>, using an interpretation
|
||||
appropriate to the current <<LC_COLLATE>> state.
|
||||
|
||||
(NOT Cygwin:) The current implementation of <<strcoll_l>> simply
|
||||
uses <<strcmp>> and does not support any language-specific sorting.
|
||||
|
||||
If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the
|
||||
behaviour is undefined.
|
||||
|
||||
RETURNS
|
||||
If the first string is greater than the second string,
|
||||
<<strcoll_l>> returns a number greater than zero. If the two
|
||||
strings are equivalent, <<strcoll_l>> returns zero. If the first
|
||||
string is less than the second string, <<strcoll_l>> returns a
|
||||
number less than zero.
|
||||
|
||||
PORTABILITY
|
||||
<<strcoll_l>> is POSIX-1.2008.
|
||||
|
||||
<<strcoll_l>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strcoll_l ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
strcoll_l (const char *a, const char *b, struct __locale_t *locale)
|
||||
{
|
||||
return strcmp (a, b);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strcpy>>---copy string
|
||||
|
||||
INDEX
|
||||
strcpy
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strcpy(char *<[dst]>, const char *<[src]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<strcpy>> copies the string pointed to by <[src]>
|
||||
(including the terminating null character) to the array
|
||||
pointed to by <[dst]>.
|
||||
|
||||
RETURNS
|
||||
This function returns the initial value of <[dst]>.
|
||||
|
||||
PORTABILITY
|
||||
<<strcpy>> is ANSI C.
|
||||
|
||||
<<strcpy>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strcpy ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
/*SUPPRESS 560*/
|
||||
/*SUPPRESS 530*/
|
||||
|
||||
/* Nonzero if either X or Y is not aligned on a "long" boundary. */
|
||||
#define UNALIGNED(X, Y) \
|
||||
(((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
|
||||
|
||||
#if LONG_MAX == 2147483647L
|
||||
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
|
||||
#else
|
||||
#if LONG_MAX == 9223372036854775807L
|
||||
/* Nonzero if X (a long int) contains a NULL byte. */
|
||||
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
|
||||
#else
|
||||
#error long int is not a 32bit or 64bit type.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DETECTNULL
|
||||
#error long int is not a 32bit or 64bit byte
|
||||
#endif
|
||||
|
||||
char*
|
||||
strcpy (char *dst0,
|
||||
const char *src0)
|
||||
{
|
||||
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
|
||||
char *s = dst0;
|
||||
|
||||
while (*dst0++ = *src0++)
|
||||
;
|
||||
|
||||
return s;
|
||||
#else
|
||||
char *dst = dst0;
|
||||
const char *src = src0;
|
||||
long *aligned_dst;
|
||||
const long *aligned_src;
|
||||
|
||||
/* If SRC or DEST is unaligned, then copy bytes. */
|
||||
if (!UNALIGNED (src, dst))
|
||||
{
|
||||
aligned_dst = (long*)dst;
|
||||
aligned_src = (long*)src;
|
||||
|
||||
/* SRC and DEST are both "long int" aligned, try to do "long int"
|
||||
sized copies. */
|
||||
while (!DETECTNULL(*aligned_src))
|
||||
{
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
}
|
||||
|
||||
dst = (char*)aligned_dst;
|
||||
src = (char*)aligned_src;
|
||||
}
|
||||
|
||||
while ((*dst++ = *src++))
|
||||
;
|
||||
return dst0;
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strcspn>>---count characters not in string
|
||||
|
||||
INDEX
|
||||
strcspn
|
||||
|
||||
SYNOPSIS
|
||||
size_t strcspn(const char *<[s1]>, const char *<[s2]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function computes the length of the initial part of
|
||||
the string pointed to by <[s1]> which consists entirely of
|
||||
characters <[NOT]> from the string pointed to by <[s2]>
|
||||
(excluding the terminating null character).
|
||||
|
||||
RETURNS
|
||||
<<strcspn>> returns the length of the substring found.
|
||||
|
||||
PORTABILITY
|
||||
<<strcspn>> is ANSI C.
|
||||
|
||||
<<strcspn>> requires no supporting OS subroutines.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t
|
||||
strcspn (const char *s1,
|
||||
const char *s2)
|
||||
{
|
||||
const char *s = s1;
|
||||
const char *c;
|
||||
|
||||
while (*s1)
|
||||
{
|
||||
for (c = s2; *c; c++)
|
||||
{
|
||||
if (*s1 == *c)
|
||||
break;
|
||||
}
|
||||
if (*c)
|
||||
break;
|
||||
s1++;
|
||||
}
|
||||
|
||||
return s1 - s;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef _REENT_ONLY
|
||||
|
||||
#include <reent.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strdup (const char *str)
|
||||
{
|
||||
return _strdup_r (_REENT, str);
|
||||
}
|
||||
|
||||
#endif /* !_REENT_ONLY */
|
||||
@@ -0,0 +1,16 @@
|
||||
#include <reent.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
_strdup_r (struct _reent *reent_ptr,
|
||||
const char *str)
|
||||
{
|
||||
size_t len = strlen (str) + 1;
|
||||
char *copy = _malloc_r (reent_ptr, len);
|
||||
if (copy)
|
||||
{
|
||||
memcpy (copy, str, len);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
@@ -0,0 +1,905 @@
|
||||
/***
|
||||
**** CAUTION!!! KEEP DOC CONSISTENT---if you change text of a message
|
||||
**** here, change two places:
|
||||
**** 1) the leading doc section (alphabetized by macro)
|
||||
**** 2) the real text inside switch(errnum)
|
||||
***/
|
||||
|
||||
/*
|
||||
FUNCTION
|
||||
<<strerror>>, <<strerror_l>>---convert error number to string
|
||||
|
||||
INDEX
|
||||
strerror
|
||||
|
||||
INDEX
|
||||
strerror_l
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strerror(int <[errnum]>);
|
||||
char *strerror_l(int <[errnum]>, locale_t <[locale]>);
|
||||
char *_strerror_r(struct _reent <[ptr]>, int <[errnum]>,
|
||||
int <[internal]>, int *<[error]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<strerror>> converts the error number <[errnum]> into a
|
||||
string. The value of <[errnum]> is usually a copy of <<errno>>.
|
||||
If <<errnum>> is not a known error number, the result points to an
|
||||
empty string.
|
||||
|
||||
<<strerror_l>> is like <<strerror>> but creates a string in a format
|
||||
as expected in locale <[locale]>. If <[locale]> is LC_GLOBAL_LOCALE or
|
||||
not a valid locale object, the behaviour is undefined.
|
||||
|
||||
This implementation of <<strerror>> prints out the following strings
|
||||
for each of the values defined in `<<errno.h>>':
|
||||
|
||||
o+
|
||||
o 0
|
||||
Success
|
||||
|
||||
o E2BIG
|
||||
Arg list too long
|
||||
|
||||
o EACCES
|
||||
Permission denied
|
||||
|
||||
o EADDRINUSE
|
||||
Address already in use
|
||||
|
||||
o EADDRNOTAVAIL
|
||||
Address not available
|
||||
|
||||
o EADV
|
||||
Advertise error
|
||||
|
||||
o EAFNOSUPPORT
|
||||
Address family not supported by protocol family
|
||||
|
||||
o EAGAIN
|
||||
No more processes
|
||||
|
||||
o EALREADY
|
||||
Socket already connected
|
||||
|
||||
o EBADF
|
||||
Bad file number
|
||||
|
||||
o EBADMSG
|
||||
Bad message
|
||||
|
||||
o EBUSY
|
||||
Device or resource busy
|
||||
|
||||
o ECANCELED
|
||||
Operation canceled
|
||||
|
||||
o ECHILD
|
||||
No children
|
||||
|
||||
o ECOMM
|
||||
Communication error
|
||||
|
||||
o ECONNABORTED
|
||||
Software caused connection abort
|
||||
|
||||
o ECONNREFUSED
|
||||
Connection refused
|
||||
|
||||
o ECONNRESET
|
||||
Connection reset by peer
|
||||
|
||||
o EDEADLK
|
||||
Deadlock
|
||||
|
||||
o EDESTADDRREQ
|
||||
Destination address required
|
||||
|
||||
o EEXIST
|
||||
File exists
|
||||
|
||||
o EDOM
|
||||
Mathematics argument out of domain of function
|
||||
|
||||
o EFAULT
|
||||
Bad address
|
||||
|
||||
o EFBIG
|
||||
File too large
|
||||
|
||||
o EHOSTDOWN
|
||||
Host is down
|
||||
|
||||
o EHOSTUNREACH
|
||||
Host is unreachable
|
||||
|
||||
o EIDRM
|
||||
Identifier removed
|
||||
|
||||
o EILSEQ
|
||||
Illegal byte sequence
|
||||
|
||||
o EINPROGRESS
|
||||
Connection already in progress
|
||||
|
||||
o EINTR
|
||||
Interrupted system call
|
||||
|
||||
o EINVAL
|
||||
Invalid argument
|
||||
|
||||
o EIO
|
||||
I/O error
|
||||
|
||||
o EISCONN
|
||||
Socket is already connected
|
||||
|
||||
o EISDIR
|
||||
Is a directory
|
||||
|
||||
o ELIBACC
|
||||
Cannot access a needed shared library
|
||||
|
||||
o ELIBBAD
|
||||
Accessing a corrupted shared library
|
||||
|
||||
o ELIBEXEC
|
||||
Cannot exec a shared library directly
|
||||
|
||||
o ELIBMAX
|
||||
Attempting to link in more shared libraries than system limit
|
||||
|
||||
o ELIBSCN
|
||||
<<.lib>> section in a.out corrupted
|
||||
|
||||
o EMFILE
|
||||
File descriptor value too large
|
||||
|
||||
o EMLINK
|
||||
Too many links
|
||||
|
||||
o EMSGSIZE
|
||||
Message too long
|
||||
|
||||
o EMULTIHOP
|
||||
Multihop attempted
|
||||
|
||||
o ENAMETOOLONG
|
||||
File or path name too long
|
||||
|
||||
o ENETDOWN
|
||||
Network interface is not configured
|
||||
|
||||
o ENETRESET
|
||||
Connection aborted by network
|
||||
|
||||
o ENETUNREACH
|
||||
Network is unreachable
|
||||
|
||||
o ENFILE
|
||||
Too many open files in system
|
||||
|
||||
o ENOBUFS
|
||||
No buffer space available
|
||||
|
||||
o ENODATA
|
||||
No data
|
||||
|
||||
o ENODEV
|
||||
No such device
|
||||
|
||||
o ENOENT
|
||||
No such file or directory
|
||||
|
||||
o ENOEXEC
|
||||
Exec format error
|
||||
|
||||
o ENOLCK
|
||||
No lock
|
||||
|
||||
o ENOLINK
|
||||
Virtual circuit is gone
|
||||
|
||||
o ENOMEM
|
||||
Not enough space
|
||||
|
||||
o ENOMSG
|
||||
No message of desired type
|
||||
|
||||
o ENONET
|
||||
Machine is not on the network
|
||||
|
||||
o ENOPKG
|
||||
No package
|
||||
|
||||
o ENOPROTOOPT
|
||||
Protocol not available
|
||||
|
||||
o ENOSPC
|
||||
No space left on device
|
||||
|
||||
o ENOSR
|
||||
No stream resources
|
||||
|
||||
o ENOSTR
|
||||
Not a stream
|
||||
|
||||
o ENOSYS
|
||||
Function not implemented
|
||||
|
||||
o ENOTBLK
|
||||
Block device required
|
||||
|
||||
o ENOTCONN
|
||||
Socket is not connected
|
||||
|
||||
o ENOTDIR
|
||||
Not a directory
|
||||
|
||||
o ENOTEMPTY
|
||||
Directory not empty
|
||||
|
||||
o ENOTRECOVERABLE
|
||||
State not recoverable
|
||||
|
||||
o ENOTSOCK
|
||||
Socket operation on non-socket
|
||||
|
||||
o ENOTSUP
|
||||
Not supported
|
||||
|
||||
o ENOTTY
|
||||
Not a character device
|
||||
|
||||
o ENXIO
|
||||
No such device or address
|
||||
|
||||
o EOPNOTSUPP
|
||||
Operation not supported on socket
|
||||
|
||||
o EOVERFLOW
|
||||
Value too large for defined data type
|
||||
|
||||
o EOWNERDEAD
|
||||
Previous owner died
|
||||
|
||||
o EPERM
|
||||
Not owner
|
||||
|
||||
o EPIPE
|
||||
Broken pipe
|
||||
|
||||
o EPROTO
|
||||
Protocol error
|
||||
|
||||
o EPROTOTYPE
|
||||
Protocol wrong type for socket
|
||||
|
||||
o EPROTONOSUPPORT
|
||||
Unknown protocol
|
||||
|
||||
o ERANGE
|
||||
Result too large
|
||||
|
||||
o EREMOTE
|
||||
Resource is remote
|
||||
|
||||
o EROFS
|
||||
Read-only file system
|
||||
|
||||
o ESHUTDOWN
|
||||
Can't send after socket shutdown
|
||||
|
||||
o ESOCKTNOSUPPORT
|
||||
Socket type not supported
|
||||
|
||||
o ESPIPE
|
||||
Illegal seek
|
||||
|
||||
o ESRCH
|
||||
No such process
|
||||
|
||||
o ESRMNT
|
||||
Srmount error
|
||||
|
||||
o ESTRPIPE
|
||||
Strings pipe error
|
||||
|
||||
o ETIME
|
||||
Stream ioctl timeout
|
||||
|
||||
o ETIMEDOUT
|
||||
Connection timed out
|
||||
|
||||
o ETXTBSY
|
||||
Text file busy
|
||||
|
||||
o EWOULDBLOCK
|
||||
Operation would block (usually same as EAGAIN)
|
||||
|
||||
o EXDEV
|
||||
Cross-device link
|
||||
|
||||
o-
|
||||
|
||||
<<_strerror_r>> is a reentrant version of the above.
|
||||
|
||||
RETURNS
|
||||
This function returns a pointer to a string. Your application must
|
||||
not modify that string.
|
||||
|
||||
PORTABILITY
|
||||
ANSI C requires <<strerror>>, but does not specify the strings used
|
||||
for each error number.
|
||||
|
||||
<<strerror_l>> is POSIX-1.2008.
|
||||
|
||||
Although this implementation of <<strerror>> is reentrant (depending
|
||||
on <<_user_strerror>>), ANSI C declares that subsequent calls to
|
||||
<<strerror>> may overwrite the result string; therefore portable
|
||||
code cannot depend on the reentrancy of this subroutine.
|
||||
|
||||
Although this implementation of <<strerror>> guarantees a non-null
|
||||
result with a NUL-terminator, some implementations return <<NULL>>
|
||||
on failure. Although POSIX allows <<strerror>> to set <<errno>>
|
||||
to EINVAL on failure, this implementation does not do so (unless
|
||||
you provide <<_user_strerror>>).
|
||||
|
||||
POSIX recommends that unknown <[errnum]> result in a message
|
||||
including that value, however it is not a requirement and this
|
||||
implementation does not provide that information (unless you
|
||||
provide <<_user_strerror>>).
|
||||
|
||||
This implementation of <<strerror>> provides for user-defined
|
||||
extensibility. <<errno.h>> defines <[__ELASTERROR]>, which can be
|
||||
used as a base for user-defined error values. If the user supplies a
|
||||
routine named <<_user_strerror>>, and <[errnum]> passed to
|
||||
<<strerror>> does not match any of the supported values,
|
||||
<<_user_strerror>> is called with three arguments. The first is of
|
||||
type <[int]>, and is the <[errnum]> value unknown to <<strerror>>.
|
||||
The second is of type <[int]>, and matches the <[internal]> argument
|
||||
of <<_strerror_r>>; this should be zero if called from <<strerror>>
|
||||
and non-zero if called from any other function; <<_user_strerror>> can
|
||||
use this information to satisfy the POSIX rule that no other
|
||||
standardized function can overwrite a static buffer reused by
|
||||
<<strerror>>. The third is of type <[int *]>, and matches the
|
||||
<[error]> argument of <<_strerror_r>>; if a non-zero value is stored
|
||||
into that location (usually <[EINVAL]>), then <<strerror>> will set
|
||||
<<errno>> to that value, and the XPG variant of <<strerror_r>> will
|
||||
return that value instead of zero or <[ERANGE]>. <<_user_strerror>>
|
||||
returns a <[char *]> value; returning <[NULL]> implies that the user
|
||||
function did not choose to handle <[errnum]>. The default
|
||||
<<_user_strerror>> returns <[NULL]> for all input values. Note that
|
||||
<<_user_sterror>> must be thread-safe, and only denote errors via the
|
||||
third argument rather than modifying <<errno>>, if <<strerror>> and
|
||||
<<strerror_r>> are are to comply with POSIX.
|
||||
|
||||
<<strerror>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strerror ansi pure
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
_strerror_r (struct _reent *ptr,
|
||||
int errnum,
|
||||
int internal,
|
||||
int *errptr)
|
||||
{
|
||||
char *error;
|
||||
extern char *_user_strerror (int, int, int *);
|
||||
|
||||
switch (errnum)
|
||||
{
|
||||
case 0:
|
||||
error = "Success";
|
||||
break;
|
||||
/* go32 defines EPERM as EACCES */
|
||||
#if defined (EPERM) && (!defined (EACCES) || (EPERM != EACCES))
|
||||
case EPERM:
|
||||
error = "Not owner";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOENT
|
||||
case ENOENT:
|
||||
error = "No such file or directory";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ESRCH
|
||||
case ESRCH:
|
||||
error = "No such process";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EINTR
|
||||
case EINTR:
|
||||
error = "Interrupted system call";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIO
|
||||
case EIO:
|
||||
error = "I/O error";
|
||||
break;
|
||||
#endif
|
||||
/* go32 defines ENXIO as ENODEV */
|
||||
#if defined (ENXIO) && (!defined (ENODEV) || (ENXIO != ENODEV))
|
||||
case ENXIO:
|
||||
error = "No such device or address";
|
||||
break;
|
||||
#endif
|
||||
#ifdef E2BIG
|
||||
case E2BIG:
|
||||
error = "Arg list too long";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOEXEC
|
||||
case ENOEXEC:
|
||||
error = "Exec format error";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EALREADY
|
||||
case EALREADY:
|
||||
error = "Socket already connected";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EBADF
|
||||
case EBADF:
|
||||
error = "Bad file number";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ECHILD
|
||||
case ECHILD:
|
||||
error = "No children";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EDESTADDRREQ
|
||||
case EDESTADDRREQ:
|
||||
error = "Destination address required";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EAGAIN
|
||||
case EAGAIN:
|
||||
error = "No more processes";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOMEM
|
||||
case ENOMEM:
|
||||
error = "Not enough space";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EACCES
|
||||
case EACCES:
|
||||
error = "Permission denied";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EFAULT
|
||||
case EFAULT:
|
||||
error = "Bad address";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOTBLK
|
||||
case ENOTBLK:
|
||||
error = "Block device required";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EBUSY
|
||||
case EBUSY:
|
||||
error = "Device or resource busy";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EEXIST
|
||||
case EEXIST:
|
||||
error = "File exists";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EXDEV
|
||||
case EXDEV:
|
||||
error = "Cross-device link";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENODEV
|
||||
case ENODEV:
|
||||
error = "No such device";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOTDIR
|
||||
case ENOTDIR:
|
||||
error = "Not a directory";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EHOSTDOWN
|
||||
case EHOSTDOWN:
|
||||
error = "Host is down";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EINPROGRESS
|
||||
case EINPROGRESS:
|
||||
error = "Connection already in progress";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EISDIR
|
||||
case EISDIR:
|
||||
error = "Is a directory";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EINVAL
|
||||
case EINVAL:
|
||||
error = "Invalid argument";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENETDOWN
|
||||
case ENETDOWN:
|
||||
error = "Network interface is not configured";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENETRESET
|
||||
case ENETRESET:
|
||||
error = "Connection aborted by network";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENFILE
|
||||
case ENFILE:
|
||||
error = "Too many open files in system";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EMFILE
|
||||
case EMFILE:
|
||||
error = "File descriptor value too large";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOTTY
|
||||
case ENOTTY:
|
||||
error = "Not a character device";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ETXTBSY
|
||||
case ETXTBSY:
|
||||
error = "Text file busy";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EFBIG
|
||||
case EFBIG:
|
||||
error = "File too large";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EHOSTUNREACH
|
||||
case EHOSTUNREACH:
|
||||
error = "Host is unreachable";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOSPC
|
||||
case ENOSPC:
|
||||
error = "No space left on device";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOTSUP
|
||||
case ENOTSUP:
|
||||
error = "Not supported";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ESPIPE
|
||||
case ESPIPE:
|
||||
error = "Illegal seek";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EROFS
|
||||
case EROFS:
|
||||
error = "Read-only file system";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EMLINK
|
||||
case EMLINK:
|
||||
error = "Too many links";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EPIPE
|
||||
case EPIPE:
|
||||
error = "Broken pipe";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EDOM
|
||||
case EDOM:
|
||||
error = "Mathematics argument out of domain of function";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERANGE
|
||||
case ERANGE:
|
||||
error = "Result too large";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOMSG
|
||||
case ENOMSG:
|
||||
error = "No message of desired type";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIDRM
|
||||
case EIDRM:
|
||||
error = "Identifier removed";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EILSEQ
|
||||
case EILSEQ:
|
||||
error = "Illegal byte sequence";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EDEADLK
|
||||
case EDEADLK:
|
||||
error = "Deadlock";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENETUNREACH
|
||||
case ENETUNREACH:
|
||||
error = "Network is unreachable";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOLCK
|
||||
case ENOLCK:
|
||||
error = "No lock";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOSTR
|
||||
case ENOSTR:
|
||||
error = "Not a stream";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ETIME
|
||||
case ETIME:
|
||||
error = "Stream ioctl timeout";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOSR
|
||||
case ENOSR:
|
||||
error = "No stream resources";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENONET
|
||||
case ENONET:
|
||||
error = "Machine is not on the network";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOPKG
|
||||
case ENOPKG:
|
||||
error = "No package";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EREMOTE
|
||||
case EREMOTE:
|
||||
error = "Resource is remote";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOLINK
|
||||
case ENOLINK:
|
||||
error = "Virtual circuit is gone";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EADV
|
||||
case EADV:
|
||||
error = "Advertise error";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ESRMNT
|
||||
case ESRMNT:
|
||||
error = "Srmount error";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ECOMM
|
||||
case ECOMM:
|
||||
error = "Communication error";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EPROTO
|
||||
case EPROTO:
|
||||
error = "Protocol error";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EPROTONOSUPPORT
|
||||
case EPROTONOSUPPORT:
|
||||
error = "Unknown protocol";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EMULTIHOP
|
||||
case EMULTIHOP:
|
||||
error = "Multihop attempted";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EBADMSG
|
||||
case EBADMSG:
|
||||
error = "Bad message";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ELIBACC
|
||||
case ELIBACC:
|
||||
error = "Cannot access a needed shared library";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ELIBBAD
|
||||
case ELIBBAD:
|
||||
error = "Accessing a corrupted shared library";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ELIBSCN
|
||||
case ELIBSCN:
|
||||
error = ".lib section in a.out corrupted";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ELIBMAX
|
||||
case ELIBMAX:
|
||||
error = "Attempting to link in more shared libraries than system limit";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ELIBEXEC
|
||||
case ELIBEXEC:
|
||||
error = "Cannot exec a shared library directly";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOSYS
|
||||
case ENOSYS:
|
||||
error = "Function not implemented";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENMFILE
|
||||
case ENMFILE:
|
||||
error = "No more files";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOTEMPTY
|
||||
case ENOTEMPTY:
|
||||
error = "Directory not empty";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENAMETOOLONG
|
||||
case ENAMETOOLONG:
|
||||
error = "File or path name too long";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ELOOP
|
||||
case ELOOP:
|
||||
error = "Too many symbolic links";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOBUFS
|
||||
case ENOBUFS:
|
||||
error = "No buffer space available";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENODATA
|
||||
case ENODATA:
|
||||
error = "No data";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EAFNOSUPPORT
|
||||
case EAFNOSUPPORT:
|
||||
error = "Address family not supported by protocol family";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EPROTOTYPE
|
||||
case EPROTOTYPE:
|
||||
error = "Protocol wrong type for socket";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOTSOCK
|
||||
case ENOTSOCK:
|
||||
error = "Socket operation on non-socket";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOPROTOOPT
|
||||
case ENOPROTOOPT:
|
||||
error = "Protocol not available";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ESHUTDOWN
|
||||
case ESHUTDOWN:
|
||||
error = "Can't send after socket shutdown";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ECONNREFUSED
|
||||
case ECONNREFUSED:
|
||||
error = "Connection refused";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ECONNRESET
|
||||
case ECONNRESET:
|
||||
error = "Connection reset by peer";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EADDRINUSE
|
||||
case EADDRINUSE:
|
||||
error = "Address already in use";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EADDRNOTAVAIL
|
||||
case EADDRNOTAVAIL:
|
||||
error = "Address not available";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ECONNABORTED
|
||||
case ECONNABORTED:
|
||||
error = "Software caused connection abort";
|
||||
break;
|
||||
#endif
|
||||
#if (defined(EWOULDBLOCK) && (!defined (EAGAIN) || (EWOULDBLOCK != EAGAIN)))
|
||||
case EWOULDBLOCK:
|
||||
error = "Operation would block";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOTCONN
|
||||
case ENOTCONN:
|
||||
error = "Socket is not connected";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ESOCKTNOSUPPORT
|
||||
case ESOCKTNOSUPPORT:
|
||||
error = "Socket type not supported";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EISCONN
|
||||
case EISCONN:
|
||||
error = "Socket is already connected";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ECANCELED
|
||||
case ECANCELED:
|
||||
error = "Operation canceled";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOTRECOVERABLE
|
||||
case ENOTRECOVERABLE:
|
||||
error = "State not recoverable";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EOWNERDEAD
|
||||
case EOWNERDEAD:
|
||||
error = "Previous owner died";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ESTRPIPE
|
||||
case ESTRPIPE:
|
||||
error = "Streams pipe error";
|
||||
break;
|
||||
#endif
|
||||
#if defined(EOPNOTSUPP) && (!defined(ENOTSUP) || (ENOTSUP != EOPNOTSUPP))
|
||||
case EOPNOTSUPP:
|
||||
error = "Operation not supported on socket";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EOVERFLOW
|
||||
case EOVERFLOW:
|
||||
error = "Value too large for defined data type";
|
||||
break;
|
||||
#endif
|
||||
#ifdef EMSGSIZE
|
||||
case EMSGSIZE:
|
||||
error = "Message too long";
|
||||
break;
|
||||
#endif
|
||||
#ifdef ETIMEDOUT
|
||||
case ETIMEDOUT:
|
||||
error = "Connection timed out";
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
if (!errptr)
|
||||
errptr = &_REENT_ERRNO(ptr);
|
||||
if ((error = _user_strerror (errnum, internal, errptr)) == 0)
|
||||
error = "";
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
char *
|
||||
strerror (int errnum)
|
||||
{
|
||||
return _strerror_r (_REENT, errnum, 0, NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
strerror_l (int errnum, locale_t locale)
|
||||
{
|
||||
/* We don't support per-locale error messages. */
|
||||
return _strerror_r (_REENT, errnum, 0, NULL);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/* GNU variant of strerror_r. */
|
||||
/*
|
||||
FUNCTION
|
||||
<<strerror_r>>---convert error number to string and copy to buffer
|
||||
|
||||
INDEX
|
||||
strerror_r
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
#ifdef _GNU_SOURCE
|
||||
char *strerror_r(int <[errnum]>, char *<[buffer]>, size_t <[n]>);
|
||||
#else
|
||||
int strerror_r(int <[errnum]>, char *<[buffer]>, size_t <[n]>);
|
||||
#endif
|
||||
|
||||
DESCRIPTION
|
||||
<<strerror_r>> converts the error number <[errnum]> into a
|
||||
string and copies the result into the supplied <[buffer]> for
|
||||
a length up to <[n]>, including the NUL terminator. The value of
|
||||
<[errnum]> is usually a copy of <<errno>>. If <<errnum>> is not a known
|
||||
error number, the result is the empty string.
|
||||
|
||||
See <<strerror>> for how strings are mapped to <<errnum>>.
|
||||
|
||||
RETURNS
|
||||
There are two variants: the GNU version always returns a NUL-terminated
|
||||
string, which is <[buffer]> if all went well, but which is another
|
||||
pointer if <[n]> was too small (leaving <[buffer]> untouched). If the
|
||||
return is not <[buffer]>, your application must not modify that string.
|
||||
The POSIX version returns 0 on success, <[EINVAL]> if <<errnum>> was not
|
||||
recognized, and <[ERANGE]> if <[n]> was too small. The variant chosen
|
||||
depends on macros that you define before inclusion of <<string.h>>.
|
||||
|
||||
PORTABILITY
|
||||
<<strerror_r>> with a <[char *]> result is a GNU extension.
|
||||
<<strerror_r>> with an <[int]> result is required by POSIX 2001.
|
||||
This function is compliant only if <<_user_strerror>> is not provided,
|
||||
or if it is thread-safe and uses separate storage according to whether
|
||||
the second argument of that function is non-zero. For more details
|
||||
on <<_user_strerror>>, see the <<strerror>> documentation.
|
||||
|
||||
POSIX states that the contents of <[buf]> are unspecified on error,
|
||||
although this implementation guarantees a NUL-terminated string for
|
||||
all except <[n]> of 0.
|
||||
|
||||
POSIX recommends that unknown <[errnum]> result in a message including
|
||||
that value, however it is not a requirement and this implementation
|
||||
provides only an empty string (unless you provide <<_user_strerror>>).
|
||||
POSIX also recommends that unknown <[errnum]> fail with EINVAL even
|
||||
when providing such a message, however it is not a requirement and
|
||||
this implementation will return success if <<_user_strerror>> provided
|
||||
a non-empty alternate string without assigning into its third argument.
|
||||
|
||||
<<strerror_r>> requires no supporting OS subroutines.
|
||||
|
||||
*/
|
||||
|
||||
#undef __STRICT_ANSI__
|
||||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#undef strerror_r
|
||||
|
||||
/* For backwards-compatible linking, this must be the GNU signature;
|
||||
see xpg_strerror_r.c for the POSIX version. */
|
||||
char *
|
||||
strerror_r (int errnum,
|
||||
char *buffer,
|
||||
size_t n)
|
||||
{
|
||||
char *error = _strerror_r (_REENT, errnum, 1, NULL);
|
||||
|
||||
if (strlen (error) >= n)
|
||||
return error;
|
||||
return strcpy (buffer, error);
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
@node Strings
|
||||
@chapter Strings and Memory (@file{string.h})
|
||||
|
||||
This chapter describes string-handling functions and functions for
|
||||
managing areas of memory. The corresponding declarations are in
|
||||
@file{string.h}.
|
||||
|
||||
@menu
|
||||
* bcmp:: Compare two memory areas
|
||||
* bcopy:: Copy memory regions
|
||||
* bzero:: Initialize memory to zero
|
||||
* index:: Search for character in string
|
||||
* memccpy:: Copy memory regions up to end-token
|
||||
* memchr:: Find character in memory
|
||||
* memcmp:: Compare two memory areas
|
||||
* memcpy:: Copy memory regions
|
||||
* memmem:: Find memory segment
|
||||
* memmove:: Move possibly overlapping memory
|
||||
* mempcpy:: Copy memory regions and locate end
|
||||
* memrchr:: Reverse search for character in memory
|
||||
* memset:: Set an area of memory
|
||||
* rawmemchr:: Find character in memory
|
||||
* rindex:: Reverse search for character in string
|
||||
* stpcpy:: Copy string returning a pointer to its end
|
||||
* stpncpy:: Counted copy string returning a pointer to its end
|
||||
* strcasecmp:: Compare strings ignoring case
|
||||
* strcasestr:: Find string segment ignoring case
|
||||
* strcat:: Concatenate strings
|
||||
* strchr:: Search for character in string
|
||||
* strchrnul:: Search for character in string
|
||||
* strcmp:: Character string compare
|
||||
* strcoll:: Locale-specific character string compare
|
||||
* strcpy:: Copy string
|
||||
* strcspn:: Count chars not in string
|
||||
* strerror:: Convert error number to string (strerror, strerror_l)
|
||||
* strerror_r:: Convert error number to string
|
||||
* strlen:: Character string length
|
||||
* strlwr:: Convert string to lowercase
|
||||
* strncasecmp:: Compare strings ignoring case
|
||||
* strncat:: Concatenate strings
|
||||
* strncmp:: Character string compare
|
||||
* strncpy:: Counted copy string
|
||||
* strnstr:: Find string segment
|
||||
* strnlen:: Character string length
|
||||
* strpbrk:: Find chars in string
|
||||
* strrchr:: Reverse search for character in string
|
||||
* strsignal:: Return signal message string
|
||||
* strspn:: Find initial match
|
||||
* strstr:: Find string segment
|
||||
* strtok:: Get next token from a string
|
||||
* strupr:: Convert string to upper case
|
||||
* strverscmp:: Compare version strings
|
||||
* strxfrm:: Transform string
|
||||
* swab:: Swap adjacent bytes
|
||||
* wcscasecmp:: Compare wide character strings ignoring case
|
||||
* wcsdup:: Wide character string duplicate
|
||||
* wcsncasecmp:: Compare wide character strings ignoring case
|
||||
@end menu
|
||||
|
||||
@page
|
||||
@include string/bcmp.def
|
||||
|
||||
@page
|
||||
@include string/bcopy.def
|
||||
|
||||
@page
|
||||
@include string/bzero.def
|
||||
|
||||
@page
|
||||
@include string/index.def
|
||||
|
||||
@page
|
||||
@include string/memccpy.def
|
||||
|
||||
@page
|
||||
@include string/memchr.def
|
||||
|
||||
@page
|
||||
@include string/memcmp.def
|
||||
|
||||
@page
|
||||
@include string/memcpy.def
|
||||
|
||||
@page
|
||||
@include string/memmem.def
|
||||
|
||||
@page
|
||||
@include string/memmove.def
|
||||
|
||||
@page
|
||||
@include string/mempcpy.def
|
||||
|
||||
@page
|
||||
@include string/memrchr.def
|
||||
|
||||
@page
|
||||
@include string/memset.def
|
||||
|
||||
@page
|
||||
@include string/rawmemchr.def
|
||||
|
||||
@page
|
||||
@include string/rindex.def
|
||||
|
||||
@page
|
||||
@include string/stpcpy.def
|
||||
|
||||
@page
|
||||
@include string/stpncpy.def
|
||||
|
||||
@page
|
||||
@include string/strcasecmp.def
|
||||
|
||||
@page
|
||||
@include string/strcasestr.def
|
||||
|
||||
@page
|
||||
@include string/strcat.def
|
||||
|
||||
@page
|
||||
@include string/strchr.def
|
||||
|
||||
@page
|
||||
@include string/strchrnul.def
|
||||
|
||||
@page
|
||||
@include string/strcmp.def
|
||||
|
||||
@page
|
||||
@include string/strcoll.def
|
||||
|
||||
@page
|
||||
@include string/strcpy.def
|
||||
|
||||
@page
|
||||
@include string/strcspn.def
|
||||
|
||||
@page
|
||||
@include string/strerror.def
|
||||
|
||||
@page
|
||||
@include string/strerror_r.def
|
||||
|
||||
@page
|
||||
@include string/strlen.def
|
||||
|
||||
@page
|
||||
@include string/strlwr.def
|
||||
|
||||
@page
|
||||
@include string/strncasecmp.def
|
||||
|
||||
@page
|
||||
@include string/strncat.def
|
||||
|
||||
@page
|
||||
@include string/strncmp.def
|
||||
|
||||
@page
|
||||
@include string/strncpy.def
|
||||
|
||||
@page
|
||||
@include string/strnstr.def
|
||||
|
||||
@page
|
||||
@include string/strnlen.def
|
||||
|
||||
@page
|
||||
@include string/strpbrk.def
|
||||
|
||||
@page
|
||||
@include string/strrchr.def
|
||||
|
||||
@page
|
||||
@include string/strsignal.def
|
||||
|
||||
@page
|
||||
@include string/strspn.def
|
||||
|
||||
@page
|
||||
@include string/strstr.def
|
||||
|
||||
@page
|
||||
@include string/strtok.def
|
||||
|
||||
@page
|
||||
@include string/strupr.def
|
||||
|
||||
@page
|
||||
@include string/strverscmp.def
|
||||
|
||||
@page
|
||||
@include string/strxfrm.def
|
||||
|
||||
@page
|
||||
@include string/swab.def
|
||||
|
||||
@page
|
||||
@include string/wcscasecmp.def
|
||||
|
||||
@page
|
||||
@include string/wcsdup.def
|
||||
|
||||
@page
|
||||
@include string/wcsncasecmp.def
|
||||
@@ -0,0 +1,57 @@
|
||||
/* $OpenBSD: strlcat.c,v 1.19 2019/01/25 00:19:25 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Appends src to string dst of size dsize (unlike strncat, dsize is the
|
||||
* full size of dst, not space left). At most dsize-1 characters
|
||||
* will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
|
||||
* Returns strlen(src) + MIN(dsize, strlen(initial dst)).
|
||||
* If retval >= dsize, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcat (char *dst,
|
||||
const char *src,
|
||||
size_t dsize)
|
||||
{
|
||||
const char *odst = dst;
|
||||
const char *osrc = src;
|
||||
size_t n = dsize;
|
||||
size_t dlen;
|
||||
|
||||
/* Find the end of dst and adjust bytes left but don't go past end. */
|
||||
while (n-- != 0 && *dst != '\0')
|
||||
dst++;
|
||||
dlen = dst - odst;
|
||||
n = dsize - dlen;
|
||||
|
||||
if (n-- == 0)
|
||||
return(dlen + strlen(src));
|
||||
while (*src != '\0') {
|
||||
if (n != 0) {
|
||||
*dst++ = *src;
|
||||
n--;
|
||||
}
|
||||
src++;
|
||||
}
|
||||
*dst = '\0';
|
||||
|
||||
return(dlen + (src - osrc)); /* count does not include NUL */
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/* $OpenBSD: strlcpy.c,v 1.16 2019/01/25 00:19:25 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Copy string src to buffer dst of size dsize. At most dsize-1
|
||||
* chars will be copied. Always NUL terminates (unless dsize == 0).
|
||||
* Returns strlen(src); if retval >= dsize, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcpy (char *dst,
|
||||
const char *src,
|
||||
size_t dsize)
|
||||
{
|
||||
const char *osrc = src;
|
||||
size_t nleft = dsize;
|
||||
|
||||
/* Copy as many bytes as will fit. */
|
||||
if (nleft != 0) {
|
||||
while (--nleft != 0) {
|
||||
if ((*dst++ = *src++) == '\0')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Not enough room in dst, add NUL and traverse rest of src. */
|
||||
if (nleft == 0) {
|
||||
if (dsize != 0)
|
||||
*dst = '\0'; /* NUL-terminate dst */
|
||||
while (*src++)
|
||||
;
|
||||
}
|
||||
|
||||
return(src - osrc - 1); /* count does not include NUL */
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strlen>>---character string length
|
||||
|
||||
INDEX
|
||||
strlen
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
size_t strlen(const char *<[str]>);
|
||||
|
||||
DESCRIPTION
|
||||
The <<strlen>> function works out the length of the string
|
||||
starting at <<*<[str]>>> by counting chararacters until it
|
||||
reaches a <<NULL>> character.
|
||||
|
||||
RETURNS
|
||||
<<strlen>> returns the character count.
|
||||
|
||||
PORTABILITY
|
||||
<<strlen>> is ANSI C.
|
||||
|
||||
<<strlen>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strlen ansi pure
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
#define LBLOCKSIZE (sizeof (long))
|
||||
#define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1))
|
||||
|
||||
#if LONG_MAX == 2147483647L
|
||||
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
|
||||
#else
|
||||
#if LONG_MAX == 9223372036854775807L
|
||||
/* Nonzero if X (a long int) contains a NULL byte. */
|
||||
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
|
||||
#else
|
||||
#error long int is not a 32bit or 64bit type.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DETECTNULL
|
||||
#error long int is not a 32bit or 64bit byte
|
||||
#endif
|
||||
|
||||
size_t
|
||||
strlen (const char *str)
|
||||
{
|
||||
const char *start = str;
|
||||
|
||||
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
|
||||
unsigned long *aligned_addr;
|
||||
|
||||
/* Align the pointer, so we can search a word at a time. */
|
||||
while (UNALIGNED (str))
|
||||
{
|
||||
if (!*str)
|
||||
return str - start;
|
||||
str++;
|
||||
}
|
||||
|
||||
/* If the string is word-aligned, we can check for the presence of
|
||||
a null in each word-sized block. */
|
||||
aligned_addr = (unsigned long *)str;
|
||||
while (!DETECTNULL (*aligned_addr))
|
||||
aligned_addr++;
|
||||
|
||||
/* Once a null is detected, we check each byte in that block for a
|
||||
precise position of the null. */
|
||||
str = (char *) aligned_addr;
|
||||
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
|
||||
while (*str)
|
||||
str++;
|
||||
return str - start;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strlwr>>---force string to lowercase
|
||||
|
||||
INDEX
|
||||
strlwr
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strlwr(char *<[a]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<strlwr>> converts each character in the string at <[a]> to
|
||||
lowercase.
|
||||
|
||||
RETURNS
|
||||
<<strlwr>> returns its argument, <[a]>.
|
||||
|
||||
PORTABILITY
|
||||
<<strlwr>> is not widely portable.
|
||||
|
||||
<<strlwr>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strlwr
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
char *
|
||||
strlwr (char *s)
|
||||
{
|
||||
unsigned char *ucs = (unsigned char *) s;
|
||||
for ( ; *ucs != '\0'; ucs++)
|
||||
{
|
||||
*ucs = tolower(*ucs);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strncasecmp>>---case-insensitive character string compare
|
||||
|
||||
INDEX
|
||||
strncasecmp
|
||||
|
||||
SYNOPSIS
|
||||
#include <strings.h>
|
||||
int strncasecmp(const char *<[a]>, const char * <[b]>, size_t <[length]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<strncasecmp>> compares up to <[length]> characters
|
||||
from the string at <[a]> to the string at <[b]> in a
|
||||
case-insensitive manner.
|
||||
|
||||
RETURNS
|
||||
|
||||
If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after
|
||||
both are converted to lowercase), <<strncasecmp>> returns a
|
||||
number greater than zero. If the two strings are equivalent,
|
||||
<<strncasecmp>> returns zero. If <<*<[a]>>> sorts
|
||||
lexicographically before <<*<[b]>>>, <<strncasecmp>> returns a
|
||||
number less than zero.
|
||||
|
||||
PORTABILITY
|
||||
<<strncasecmp>> is in the Berkeley Software Distribution.
|
||||
|
||||
<<strncasecmp>> requires no supporting OS subroutines. It uses
|
||||
tolower() from elsewhere in this library.
|
||||
|
||||
QUICKREF
|
||||
strncasecmp
|
||||
*/
|
||||
|
||||
#include <strings.h>
|
||||
#include <ctype.h>
|
||||
|
||||
int
|
||||
strncasecmp (const char *s1,
|
||||
const char *s2,
|
||||
size_t n)
|
||||
{
|
||||
int d = 0;
|
||||
for ( ; n != 0; n--)
|
||||
{
|
||||
const int c1 = tolower(*s1++);
|
||||
const int c2 = tolower(*s2++);
|
||||
if (((d = c1 - c2) != 0) || (c2 == '\0'))
|
||||
break;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strncasecmp_l>>---case-insensitive character string compare
|
||||
|
||||
INDEX
|
||||
strncasecmp_l
|
||||
|
||||
SYNOPSIS
|
||||
#include <strings.h>
|
||||
int strncasecmp_l(const char *<[a]>, const char * <[b]>,
|
||||
size_t <[length]>, locale_t <[locale]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<strncasecmp_l>> compares up to <[length]> characters
|
||||
from the string at <[a]> to the string at <[b]> in a
|
||||
case-insensitive manner.
|
||||
|
||||
if <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the
|
||||
behaviour is undefined.
|
||||
|
||||
RETURNS
|
||||
|
||||
If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after
|
||||
both are converted to lowercase), <<strncasecmp_l>> returns a
|
||||
number greater than zero. If the two strings are equivalent,
|
||||
<<strncasecmp_l>> returns zero. If <<*<[a]>>> sorts
|
||||
lexicographically before <<*<[b]>>>, <<strncasecmp_l>> returns a
|
||||
number less than zero.
|
||||
|
||||
PORTABILITY
|
||||
<<strncasecmp_l>> is POSIX-1.2008.
|
||||
|
||||
<<strncasecmp_l>> requires no supporting OS subroutines. It uses
|
||||
tolower_l() from elsewhere in this library.
|
||||
|
||||
QUICKREF
|
||||
strncasecmp_l
|
||||
*/
|
||||
|
||||
#include <strings.h>
|
||||
#include <ctype.h>
|
||||
|
||||
int
|
||||
strncasecmp_l (const char *s1, const char *s2, size_t n,
|
||||
struct __locale_t *locale)
|
||||
{
|
||||
int d = 0;
|
||||
for ( ; n != 0; n--)
|
||||
{
|
||||
const int c1 = tolower_l (*s1++, locale);
|
||||
const int c2 = tolower_l (*s2++, locale);
|
||||
if (((d = c1 - c2) != 0) || (c2 == '\0'))
|
||||
break;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strncat>>---concatenate strings
|
||||
|
||||
INDEX
|
||||
strncat
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strncat(char *restrict <[dst]>, const char *restrict <[src]>,
|
||||
size_t <[length]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<strncat>> appends not more than <[length]> characters from
|
||||
the string pointed to by <[src]> (including the terminating
|
||||
null character) to the end of the string pointed to by
|
||||
<[dst]>. The initial character of <[src]> overwrites the null
|
||||
character at the end of <[dst]>. A terminating null character
|
||||
is always appended to the result
|
||||
|
||||
WARNINGS
|
||||
Note that a null is always appended, so that if the copy is
|
||||
limited by the <[length]> argument, the number of characters
|
||||
appended to <[dst]> is <<n + 1>>.
|
||||
|
||||
RETURNS
|
||||
This function returns the initial value of <[dst]>
|
||||
|
||||
PORTABILITY
|
||||
<<strncat>> is ANSI C.
|
||||
|
||||
<<strncat>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strncat ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
/* Nonzero if X is aligned on a "long" boundary. */
|
||||
#define ALIGNED(X) \
|
||||
(((long)X & (sizeof (long) - 1)) == 0)
|
||||
|
||||
#if LONG_MAX == 2147483647L
|
||||
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
|
||||
#else
|
||||
#if LONG_MAX == 9223372036854775807L
|
||||
/* Nonzero if X (a long int) contains a NULL byte. */
|
||||
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
|
||||
#else
|
||||
#error long int is not a 32bit or 64bit type.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DETECTNULL
|
||||
#error long int is not a 32bit or 64bit byte
|
||||
#endif
|
||||
|
||||
char *
|
||||
strncat (char *__restrict s1,
|
||||
const char *__restrict s2,
|
||||
size_t n)
|
||||
{
|
||||
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
|
||||
char *s = s1;
|
||||
|
||||
while (*s1)
|
||||
s1++;
|
||||
while (n-- != 0 && (*s1++ = *s2++))
|
||||
{
|
||||
if (n == 0)
|
||||
*s1 = '\0';
|
||||
}
|
||||
|
||||
return s;
|
||||
#else
|
||||
char *s = s1;
|
||||
|
||||
/* Skip over the data in s1 as quickly as possible. */
|
||||
if (ALIGNED (s1))
|
||||
{
|
||||
unsigned long *aligned_s1 = (unsigned long *)s1;
|
||||
while (!DETECTNULL (*aligned_s1))
|
||||
aligned_s1++;
|
||||
|
||||
s1 = (char *)aligned_s1;
|
||||
}
|
||||
|
||||
while (*s1)
|
||||
s1++;
|
||||
|
||||
/* s1 now points to the its trailing null character, now copy
|
||||
up to N bytes from S2 into S1 stopping if a NULL is encountered
|
||||
in S2.
|
||||
|
||||
It is not safe to use strncpy here since it copies EXACTLY N
|
||||
characters, NULL padding if necessary. */
|
||||
while (n-- != 0 && (*s1++ = *s2++))
|
||||
{
|
||||
if (n == 0)
|
||||
*s1 = '\0';
|
||||
}
|
||||
|
||||
return s;
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strncmp>>---character string compare
|
||||
|
||||
INDEX
|
||||
strncmp
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
int strncmp(const char *<[a]>, const char * <[b]>, size_t <[length]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<strncmp>> compares up to <[length]> characters
|
||||
from the string at <[a]> to the string at <[b]>.
|
||||
|
||||
RETURNS
|
||||
If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>,
|
||||
<<strncmp>> returns a number greater than zero. If the two
|
||||
strings are equivalent, <<strncmp>> returns zero. If <<*<[a]>>>
|
||||
sorts lexicographically before <<*<[b]>>>, <<strncmp>> returns a
|
||||
number less than zero.
|
||||
|
||||
PORTABILITY
|
||||
<<strncmp>> is ANSI C.
|
||||
|
||||
<<strncmp>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strncmp ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
/* Nonzero if either X or Y is not aligned on a "long" boundary. */
|
||||
#define UNALIGNED(X, Y) \
|
||||
(((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
|
||||
|
||||
/* DETECTNULL returns nonzero if (long)X contains a NULL byte. */
|
||||
#if LONG_MAX == 2147483647L
|
||||
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
|
||||
#else
|
||||
#if LONG_MAX == 9223372036854775807L
|
||||
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
|
||||
#else
|
||||
#error long int is not a 32bit or 64bit type.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DETECTNULL
|
||||
#error long int is not a 32bit or 64bit byte
|
||||
#endif
|
||||
|
||||
int
|
||||
strncmp (const char *s1,
|
||||
const char *s2,
|
||||
size_t n)
|
||||
{
|
||||
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
|
||||
if (n == 0)
|
||||
return 0;
|
||||
|
||||
while (n-- != 0 && *s1 == *s2)
|
||||
{
|
||||
if (n == 0 || *s1 == '\0')
|
||||
break;
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return (*(unsigned char *) s1) - (*(unsigned char *) s2);
|
||||
#else
|
||||
unsigned long *a1;
|
||||
unsigned long *a2;
|
||||
|
||||
if (n == 0)
|
||||
return 0;
|
||||
|
||||
/* If s1 or s2 are unaligned, then compare bytes. */
|
||||
if (!UNALIGNED (s1, s2))
|
||||
{
|
||||
/* If s1 and s2 are word-aligned, compare them a word at a time. */
|
||||
a1 = (unsigned long*)s1;
|
||||
a2 = (unsigned long*)s2;
|
||||
while (n >= sizeof (long) && *a1 == *a2)
|
||||
{
|
||||
n -= sizeof (long);
|
||||
|
||||
/* If we've run out of bytes or hit a null, return zero
|
||||
since we already know *a1 == *a2. */
|
||||
if (n == 0 || DETECTNULL (*a1))
|
||||
return 0;
|
||||
|
||||
a1++;
|
||||
a2++;
|
||||
}
|
||||
|
||||
/* A difference was detected in last few bytes of s1, so search bytewise */
|
||||
s1 = (char*)a1;
|
||||
s2 = (char*)a2;
|
||||
}
|
||||
|
||||
while (n-- > 0 && *s1 == *s2)
|
||||
{
|
||||
/* If we've run out of bytes or hit a null, return zero
|
||||
since we already know *s1 == *s2. */
|
||||
if (n == 0 || *s1 == '\0')
|
||||
return 0;
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
return (*(unsigned char *) s1) - (*(unsigned char *) s2);
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strncpy>>---counted copy string
|
||||
|
||||
INDEX
|
||||
strncpy
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strncpy(char *restrict <[dst]>, const char *restrict <[src]>,
|
||||
size_t <[length]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<strncpy>> copies not more than <[length]> characters from the
|
||||
the string pointed to by <[src]> (including the terminating
|
||||
null character) to the array pointed to by <[dst]>. If the
|
||||
string pointed to by <[src]> is shorter than <[length]>
|
||||
characters, null characters are appended to the destination
|
||||
array until a total of <[length]> characters have been
|
||||
written.
|
||||
|
||||
RETURNS
|
||||
This function returns the initial value of <[dst]>.
|
||||
|
||||
PORTABILITY
|
||||
<<strncpy>> is ANSI C.
|
||||
|
||||
<<strncpy>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strncpy ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
/*SUPPRESS 560*/
|
||||
/*SUPPRESS 530*/
|
||||
|
||||
/* Nonzero if either X or Y is not aligned on a "long" boundary. */
|
||||
#define UNALIGNED(X, Y) \
|
||||
(((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
|
||||
|
||||
#if LONG_MAX == 2147483647L
|
||||
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
|
||||
#else
|
||||
#if LONG_MAX == 9223372036854775807L
|
||||
/* Nonzero if X (a long int) contains a NULL byte. */
|
||||
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
|
||||
#else
|
||||
#error long int is not a 32bit or 64bit type.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DETECTNULL
|
||||
#error long int is not a 32bit or 64bit byte
|
||||
#endif
|
||||
|
||||
#define TOO_SMALL(LEN) ((LEN) < sizeof (long))
|
||||
|
||||
char *
|
||||
strncpy (char *__restrict dst0,
|
||||
const char *__restrict src0,
|
||||
size_t count)
|
||||
{
|
||||
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
|
||||
char *dscan;
|
||||
const char *sscan;
|
||||
|
||||
dscan = dst0;
|
||||
sscan = src0;
|
||||
while (count > 0)
|
||||
{
|
||||
--count;
|
||||
if ((*dscan++ = *sscan++) == '\0')
|
||||
break;
|
||||
}
|
||||
while (count-- > 0)
|
||||
*dscan++ = '\0';
|
||||
|
||||
return dst0;
|
||||
#else
|
||||
char *dst = dst0;
|
||||
const char *src = src0;
|
||||
long *aligned_dst;
|
||||
const long *aligned_src;
|
||||
|
||||
/* If SRC and DEST is aligned and count large enough, then copy words. */
|
||||
if (!UNALIGNED (src, dst) && !TOO_SMALL (count))
|
||||
{
|
||||
aligned_dst = (long*)dst;
|
||||
aligned_src = (long*)src;
|
||||
|
||||
/* SRC and DEST are both "long int" aligned, try to do "long int"
|
||||
sized copies. */
|
||||
while (count >= sizeof (long int) && !DETECTNULL(*aligned_src))
|
||||
{
|
||||
count -= sizeof (long int);
|
||||
*aligned_dst++ = *aligned_src++;
|
||||
}
|
||||
|
||||
dst = (char*)aligned_dst;
|
||||
src = (char*)aligned_src;
|
||||
}
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
--count;
|
||||
if ((*dst++ = *src++) == '\0')
|
||||
break;
|
||||
}
|
||||
|
||||
while (count-- > 0)
|
||||
*dst++ = '\0';
|
||||
|
||||
return dst0;
|
||||
#endif /* not PREFER_SIZE_OVER_SPEED */
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef _REENT_ONLY
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <reent.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strndup (const char *str,
|
||||
size_t n)
|
||||
{
|
||||
return _strndup_r (_REENT, str, n);
|
||||
}
|
||||
|
||||
#endif /* !_REENT_ONLY */
|
||||
@@ -0,0 +1,26 @@
|
||||
#include <reent.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
_strndup_r (struct _reent *reent_ptr,
|
||||
const char *str,
|
||||
size_t n)
|
||||
{
|
||||
const char *ptr = str;
|
||||
size_t len;
|
||||
char *copy;
|
||||
|
||||
while (n-- > 0 && *ptr)
|
||||
ptr++;
|
||||
|
||||
len = ptr - str;
|
||||
|
||||
copy = _malloc_r (reent_ptr, len + 1);
|
||||
if (copy)
|
||||
{
|
||||
memcpy (copy, str, len);
|
||||
copy[len] = '\0';
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strnlen>>---character string length
|
||||
|
||||
INDEX
|
||||
strnlen
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
size_t strnlen(const char *<[str]>, size_t <[n]>);
|
||||
|
||||
DESCRIPTION
|
||||
The <<strnlen>> function works out the length of the string
|
||||
starting at <<*<[str]>>> by counting chararacters until it
|
||||
reaches a NUL character or the maximum: <[n]> number of
|
||||
characters have been inspected.
|
||||
|
||||
RETURNS
|
||||
<<strnlen>> returns the character count or <[n]>.
|
||||
|
||||
PORTABILITY
|
||||
<<strnlen>> is a GNU extension.
|
||||
|
||||
<<strnlen>> requires no supporting OS subroutines.
|
||||
|
||||
*/
|
||||
|
||||
#undef __STRICT_ANSI__
|
||||
#include <_ansi.h>
|
||||
#include <string.h>
|
||||
|
||||
size_t
|
||||
strnlen (const char *str,
|
||||
size_t n)
|
||||
{
|
||||
const char *start = str;
|
||||
|
||||
while (n-- > 0 && *str)
|
||||
str++;
|
||||
|
||||
return str - start;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strnstr>>---find string segment
|
||||
|
||||
INDEX
|
||||
strnstr
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
size_t strnstr(const char *<[s1]>, const char *<[s2]>, size_t <[n]>);
|
||||
|
||||
DESCRIPTION
|
||||
Locates the first occurrence in the string pointed to by <[s1]> of
|
||||
the sequence of limited to the <[n]> characters in the string
|
||||
pointed to by <[s2]>
|
||||
|
||||
RETURNS
|
||||
Returns a pointer to the located string segment, or a null
|
||||
pointer if the string <[s2]> is not found. If <[s2]> points to
|
||||
a string with zero length, <[s1]> is returned.
|
||||
|
||||
|
||||
PORTABILITY
|
||||
<<strnstr>> is a BSD extension.
|
||||
|
||||
<<strnstr>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strnstr pure
|
||||
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Find the first occurrence of find in s, where the search is limited to the
|
||||
* first slen characters of s.
|
||||
*/
|
||||
char *
|
||||
strnstr(const char *haystack, const char *needle, size_t haystack_len)
|
||||
{
|
||||
size_t needle_len = strnlen(needle, haystack_len);
|
||||
|
||||
if (needle_len < haystack_len || !needle[needle_len]) {
|
||||
char *x = memmem(haystack, haystack_len, needle, needle_len);
|
||||
if (x && !memchr(haystack, 0, x - haystack))
|
||||
return x;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strpbrk>>---find characters in string
|
||||
|
||||
INDEX
|
||||
strpbrk
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strpbrk(const char *<[s1]>, const char *<[s2]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function locates the first occurence in the string
|
||||
pointed to by <[s1]> of any character in string pointed to by
|
||||
<[s2]> (excluding the terminating null character).
|
||||
|
||||
RETURNS
|
||||
<<strpbrk>> returns a pointer to the character found in <[s1]>, or a
|
||||
null pointer if no character from <[s2]> occurs in <[s1]>.
|
||||
|
||||
PORTABILITY
|
||||
<<strpbrk>> requires no supporting OS subroutines.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strpbrk (const char *s1,
|
||||
const char *s2)
|
||||
{
|
||||
const char *c = s2;
|
||||
if (!*s1)
|
||||
return (char *) NULL;
|
||||
|
||||
while (*s1)
|
||||
{
|
||||
for (c = s2; *c; c++)
|
||||
{
|
||||
if (*s1 == *c)
|
||||
break;
|
||||
}
|
||||
if (*c)
|
||||
break;
|
||||
s1++;
|
||||
}
|
||||
|
||||
if (*c == '\0')
|
||||
s1 = NULL;
|
||||
|
||||
return (char *) s1;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strrchr>>---reverse search for character in string
|
||||
|
||||
INDEX
|
||||
strrchr
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
char * strrchr(const char *<[string]>, int <[c]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function finds the last occurence of <[c]> (converted to
|
||||
a char) in the string pointed to by <[string]> (including the
|
||||
terminating null character).
|
||||
|
||||
RETURNS
|
||||
Returns a pointer to the located character, or a null pointer
|
||||
if <[c]> does not occur in <[string]>.
|
||||
|
||||
PORTABILITY
|
||||
<<strrchr>> is ANSI C.
|
||||
|
||||
<<strrchr>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strrchr ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strrchr (const char *s,
|
||||
int i)
|
||||
{
|
||||
const char *last = NULL;
|
||||
char c = i;
|
||||
|
||||
if (c)
|
||||
{
|
||||
while ((s=strchr(s, c)))
|
||||
{
|
||||
last = s;
|
||||
s++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
last = strchr(s, c);
|
||||
}
|
||||
|
||||
return (char *) last;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/* BSD strsep function */
|
||||
|
||||
/* Copyright 2002, Red Hat Inc. */
|
||||
|
||||
/* undef STRICT_ANSI so that strsep prototype will be defined */
|
||||
#undef __STRICT_ANSI__
|
||||
#include <string.h>
|
||||
#include <_ansi.h>
|
||||
#include <reent.h>
|
||||
|
||||
extern char *__strtok_r (char *, const char *, char **, int);
|
||||
|
||||
char *
|
||||
strsep (register char **source_ptr,
|
||||
register const char *delim)
|
||||
{
|
||||
return __strtok_r (*source_ptr, delim, source_ptr, 0);
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strsignal>>---convert signal number to string
|
||||
|
||||
INDEX
|
||||
strsignal
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strsignal(int <[signal]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<strsignal>> converts the signal number <[signal]> into a
|
||||
string. If <[signal]> is not a known signal number, the result
|
||||
will be of the form "Unknown signal NN" where NN is the <[signal]>
|
||||
is a decimal number.
|
||||
|
||||
RETURNS
|
||||
This function returns a pointer to a string. Your application must
|
||||
not modify that string.
|
||||
|
||||
PORTABILITY
|
||||
POSIX.1-2008 C requires <<strsignal>>, but does not specify the strings used
|
||||
for each signal number.
|
||||
|
||||
<<strsignal>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strsignal pure
|
||||
*/
|
||||
|
||||
/*
|
||||
* Written by Joel Sherrill <joel.sherrill@OARcorp.com>.
|
||||
*
|
||||
* COPYRIGHT (c) 2010, 2017.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose without fee is hereby granted, provided that this entire notice
|
||||
* is included in all copies of any software which is or includes a copy
|
||||
* or modification of this software.
|
||||
*
|
||||
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
|
||||
* WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION
|
||||
* OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS
|
||||
* SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <reent.h>
|
||||
|
||||
#ifdef _REENT_THREAD_LOCAL
|
||||
_Thread_local char _tls_signal_buf[_REENT_SIGNAL_SIZE];
|
||||
#endif
|
||||
|
||||
char *
|
||||
strsignal (int signal)
|
||||
{
|
||||
char *buffer;
|
||||
struct _reent *ptr;
|
||||
|
||||
ptr = _REENT;
|
||||
|
||||
_REENT_CHECK_SIGNAL_BUF(ptr);
|
||||
buffer = _REENT_SIGNAL_BUF(ptr);
|
||||
|
||||
#if defined(SIGRTMIN) && defined(SIGRTMAX)
|
||||
if ((signal >= SIGRTMIN) && (signal <= SIGRTMAX)) {
|
||||
siprintf (buffer, "Real-time signal %d", signal - SIGRTMIN);
|
||||
return buffer;
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (signal) {
|
||||
#ifdef SIGHUP
|
||||
case SIGHUP:
|
||||
buffer = "Hangup";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGINT
|
||||
case SIGINT:
|
||||
buffer = "Interrupt";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGQUIT
|
||||
case SIGQUIT:
|
||||
buffer = "Quit";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGILL
|
||||
case SIGILL:
|
||||
buffer = "Illegal instruction";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGTRAP
|
||||
case SIGTRAP:
|
||||
buffer = "Trace/breakpoint trap";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGIOT
|
||||
#if defined(SIGABRT) && (SIGIOT != SIGABRT)
|
||||
case SIGABRT:
|
||||
#endif
|
||||
case SIGIOT:
|
||||
buffer = "IOT trap";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGEMT
|
||||
case SIGEMT:
|
||||
buffer = "EMT trap";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGFPE
|
||||
case SIGFPE:
|
||||
buffer = "Floating point exception";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGKILL
|
||||
case SIGKILL:
|
||||
buffer = "Killed";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGBUS
|
||||
case SIGBUS:
|
||||
buffer = "Bus error";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGSEGV
|
||||
case SIGSEGV:
|
||||
buffer = "Segmentation fault";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGSYS
|
||||
case SIGSYS:
|
||||
buffer = "Bad system call";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGPIPE
|
||||
case SIGPIPE:
|
||||
buffer = "Broken pipe";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGALRM
|
||||
case SIGALRM:
|
||||
buffer = "Alarm clock";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGTERM
|
||||
case SIGTERM:
|
||||
buffer = "Terminated";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGURG
|
||||
case SIGURG:
|
||||
buffer = "Urgent I/O condition";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGSTOP
|
||||
case SIGSTOP:
|
||||
buffer = "Stopped (signal)";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGTSTP
|
||||
case SIGTSTP:
|
||||
buffer = "Stopped";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGCONT
|
||||
case SIGCONT:
|
||||
buffer = "Continued";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGCHLD
|
||||
#if defined(SIGCLD) && (SIGCHLD != SIGCLD)
|
||||
case SIGCLD:
|
||||
#endif
|
||||
case SIGCHLD:
|
||||
buffer = "Child exited";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGTTIN
|
||||
case SIGTTIN:
|
||||
buffer = "Stopped (tty input)";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGTTOUT
|
||||
case SIGTTOUT:
|
||||
buffer = "Stopped (tty output)";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGIO
|
||||
#if defined(SIGPOLL) && (SIGIO != SIGPOLL)
|
||||
case SIGPOLL:
|
||||
#endif
|
||||
case SIGIO:
|
||||
buffer = "I/O possible";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGWINCH
|
||||
case SIGWINCH:
|
||||
buffer = "Window changed";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGUSR1
|
||||
case SIGUSR1:
|
||||
buffer = "User defined signal 1";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGUSR2
|
||||
case SIGUSR2:
|
||||
buffer = "User defined signal 2";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGPWR
|
||||
case SIGPWR:
|
||||
buffer = "Power Failure";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGXCPU
|
||||
case SIGXCPU:
|
||||
buffer = "CPU time limit exceeded";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGXFSZ
|
||||
case SIGXFSZ:
|
||||
buffer = "File size limit exceeded";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGVTALRM
|
||||
case SIGVTALRM :
|
||||
buffer = "Virtual timer expired";
|
||||
break;
|
||||
#endif
|
||||
#ifdef SIGPROF
|
||||
case SIGPROF:
|
||||
buffer = "Profiling timer expired";
|
||||
break;
|
||||
#endif
|
||||
#if defined(SIGLOST) && SIGLOST != SIGPWR
|
||||
case SIGLOST:
|
||||
buffer = "Resource lost";
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
siprintf (buffer, "Unknown signal %d", signal);
|
||||
break;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strspn>>---find initial match
|
||||
|
||||
INDEX
|
||||
strspn
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
size_t strspn(const char *<[s1]>, const char *<[s2]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function computes the length of the initial segment of
|
||||
the string pointed to by <[s1]> which consists entirely of
|
||||
characters from the string pointed to by <[s2]> (excluding the
|
||||
terminating null character).
|
||||
|
||||
RETURNS
|
||||
<<strspn>> returns the length of the segment found.
|
||||
|
||||
PORTABILITY
|
||||
<<strspn>> is ANSI C.
|
||||
|
||||
<<strspn>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strspn ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t
|
||||
strspn (const char *s1,
|
||||
const char *s2)
|
||||
{
|
||||
const char *s = s1;
|
||||
const char *c;
|
||||
|
||||
while (*s1)
|
||||
{
|
||||
for (c = s2; *c; c++)
|
||||
{
|
||||
if (*s1 == *c)
|
||||
break;
|
||||
}
|
||||
if (*c == '\0')
|
||||
break;
|
||||
s1++;
|
||||
}
|
||||
|
||||
return s1 - s;
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
/* Optimized strstr function.
|
||||
Copyright (c) 2018 Arm Ltd. All rights reserved.
|
||||
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. The name of the company may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
||||
|
||||
/*
|
||||
FUNCTION
|
||||
<<strstr>>---find string segment
|
||||
|
||||
INDEX
|
||||
strstr
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strstr(const char *<[s1]>, const char *<[s2]>);
|
||||
|
||||
DESCRIPTION
|
||||
Locates the first occurrence in the string pointed to by <[s1]> of
|
||||
the sequence of characters in the string pointed to by <[s2]>
|
||||
(excluding the terminating null character).
|
||||
|
||||
RETURNS
|
||||
Returns a pointer to the located string segment, or a null
|
||||
pointer if the string <[s2]> is not found. If <[s2]> points to
|
||||
a string with zero length, <[s1]> is returned.
|
||||
|
||||
PORTABILITY
|
||||
<<strstr>> is ANSI C.
|
||||
|
||||
<<strstr>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strstr ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) \
|
||||
|| CHAR_BIT > 8
|
||||
|
||||
/* Small and efficient strstr implementation. */
|
||||
char *
|
||||
strstr (const char *hs, const char *ne)
|
||||
{
|
||||
size_t i;
|
||||
int c = ne[0];
|
||||
|
||||
if (c == 0)
|
||||
return (char*)hs;
|
||||
|
||||
for ( ; hs[0] != '\0'; hs++)
|
||||
{
|
||||
if (hs[0] != c)
|
||||
continue;
|
||||
for (i = 1; ne[i] != 0; i++)
|
||||
if (hs[i] != ne[i])
|
||||
break;
|
||||
if (ne[i] == '\0')
|
||||
return (char*)hs;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#else /* compilation for speed */
|
||||
|
||||
# define RETURN_TYPE char *
|
||||
# define AVAILABLE(h, h_l, j, n_l) (((j) <= (h_l) - (n_l)) \
|
||||
|| ((h_l) += strnlen ((const char *) (h) + (h_l), (n_l) | 2048), ((j) <= (h_l) - (n_l))))
|
||||
|
||||
# include "str-two-way.h"
|
||||
|
||||
/* Number of bits used to index shift table. */
|
||||
#define SHIFT_TABLE_BITS 6
|
||||
|
||||
static inline char *
|
||||
strstr2 (const unsigned char *hs, const unsigned char *ne)
|
||||
{
|
||||
uint32_t h1 = (ne[0] << 16) | ne[1];
|
||||
uint32_t h2 = 0;
|
||||
int c;
|
||||
for (c = hs[0]; h1 != h2 && c != 0; c = *++hs)
|
||||
h2 = (h2 << 16) | c;
|
||||
return h1 == h2 ? (char *)hs - 2 : NULL;
|
||||
}
|
||||
|
||||
static inline char *
|
||||
strstr3 (const unsigned char *hs, const unsigned char *ne)
|
||||
{
|
||||
uint32_t h1 = (ne[0] << 24) | (ne[1] << 16) | (ne[2] << 8);
|
||||
uint32_t h2 = 0;
|
||||
int c;
|
||||
for (c = hs[0]; h1 != h2 && c != 0; c = *++hs)
|
||||
h2 = (h2 | c) << 8;
|
||||
return h1 == h2 ? (char *)hs - 3 : NULL;
|
||||
}
|
||||
|
||||
static inline char *
|
||||
strstr4 (const unsigned char *hs, const unsigned char *ne)
|
||||
{
|
||||
uint32_t h1 = (ne[0] << 24) | (ne[1] << 16) | (ne[2] << 8) | ne[3];
|
||||
uint32_t h2 = 0;
|
||||
int c;
|
||||
for (c = hs[0]; c != 0 && h1 != h2; c = *++hs)
|
||||
h2 = (h2 << 8) | c;
|
||||
return h1 == h2 ? (char *)hs - 4 : NULL;
|
||||
}
|
||||
|
||||
/* Extremely fast strstr algorithm with guaranteed linear-time performance.
|
||||
Small needles up to size 4 use a dedicated linear search. Longer needles
|
||||
up to size 254 use Sunday's Quick-Search algorithm. Due to its simplicity
|
||||
it has the best average performance of string matching algorithms on almost
|
||||
all inputs. It uses a bad-character shift table to skip past mismatches.
|
||||
By limiting the needle length to 254, the shift table can be reduced to 8
|
||||
bits per entry, lowering preprocessing overhead and minimizing cache effects.
|
||||
The limit also implies the worst-case performance is linear.
|
||||
Even larger needles are processed by the linear-time Two-Way algorithm.
|
||||
*/
|
||||
char *
|
||||
strstr (const char *haystack, const char *needle)
|
||||
{
|
||||
const unsigned char *hs = (const unsigned char *) haystack;
|
||||
const unsigned char *ne = (const unsigned char *) needle;
|
||||
int i;
|
||||
|
||||
/* Handle short needle special cases first. */
|
||||
if (ne[0] == '\0')
|
||||
return (char *) hs;
|
||||
if (ne[1] == '\0')
|
||||
return (char*)strchr ((const char *) hs, ne[0]);
|
||||
if (ne[2] == '\0')
|
||||
return strstr2 (hs, ne);
|
||||
if (ne[3] == '\0')
|
||||
return strstr3 (hs, ne);
|
||||
if (ne[4] == '\0')
|
||||
return strstr4 (hs, ne);
|
||||
|
||||
size_t ne_len = strlen ((const char *) ne);
|
||||
size_t hs_len = strnlen ((const char *) hs, ne_len | 512);
|
||||
|
||||
/* Ensure haystack length is >= needle length. */
|
||||
if (hs_len < ne_len)
|
||||
return NULL;
|
||||
|
||||
/* Use the Quick-Search algorithm for needle lengths less than 255. */
|
||||
if (__builtin_expect (ne_len < 255, 1))
|
||||
{
|
||||
uint8_t shift[1 << SHIFT_TABLE_BITS];
|
||||
const unsigned char *end = hs + hs_len - ne_len;
|
||||
|
||||
/* Initialize bad character shift hash table. */
|
||||
memset (shift, ne_len + 1, sizeof (shift));
|
||||
for (i = 0; i < ne_len; i++)
|
||||
shift[ne[i] % sizeof (shift)] = ne_len - i;
|
||||
|
||||
do
|
||||
{
|
||||
hs--;
|
||||
|
||||
/* Search by skipping past bad characters. */
|
||||
size_t tmp = shift[hs[ne_len] % sizeof (shift)];
|
||||
for (hs += tmp; hs <= end; hs += tmp)
|
||||
{
|
||||
tmp = shift[hs[ne_len] % sizeof (shift)];
|
||||
if (memcmp (hs, ne, ne_len) == 0)
|
||||
return (char*) hs;
|
||||
}
|
||||
if (end[ne_len] == 0)
|
||||
return NULL;
|
||||
end += strnlen ((const char *) (end + ne_len), 2048);
|
||||
}
|
||||
while (hs <= end);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Use Two-Way algorithm for very long needles. */
|
||||
return two_way_long_needle (hs, hs_len, ne, ne_len);
|
||||
}
|
||||
#endif /* compilation for speed */
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strtok>>, <<strtok_r>>, <<strsep>>---get next token from a string
|
||||
|
||||
INDEX
|
||||
strtok
|
||||
|
||||
INDEX
|
||||
strtok_r
|
||||
|
||||
INDEX
|
||||
strsep
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strtok(char *restrict <[source]>,
|
||||
const char *restrict <[delimiters]>);
|
||||
char *strtok_r(char *restrict <[source]>,
|
||||
const char *restrict <[delimiters]>,
|
||||
char **<[lasts]>);
|
||||
char *strsep(char **<[source_ptr]>, const char *<[delimiters]>);
|
||||
|
||||
DESCRIPTION
|
||||
The <<strtok>> function is used to isolate sequential tokens in a
|
||||
null-terminated string, <<*<[source]>>>. These tokens are delimited
|
||||
in the string by at least one of the characters in <<*<[delimiters]>>>.
|
||||
The first time that <<strtok>> is called, <<*<[source]>>> should be
|
||||
specified; subsequent calls, wishing to obtain further tokens from
|
||||
the same string, should pass a null pointer instead. The separator
|
||||
string, <<*<[delimiters]>>>, must be supplied each time and may
|
||||
change between calls.
|
||||
|
||||
The <<strtok>> function returns a pointer to the beginning of each
|
||||
subsequent token in the string, after replacing the separator
|
||||
character itself with a null character. When no more tokens remain,
|
||||
a null pointer is returned.
|
||||
|
||||
The <<strtok_r>> function has the same behavior as <<strtok>>, except
|
||||
a pointer to placeholder <<*<[lasts]>>> must be supplied by the caller.
|
||||
|
||||
The <<strsep>> function is similar in behavior to <<strtok>>, except
|
||||
a pointer to the string pointer must be supplied <<<[source_ptr]>>> and
|
||||
the function does not skip leading delimiters. When the string starts
|
||||
with a delimiter, the delimiter is changed to the null character and
|
||||
the empty string is returned. Like <<strtok_r>> and <<strtok>>, the
|
||||
<<*<[source_ptr]>>> is updated to the next character following the
|
||||
last delimiter found or NULL if the end of string is reached with
|
||||
no more delimiters.
|
||||
|
||||
RETURNS
|
||||
<<strtok>>, <<strtok_r>>, and <<strsep>> all return a pointer to the
|
||||
next token, or <<NULL>> if no more tokens can be found. For
|
||||
<<strsep>>, a token may be the empty string.
|
||||
|
||||
NOTES
|
||||
<<strtok>> is unsafe for multi-threaded applications. <<strtok_r>>
|
||||
and <<strsep>> are thread-safe and should be used instead.
|
||||
|
||||
PORTABILITY
|
||||
<<strtok>> is ANSI C.
|
||||
<<strtok_r>> is POSIX.
|
||||
<<strsep>> is a BSD extension.
|
||||
|
||||
<<strtok>>, <<strtok_r>>, and <<strsep>> require no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strtok ansi impure
|
||||
*/
|
||||
|
||||
/* undef STRICT_ANSI so that strtok_r prototype will be defined */
|
||||
#undef __STRICT_ANSI__
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <_ansi.h>
|
||||
#include <reent.h>
|
||||
|
||||
#ifdef _REENT_THREAD_LOCAL
|
||||
_Thread_local char *_tls_strtok_last;
|
||||
#endif
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
|
||||
extern char *__strtok_r (char *, const char *, char **, int);
|
||||
|
||||
char *
|
||||
strtok (register char *__restrict s,
|
||||
register const char *__restrict delim)
|
||||
{
|
||||
struct _reent *reent = _REENT;
|
||||
|
||||
_REENT_CHECK_MISC(reent);
|
||||
return __strtok_r (s, delim, &(_REENT_STRTOK_LAST(reent)), 1);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (c) 1988 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
__strtok_r (register char *s,
|
||||
register const char *delim,
|
||||
char **lasts,
|
||||
int skip_leading_delim)
|
||||
{
|
||||
register char *spanp;
|
||||
register int c, sc;
|
||||
char *tok;
|
||||
|
||||
|
||||
if (s == NULL && (s = *lasts) == NULL)
|
||||
return (NULL);
|
||||
|
||||
/*
|
||||
* Skip (span) leading delimiters (s += strspn(s, delim), sort of).
|
||||
*/
|
||||
cont:
|
||||
c = *s++;
|
||||
for (spanp = (char *)delim; (sc = *spanp++) != 0;) {
|
||||
if (c == sc) {
|
||||
if (skip_leading_delim) {
|
||||
goto cont;
|
||||
}
|
||||
else {
|
||||
*lasts = s;
|
||||
s[-1] = 0;
|
||||
return (s - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (c == 0) { /* no non-delimiter characters */
|
||||
*lasts = NULL;
|
||||
return (NULL);
|
||||
}
|
||||
tok = s - 1;
|
||||
|
||||
/*
|
||||
* Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
|
||||
* Note that delim must have one NUL; we stop if we see that, too.
|
||||
*/
|
||||
for (;;) {
|
||||
c = *s++;
|
||||
spanp = (char *)delim;
|
||||
do {
|
||||
if ((sc = *spanp++) == c) {
|
||||
if (c == 0)
|
||||
s = NULL;
|
||||
else
|
||||
s[-1] = 0;
|
||||
*lasts = s;
|
||||
return (tok);
|
||||
}
|
||||
} while (sc != 0);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
char *
|
||||
strtok_r (register char *__restrict s,
|
||||
register const char *__restrict delim,
|
||||
char **__restrict lasts)
|
||||
{
|
||||
return __strtok_r (s, delim, lasts, 1);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strupr>>---force string to uppercase
|
||||
|
||||
INDEX
|
||||
strupr
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
char *strupr(char *<[a]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<strupr>> converts each character in the string at <[a]> to
|
||||
uppercase.
|
||||
|
||||
RETURNS
|
||||
<<strupr>> returns its argument, <[a]>.
|
||||
|
||||
PORTABILITY
|
||||
<<strupr>> is not widely portable.
|
||||
|
||||
<<strupr>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strupr
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
char *
|
||||
strupr (char *s)
|
||||
{
|
||||
unsigned char *ucs = (unsigned char *) s;
|
||||
for ( ; *ucs != '\0'; ucs++)
|
||||
{
|
||||
*ucs = toupper(*ucs);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strverscmp>>---version string compare
|
||||
|
||||
INDEX
|
||||
strverscmp
|
||||
|
||||
SYNOPSIS
|
||||
#define _GNU_SOURCE
|
||||
#include <string.h>
|
||||
int strverscmp(const char *<[a]>, const char *<[b]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<strverscmp>> compares the string at <[a]> to
|
||||
the string at <[b]> in a version-logical order.
|
||||
|
||||
RETURNS
|
||||
|
||||
If <<*<[a]>>> version-sorts after <<*<[b]>>>, <<strverscmp>> returns
|
||||
a number greater than zero. If the two strings match, <<strverscmp>>
|
||||
returns zero. If <<*<[a]>>> version-sorts before <<*<[b]>>>,
|
||||
<<strverscmp>> returns a number less than zero.
|
||||
|
||||
PORTABILITY
|
||||
<<strverscmp>> is a GNU extension.
|
||||
|
||||
<<strverscmp>> requires no supporting OS subroutines. It uses
|
||||
isdigit() from elsewhere in this library.
|
||||
|
||||
QUICKREF
|
||||
strverscmp
|
||||
*/
|
||||
|
||||
/*
|
||||
From musl src/string/strverscmp.c
|
||||
|
||||
Copyright © 2005-2014 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.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
int strverscmp(const char *l0, const char *r0)
|
||||
{
|
||||
const unsigned char *l = (const void *)l0;
|
||||
const unsigned char *r = (const void *)r0;
|
||||
size_t i, dp, j;
|
||||
int z = 1;
|
||||
|
||||
/* Find maximal matching prefix and track its maximal digit
|
||||
* suffix and whether those digits are all zeros. */
|
||||
for (dp=i=0; l[i]==r[i]; i++) {
|
||||
int c = l[i];
|
||||
if (!c) return 0;
|
||||
if (!isdigit(c)) dp=i+1, z=1;
|
||||
else if (c!='0') z=0;
|
||||
}
|
||||
|
||||
if (l[dp]!='0' && r[dp]!='0') {
|
||||
/* If we're not looking at a digit sequence that began
|
||||
* with a zero, longest digit string is greater. */
|
||||
for (j=i; isdigit(l[j]); j++)
|
||||
if (!isdigit(r[j])) return 1;
|
||||
if (isdigit(r[j])) return -1;
|
||||
} else if (z && dp<i && (isdigit(l[i]) || isdigit(r[i]))) {
|
||||
/* Otherwise, if common prefix of digit sequence is
|
||||
* all zeros, digits order less than non-digits. */
|
||||
return (unsigned char)(l[i]-'0') - (unsigned char)(r[i]-'0');
|
||||
}
|
||||
|
||||
return l[i] - r[i];
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strxfrm>>---transform string
|
||||
|
||||
INDEX
|
||||
strxfrm
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
size_t strxfrm(char *restrict <[s1]>, const char *restrict <[s2]>,
|
||||
size_t <[n]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function transforms the string pointed to by <[s2]> and
|
||||
places the resulting string into the array pointed to by
|
||||
<[s1]>. The transformation is such that if the <<strcmp>>
|
||||
function is applied to the two transformed strings, it returns
|
||||
a value greater than, equal to, or less than zero,
|
||||
correspoinding to the result of a <<strcoll>> function applied
|
||||
to the same two original strings.
|
||||
|
||||
No more than <[n]> characters are placed into the resulting
|
||||
array pointed to by <[s1]>, including the terminating null
|
||||
character. If <[n]> is zero, <[s1]> may be a null pointer. If
|
||||
copying takes place between objects that overlap, the behavior
|
||||
is undefined.
|
||||
|
||||
(NOT Cygwin:) The current implementation of <<strxfrm>> simply copies
|
||||
the input and does not support any language-specific transformations.
|
||||
|
||||
RETURNS
|
||||
The <<strxfrm>> function returns the length of the transformed string
|
||||
(not including the terminating null character). If the value returned
|
||||
is <[n]> or more, the contents of the array pointed to by
|
||||
<[s1]> are indeterminate.
|
||||
|
||||
PORTABILITY
|
||||
<<strxfrm>> is ANSI C.
|
||||
|
||||
<<strxfrm>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strxfrm ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t
|
||||
strxfrm (char *__restrict s1,
|
||||
const char *__restrict s2,
|
||||
size_t n)
|
||||
{
|
||||
size_t res;
|
||||
res = 0;
|
||||
while (n-- > 0)
|
||||
{
|
||||
if ((*s1++ = *s2++) != '\0')
|
||||
++res;
|
||||
else
|
||||
return res;
|
||||
}
|
||||
while (*s2)
|
||||
{
|
||||
++s2;
|
||||
++res;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strxfrm_l>>---transform string
|
||||
|
||||
INDEX
|
||||
strxfrm_l
|
||||
|
||||
SYNOPSIS
|
||||
#include <string.h>
|
||||
size_t strxfrm_l(char *restrict <[s1]>, const char *restrict <[s2]>,
|
||||
size_t <[n]>, locale_t <[locale]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function transforms the string pointed to by <[s2]> and
|
||||
places the resulting string into the array pointed to by
|
||||
<[s1]>. The transformation is such that if the <<strcmp>>
|
||||
function is applied to the two transformed strings, it returns
|
||||
a value greater than, equal to, or less than zero,
|
||||
correspoinding to the result of a <<strcoll>> function applied
|
||||
to the same two original strings.
|
||||
|
||||
No more than <[n]> characters are placed into the resulting
|
||||
array pointed to by <[s1]>, including the terminating null
|
||||
character. If <[n]> is zero, <[s1]> may be a null pointer. If
|
||||
copying takes place between objects that overlap, the behavior
|
||||
is undefined.
|
||||
|
||||
(NOT Cygwin:) The current implementation of <<strxfrm_l>> simply copies
|
||||
the input and does not support any language-specific transformations.
|
||||
|
||||
If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the
|
||||
behaviour is undefined.
|
||||
|
||||
RETURNS
|
||||
The <<strxfrm_l>> function returns the length of the transformed string
|
||||
(not including the terminating null character). If the value returned
|
||||
is <[n]> or more, the contents of the array pointed to by
|
||||
<[s1]> are indeterminate.
|
||||
|
||||
PORTABILITY
|
||||
<<strxfrm_l>> is POSIX-1.2008.
|
||||
|
||||
<<strxfrm_l>> requires no supporting OS subroutines.
|
||||
|
||||
QUICKREF
|
||||
strxfrm_l ansi pure
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t
|
||||
strxfrm_l (char *__restrict s1, const char *__restrict s2, size_t n,
|
||||
struct __locale_t *locale)
|
||||
{
|
||||
size_t res;
|
||||
res = 0;
|
||||
while (n-- > 0)
|
||||
{
|
||||
if ((*s1++ = *s2++) != '\0')
|
||||
++res;
|
||||
else
|
||||
return res;
|
||||
}
|
||||
while (*s2)
|
||||
{
|
||||
++s2;
|
||||
++res;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<swab>>---swap adjacent bytes
|
||||
|
||||
SYNOPSIS
|
||||
#include <unistd.h>
|
||||
void swab(const void *<[in]>, void *<[out]>, ssize_t <[n]>);
|
||||
|
||||
DESCRIPTION
|
||||
This function copies <[n]> bytes from the memory region
|
||||
pointed to by <[in]> to the memory region pointed to by
|
||||
<[out]>, exchanging adjacent even and odd bytes.
|
||||
|
||||
PORTABILITY
|
||||
<<swab>> requires no supporting OS subroutines.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void
|
||||
swab (const void *b1,
|
||||
void *b2,
|
||||
ssize_t length)
|
||||
{
|
||||
const char *from = b1;
|
||||
char *to = b2;
|
||||
ssize_t ptr;
|
||||
for (ptr = 1; ptr < length; ptr += 2)
|
||||
{
|
||||
char p = from[ptr];
|
||||
char q = from[ptr-1];
|
||||
to[ptr-1] = p;
|
||||
to[ptr ] = q;
|
||||
}
|
||||
if (ptr == length) /* I.e., if length is odd, */
|
||||
to[ptr-1] = 0; /* then pad with a NUL. */
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/* $OpenBSD: timingsafe_bcmp.c,v 1.2 2014/06/10 04:17:37 deraadt Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2010 Damien Miller. All rights reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
timingsafe_bcmp(const void *b1, const void *b2, size_t n)
|
||||
{
|
||||
const unsigned char *p1 = b1, *p2 = b2;
|
||||
int ret = 0;
|
||||
|
||||
for (; n > 0; n--)
|
||||
ret |= *p1++ ^ *p2++;
|
||||
return (ret != 0);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/* $OpenBSD: timingsafe_memcmp.c,v 1.1 2014/06/13 02:12:17 matthew Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2014 Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
timingsafe_memcmp(const void *b1, const void *b2, size_t len)
|
||||
{
|
||||
const unsigned char *p1 = b1, *p2 = b2;
|
||||
size_t i;
|
||||
int res = 0, done = 0;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
/* lt is -1 if p1[i] < p2[i]; else 0. */
|
||||
int lt = (p1[i] - p2[i]) >> CHAR_BIT;
|
||||
|
||||
/* gt is -1 if p1[i] > p2[i]; else 0. */
|
||||
int gt = (p2[i] - p1[i]) >> CHAR_BIT;
|
||||
|
||||
/* cmp is 1 if p1[i] > p2[i]; -1 if p1[i] < p2[i]; else 0. */
|
||||
int cmp = lt - gt;
|
||||
|
||||
/* set res = cmp if !done. */
|
||||
res |= cmp & ~done;
|
||||
|
||||
/* set done if p1[i] != p2[i]. */
|
||||
done |= lt | gt;
|
||||
}
|
||||
|
||||
return (res);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#include <_ansi.h>
|
||||
|
||||
char *
|
||||
_user_strerror (int errnum,
|
||||
int internal,
|
||||
int *errptr)
|
||||
{
|
||||
/* prevent warning about unused parameters */
|
||||
(void) errnum;
|
||||
(void) internal;
|
||||
(void) errptr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,697 @@
|
||||
#!/usr/bin/perl
|
||||
# Uniset -- Unicode subset manager -- Markus Kuhn
|
||||
# http://www.cl.cam.ac.uk/~mgk25/download/uniset.tar.gz
|
||||
|
||||
require 5.014;
|
||||
use open ':utf8';
|
||||
use FindBin qw($RealBin); # to find directory where this file is located
|
||||
|
||||
binmode(STDOUT, ":utf8");
|
||||
binmode(STDIN, ":utf8");
|
||||
|
||||
my (%name, %invname, %category, %comment);
|
||||
|
||||
print <<End if $#ARGV < 0;
|
||||
Uniset -- Unicode subset manager -- Markus Kuhn
|
||||
|
||||
Uniset merges and subtracts Unicode subsets. It can output and
|
||||
analyse the resulting character set in various formats.
|
||||
|
||||
Uniset understand the following command-line arguments:
|
||||
|
||||
Commands to define a set of characters:
|
||||
|
||||
+ filename add the character set described in the file to the set
|
||||
- filename remove the character set described in the file from the set
|
||||
+: filename add the characters in the UTF-8 file to the set
|
||||
-: filename remove the characters in the UTF-8 file from the set
|
||||
+xxxx..yyyy add the range to the set (xxxx and yyyy are hex numbers)
|
||||
-xxxx..yyyy remove the range from the set (xxxx and yyyy are hex numbers)
|
||||
+cat=Xx add all Unicode characters with category code Xx
|
||||
-cat=Xx remove all Unicode characters with category code Xx
|
||||
-cat!=Xx remove all Unicode characters without category code Xx
|
||||
clean remove any elements that do not appear in the Unicode database
|
||||
unknown remove any elements that do appear in the Unicode database
|
||||
|
||||
Command to output descriptions of the constructed set of characters:
|
||||
|
||||
table write a full table with one line per character
|
||||
compact output the set in compact MES format
|
||||
c output the set as C interval array
|
||||
nr output the number of characters
|
||||
sources output a table that shows the number of characters contributed
|
||||
by the various combinations of input sets added with +.
|
||||
utf8-list output a list of all characters encoded in UTF-8
|
||||
|
||||
Commands to tailor the following output commands:
|
||||
|
||||
html write HTML tables instead of plain text
|
||||
ucs add the unicode character itself to the table (UTF-8 in
|
||||
plain table, numeric character reference in HTML)
|
||||
|
||||
Formats of character set input files read by the + and - command:
|
||||
|
||||
Empty lines, white space at the start and end of the line and any
|
||||
comment text following a \# are ignored. The following formats are
|
||||
recognized
|
||||
|
||||
xx yyyy xx is the hex code in an 8-bit character set and yyyy
|
||||
is the corresponding Unicode value. Both can optionally
|
||||
be prefixed by 0x. This is the format used in the
|
||||
files on <ftp://ftp.unicode.org/Public/MAPPINGS/>.
|
||||
|
||||
yyyy yyyy (optionally prefixed with 0x) is a Unicode character
|
||||
belonging to the specified subset.
|
||||
|
||||
yyyy-yyyy a range of Unicode characters belonging to
|
||||
yyyy..yyyy the specified subset.
|
||||
|
||||
xx yy yy yy-yy yy xx denotes a row (high-byte) and the yy specify
|
||||
corresponding low bytes or with a hyphen also ranges of
|
||||
low bytes in the Unicode values that belong to this
|
||||
subset. This is also the format that is generated by
|
||||
the compact command.
|
||||
End
|
||||
exit 1 if $#ARGV < 0;
|
||||
|
||||
|
||||
# Subroutine to identify whether the ISO 10646/Unicode character code
|
||||
# ucs belongs into the East Asian Wide (W) or East Asian FullWidth
|
||||
# (F) category as defined in Unicode Technical Report #11.
|
||||
|
||||
sub iswide ($) {
|
||||
my $ucs = shift(@_);
|
||||
|
||||
return ($ucs >= 0x1100 &&
|
||||
($ucs <= 0x115f || # Hangul Jamo
|
||||
$ucs == 0x2329 || $ucs == 0x232a ||
|
||||
($ucs >= 0x2e80 && $ucs <= 0xa4cf &&
|
||||
$ucs != 0x303f) || # CJK .. Yi
|
||||
($ucs >= 0xac00 && $ucs <= 0xd7a3) || # Hangul Syllables
|
||||
($ucs >= 0xf900 && $ucs <= 0xfaff) || # CJK Comp. Ideographs
|
||||
($ucs >= 0xfe30 && $ucs <= 0xfe6f) || # CJK Comp. Forms
|
||||
($ucs >= 0xff00 && $ucs <= 0xff60) || # Fullwidth Forms
|
||||
($ucs >= 0xffe0 && $ucs <= 0xffe6) ||
|
||||
($ucs >= 0x20000 && $ucs <= 0x2fffd) ||
|
||||
($ucs >= 0x30000 && $ucs <= 0x3fffd)));
|
||||
}
|
||||
|
||||
# Return the Unicode name that belongs to a given character code
|
||||
|
||||
# Jamo short names, see Unicode 3.0, table 4-4, page 86
|
||||
|
||||
my @lname = ('G', 'GG', 'N', 'D', 'DD', 'R', 'M', 'B', 'BB', 'S', 'SS', '',
|
||||
'J', 'JJ', 'C', 'K', 'T', 'P', 'H'); # 1100..1112
|
||||
my @vname = ('A', 'AE', 'YA', 'YAE', 'EO', 'E', 'YEO', 'YE', 'O',
|
||||
'WA', 'WAE', 'OE', 'YO', 'U', 'WEO', 'WE', 'WI', 'YU',
|
||||
'EU', 'YI', 'I'); # 1161..1175
|
||||
my @tname = ('G', 'GG', 'GS', 'N', 'NJ', 'NH', 'D', 'L', 'LG', 'LM',
|
||||
'LB', 'LS', 'LT', 'LP', 'LH', 'M', 'B', 'BS', 'S', 'SS',
|
||||
'NG', 'J', 'C', 'K', 'T', 'P', 'H'); # 11a8..11c2
|
||||
|
||||
sub name {
|
||||
my $ucs = shift(@_);
|
||||
|
||||
# The intervals used here reflect Unicode Version 3.2
|
||||
if (($ucs >= 0x3400 && $ucs <= 0x4db5) ||
|
||||
($ucs >= 0x4e00 && $ucs <= 0x9fa5) ||
|
||||
($ucs >= 0x20000 && $ucs <= 0x2a6d6)) {
|
||||
return "CJK UNIFIED IDEOGRAPH-" . sprintf("%04X", $ucs);
|
||||
}
|
||||
|
||||
if ($ucs >= 0xac00 && $ucs <= 0xd7a3) {
|
||||
my $s = $ucs - 0xac00;
|
||||
my $l = 0x1100 + int($s / (21 * 28));
|
||||
my $v = 0x1161 + int(($s % (21 * 28)) / 28);
|
||||
my $t = 0x11a7 + $s % 28;
|
||||
return "HANGUL SYLLABLE " .
|
||||
($lname[int($s / (21 * 28))] .
|
||||
$vname[int(($s % (21 * 28)) / 28)] .
|
||||
$tname[$s % 28 - 1]);
|
||||
}
|
||||
|
||||
return $name{$ucs};
|
||||
}
|
||||
|
||||
sub is_unicode {
|
||||
my $ucs = shift(@_);
|
||||
|
||||
# The intervals used here reflect Unicode Version 3.2
|
||||
if (($ucs >= 0x3400 && $ucs <= 0x4db5) ||
|
||||
($ucs >= 0x4e00 && $ucs <= 0x9fa5) ||
|
||||
($ucs >= 0xac00 && $ucs <= 0xd7a3) ||
|
||||
($ucs >= 0x20000 && $ucs <= 0x2a6d6)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return exists $name{$ucs};
|
||||
}
|
||||
|
||||
my @search_path = ();
|
||||
if ($RealBin =~ m|^(.*)/bin\z| && -d "$1/share/uniset") {
|
||||
push @search_path, "$1/share/uniset";
|
||||
} else {
|
||||
push @search_path, $RealBin;
|
||||
}
|
||||
|
||||
sub search_open {
|
||||
my ($mode, $fn) = @_;
|
||||
my $file;
|
||||
return $file if open($file, $mode, $fn);
|
||||
return undef if $fn =~ m|/|;
|
||||
for my $path (@search_path) {
|
||||
return $file if open($file, $mode, "$path/$fn");
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
my $html = 0;
|
||||
my $image = 0;
|
||||
my $adducs = 0;
|
||||
my $unicodedata = "UnicodeData.txt";
|
||||
my $blockdata = "Blocks.txt";
|
||||
|
||||
# read list of all Unicode names
|
||||
my $data = search_open('<', $unicodedata);
|
||||
unless ($data) {
|
||||
die ("Can't open Unicode database '$unicodedata':\n$!\n\n" .
|
||||
"Please make sure that you have downloaded the file\n" .
|
||||
"http://www.unicode.org/Public/UNIDATA/UnicodeData.txt\n");
|
||||
}
|
||||
while (<$data>) {
|
||||
if (/^([0-9,A-F]{4,8});([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*)$/) {
|
||||
next if $2 ne '<control>' && substr($2, 0, 1) eq '<';
|
||||
$ucs = hex($1);
|
||||
$name{$ucs} = $2;
|
||||
$invname{$2} = $ucs;
|
||||
$category{$ucs} = $3;
|
||||
$comment{$ucs} = $12;
|
||||
} else {
|
||||
die("Syntax error in line '$_' in file '$unicodedata'\n");
|
||||
}
|
||||
}
|
||||
close($data);
|
||||
|
||||
# read list of all Unicode blocks
|
||||
$data = search_open('<', $blockdata);
|
||||
unless ($data) {
|
||||
die ("Can't open Unicode blockname list '$blockdata':\n$!\n\n" .
|
||||
"Please make sure that you have downloaded the file\n" .
|
||||
"http://www.unicode.org/Public/UNIDATA/Blocks.txt\n");
|
||||
}
|
||||
my $blocks = 0;
|
||||
my (@blockstart, @blockend, @blockname);
|
||||
while (<$data>) {
|
||||
if (/^\s*([0-9,A-F]{4,8})\s*\.\.\s*([0-9,A-F]{4,8})\s*;\s*(.*)$/) {
|
||||
$blockstart[$blocks] = hex($1);
|
||||
$blockend [$blocks] = hex($2);
|
||||
$blockname [$blocks] = $3;
|
||||
$blocks++;
|
||||
} elsif (/^\s*\#/ || /^\s*$/) {
|
||||
# ignore comments and empty lines
|
||||
} else {
|
||||
die("Syntax error in line '$_' in file '$blockdata'\n");
|
||||
}
|
||||
}
|
||||
close($data);
|
||||
if ($blockend[$blocks-1] < 0x110000) {
|
||||
$blockstart[$blocks] = 0x110000;
|
||||
$blockend [$blocks] = 0x7FFFFFFF;
|
||||
$blockname [$blocks] = "Beyond Plane 16";
|
||||
$blocks++;
|
||||
}
|
||||
|
||||
# process command line arguments
|
||||
while ($_ = shift(@ARGV)) {
|
||||
if (/^html$/) {
|
||||
$html = 1;
|
||||
} elsif (/^ucs$/) {
|
||||
$adducs = 1;
|
||||
} elsif (/^img$/) {
|
||||
$html = 1;
|
||||
$image = 1;
|
||||
} elsif (/^template$/) {
|
||||
$template = shift(@ARGV);
|
||||
open(TEMPLATE, $template) || die("Can't open template file '$template': $!\n");
|
||||
while (<TEMPLATE>) {
|
||||
if (/^\#\s*include\s+\"([^\"]*)\"\s*$/) {
|
||||
open(INCLUDE, $1) || die("Can't open template include file '$1': $!\n");
|
||||
while (<INCLUDE>) {
|
||||
print $_;
|
||||
}
|
||||
close(INCLUDE);
|
||||
} elsif (/^\#\s*quote\s+\"([^\"]*)\"\s*$/) {
|
||||
open(INCLUDE, $1) || die("Can't open template include file '$1': $!\n");
|
||||
while (<INCLUDE>) {
|
||||
s/&/&/g;
|
||||
s/</</g;
|
||||
print $_;
|
||||
}
|
||||
close(INCLUDE);
|
||||
} else {
|
||||
print $_;
|
||||
}
|
||||
}
|
||||
close(TEMPLATE);
|
||||
} elsif (/^\+cat=(.+)$/) {
|
||||
# add characters with given category
|
||||
$cat = $1;
|
||||
for $i (keys(%category)) {
|
||||
$used{$i} = "[${cat}]" if $category{$i} eq $cat;
|
||||
}
|
||||
} elsif (/^\-cat=(.+)$/) {
|
||||
# remove characters with given category
|
||||
$cat = $1;
|
||||
for $i (keys(%category)) {
|
||||
delete $used{$i} if $category{$i} eq $cat;
|
||||
}
|
||||
} elsif (/^\-cat!=(.+)$/) {
|
||||
# remove characters without given category
|
||||
$cat = $1;
|
||||
for $i (keys(%category)) {
|
||||
delete $used{$i} unless $category{$i} eq $cat;
|
||||
}
|
||||
} elsif (/^([+-]):(.*)/) {
|
||||
$remove = $1 eq "-";
|
||||
$setfile = $2;
|
||||
$setfile = shift(@ARGV) if $setfile eq "";
|
||||
push(@SETS, $setfile);
|
||||
open(SET, $setfile) || die("Can't open set file '$setfile': $!\n");
|
||||
$setname = $setfile;
|
||||
while (<SET>) {
|
||||
while ($_) {
|
||||
$i = ord($_);
|
||||
$used{$i} .= "[${setname}]" unless $remove;
|
||||
delete $used{$i} if $remove;
|
||||
$_ = substr($_, 1);
|
||||
}
|
||||
}
|
||||
close SET;
|
||||
} elsif (/^([+-])(.*)/) {
|
||||
$remove = $1 eq "-";
|
||||
$setfile = $2;
|
||||
$setfile = "$setfile..$setfile" if $setfile =~ /^([0-9A-Fa-f]{4,8})$/;
|
||||
if ($setfile =~ /^([0-9A-Fa-f]{4,8})(-|\.\.)([0-9A-Fa-f]{4,8})$/) {
|
||||
# handle intervall specification on command line
|
||||
$first = hex($1);
|
||||
$last = hex($3);
|
||||
for ($i = $first; $i <= $last; $i++) {
|
||||
$used{$i} .= "[ARG]" unless $remove;
|
||||
delete $used{$i} if $remove;
|
||||
}
|
||||
next;
|
||||
}
|
||||
$setfile = shift(@ARGV) if $setfile eq "";
|
||||
push(@SETS, $setfile);
|
||||
my $setf = search_open('<', $setfile);
|
||||
die("Can't open set file '$setfile': $!\n") unless $setf;
|
||||
$cedf = ($setfile =~ /cedf/); # detect Kosta Kosti's trans CEDF format by path name
|
||||
$setname = $setfile;
|
||||
$setname =~ s/([^.\[\]]*)\..*/$1/;
|
||||
while (<$setf>) {
|
||||
if (/^<code_set_name>/) {
|
||||
# handle ISO 15897 (POSIX registry) charset mapping format
|
||||
undef $comment_char;
|
||||
undef $escape_char;
|
||||
while (<$setf>) {
|
||||
if ($comment_char && /^$comment_char/) {
|
||||
# remove comments
|
||||
$_ = $`;
|
||||
}
|
||||
next if (/^\032?\s*$/); # skip empty lines
|
||||
if (/^<comment_char> (\S)$/) {
|
||||
$comment_char = $1;
|
||||
} elsif (/^<escape_char> (\S)$/) {
|
||||
$escape_char = $1;
|
||||
} elsif (/^(END )?CHARMAP$/) {
|
||||
#ignore
|
||||
} elsif (/^<.*>\s*\/x([0-9A-F]{2})\s*<U([0-9A-F]{4,8})>/) {
|
||||
$used{hex($2)} .= "[${setname}{$1}]" unless $remove;
|
||||
delete $used{hex($2)} if $remove;
|
||||
} else {
|
||||
die("Syntax error in line $. in file '$setfile':\n'$_'\n");
|
||||
}
|
||||
}
|
||||
next;
|
||||
} elsif (/^STARTFONT /) {
|
||||
# handle X11 BDF file
|
||||
while (<$setf>) {
|
||||
if (/^ENCODING\s+([0-9]+)/) {
|
||||
$used{$1} .= "[${setname}]" unless $remove;
|
||||
delete $used{$1} if $remove;
|
||||
}
|
||||
}
|
||||
next;
|
||||
}
|
||||
tr/a-z/A-Z/; # make input uppercase
|
||||
if ($cedf) {
|
||||
if ($. > 4) {
|
||||
if (/^([0-9A-F]{2})\t.?\t(.*)$/) {
|
||||
# handle Kosta Kosti's trans CEDF format
|
||||
next if (hex($1) < 32 || (hex($1) > 0x7e && hex($1) < 0xa0));
|
||||
$ucs = $invname{$2};
|
||||
die "unknown ISO 10646 name '$2' in '$setfile' line $..\n" if ! $ucs;
|
||||
$used{$ucs} .= "[${setname}{$1}]" unless $remove;
|
||||
delete $used{$ucs} if $remove;
|
||||
} else {
|
||||
die("Syntax error in line $. in CEDF file '$setfile':\n'$_'\n");
|
||||
}
|
||||
}
|
||||
next;
|
||||
}
|
||||
if (/^\s*(0X|U\+|U-)?([0-9A-F]{2})\s+\#\s*UNDEFINED\s*$/) {
|
||||
# ignore ftp.unicode.org mapping file lines with #UNDEFINED
|
||||
next;
|
||||
}
|
||||
s/^([^\#]*)\#.*$/$1/; # remove comments
|
||||
next if (/^\032?\s*$/); # skip empty lines
|
||||
if (/^\s*(0X)?([0-9A-F-]{2})\s+(0X|U\+|U-)?([0-9A-F]{4,8})\s*$/) {
|
||||
# handle entry from a ftp.unicode.org mapping file
|
||||
$used{hex($4)} .= "[${setname}{$2}]" unless $remove;
|
||||
delete $used{hex($4)} if $remove;
|
||||
} elsif (/^\s*(0X|U\+|U-)?([0-9A-F]{4,8})(\s*-\s*|\s*\.\.\s*|\s+)(0X|U\+|U-)?([0-9A-F]{4,8})\s*$/) {
|
||||
# handle interval specification
|
||||
$first = hex($2);
|
||||
$last = hex($5);
|
||||
for ($i = $first; $i <= $last; $i++) {
|
||||
$used{$i} .= "[${setname}]" unless $remove;
|
||||
delete $used{$i} if $remove;
|
||||
}
|
||||
} elsif (/^\s*([0-9A-F]{2,6})(\s+[0-9A-F]{2},?|\s+[0-9A-F]{2}-[0-9A-F]{2},?)+/) {
|
||||
# handle lines from P10 MES draft
|
||||
$row = $1;
|
||||
$cols = $_;
|
||||
$cols =~ s/^\s*([0-9A-F]{2,6})\s*(.*)\s*$/$2/;
|
||||
$cols =~ tr/,//d;
|
||||
@cols = split(/\s+/, $cols);
|
||||
for (@cols) {
|
||||
if (/^(..)$/) {
|
||||
$first = hex("$row$1");
|
||||
$last = $first;
|
||||
} elsif (/^(..)-(..)$/) {
|
||||
$first = hex("$row$1");
|
||||
$last = hex("$row$2");
|
||||
} else {
|
||||
die ("this should never happen '$_'");
|
||||
}
|
||||
for ($i = $first; $i <= $last; $i++) {
|
||||
$used{$i} .= "[${setname}]" unless $remove;
|
||||
delete $used{$i} if $remove;
|
||||
}
|
||||
}
|
||||
} elsif (/^\s*(0X|U\+|U-)?([0-9A-F]{4,8})\s*/) {
|
||||
# handle single character
|
||||
$used{hex($2)} .= "[${setname}]" unless $remove;
|
||||
delete $used{hex($2)} if $remove;
|
||||
} else {
|
||||
die("Syntax error in line $. in file '$setfile':\n'$_'\n") unless /^\s*(\#.*)?$/;
|
||||
}
|
||||
}
|
||||
close $setf;
|
||||
} elsif (/^loadimages$/ || /^loadbigimages$/) {
|
||||
if (/^loadimages$/) {
|
||||
$prefix = "Small.Glyphs";
|
||||
} else {
|
||||
$prefix = "Glyphs";
|
||||
}
|
||||
$total = 0;
|
||||
for $i (keys(%used)) {
|
||||
next if ($name{$i} eq "<control>");
|
||||
$total++;
|
||||
}
|
||||
$count = 0;
|
||||
$| = 1;
|
||||
for $i (sort({$a <=> $b} keys(%used))) {
|
||||
next if ($name{$i} eq "<control>");
|
||||
$count++;
|
||||
$j = sprintf("%04X", $i);
|
||||
$j =~ /(..)(..)/;
|
||||
$gif = "http://charts.unicode.org/Unicode.charts/$prefix/$1/U$j.gif";
|
||||
print("\r$count/$total: $gif");
|
||||
system("mkdir -p $prefix/$1; cd $prefix/$1; webcopy -u -s $gif &");
|
||||
select(undef, undef, undef, 0.2);
|
||||
}
|
||||
print("\n");
|
||||
exit 0;
|
||||
} elsif (/^giftable/) {
|
||||
# form a table of glyphs (requires pbmtools installed)
|
||||
$count = 0;
|
||||
for $i (keys(%used)) {
|
||||
$count++ unless $name{$i} eq "<control>";
|
||||
}
|
||||
$width = int(sqrt($count/sqrt(2)) + 0.5);
|
||||
$width = $1 if /^giftable([0-9]+)$/;
|
||||
system("rm -f tmp-*.pnm table.pnm~ table.pnm");
|
||||
$col = 0;
|
||||
$row = 0;
|
||||
for $i (sort({$a <=> $b} keys(%used))) {
|
||||
next if ($name{$i} eq "<control>");
|
||||
$j = sprintf("%04X", $i);
|
||||
$j =~ /(..)(..)/;
|
||||
$gif = "Small.Glyphs/$1/U$j.gif";
|
||||
$pnm = sprintf("tmp-%02x.pnm", $col);
|
||||
$fallback = "Small.Glyphs/FF/UFFFD.gif";
|
||||
system("giftopnm $gif >$pnm || { rm $pnm ; giftopnm $fallback >$pnm ; }");
|
||||
if (++$col == $width) {
|
||||
system("pnmcat -lr tmp-*.pnm | cat >tmp-row.pnm");
|
||||
if ($row == 0) {
|
||||
system("mv tmp-row.pnm table.pnm");
|
||||
} else {
|
||||
system("mv table.pnm table.pnm~; pnmcat -tb table.pnm~ tmp-row.pnm >table.pnm");
|
||||
}
|
||||
$row++;
|
||||
$col = 0;
|
||||
system("rm -f tmp-*.pnm table.pnm~");
|
||||
}
|
||||
}
|
||||
if ($col > 0) {
|
||||
system("pnmcat -lr tmp-*.pnm | cat >tmp-row.pnm");
|
||||
if ($row == 0) {
|
||||
system("mv tmp-row.pnm table.pnm");
|
||||
} else {
|
||||
system("mv table.pnm table.pnm~; pnmcat -tb -jleft -black table.pnm~ tmp-row.pnm >table.pnm");
|
||||
}
|
||||
}
|
||||
system("rm -f table.gif ; ppmtogif table.pnm > table.gif");
|
||||
system("rm -f tmp-*.pnm table.pnm~ table.pnm");
|
||||
} elsif (/^table$/) {
|
||||
# go through all used names to print full table
|
||||
print "<TABLE border=2>\n" if $html;
|
||||
for $i (sort({$a <=> $b} keys(%used))) {
|
||||
next if ($name{$i} eq "<control>");
|
||||
if ($html) {
|
||||
$sources = $used{$i};
|
||||
$sources =~ s/\]\[/, /g;
|
||||
$sources =~ s/^\[//g;
|
||||
$sources =~ s/\]$//g;
|
||||
$sources =~ s/\{(..)\}/<SUB>$1<\/SUB>/g;
|
||||
$j = sprintf("%04X", $i);
|
||||
$j =~ /(..)(..)/;
|
||||
$gif = "Small.Glyphs/$1/U$j.gif";
|
||||
print "<TR>";
|
||||
print "<TD><img width=32 height=32 src=\"$gif\">" if $image;
|
||||
printf("<TD>&#%d;", $i) if $adducs;
|
||||
print "<TD><SAMP>$j</SAMP><TD><SAMP>" . name($i);
|
||||
print " ($comment{$i})" if $comment{$i};
|
||||
print "</SAMP><TD><SMALL>$sources</SMALL>\n";
|
||||
} else {
|
||||
printf("%04X \# ", $i);
|
||||
print pack("U", $i) . " " if $adducs;
|
||||
print name($i) ."\n";
|
||||
}
|
||||
}
|
||||
print "</TABLE>\n" if $html;
|
||||
} elsif (/^imgblock$/) {
|
||||
$width = 16;
|
||||
$width = $1 if /giftable([0-9]+)/;
|
||||
$col = 0;
|
||||
$subline = "";
|
||||
print "\n<P><TABLE cellspacing=0 cellpadding=0>";
|
||||
for $i (sort({$a <=> $b} keys(%used))) {
|
||||
print "<TR>" if $col == 0;
|
||||
$j = sprintf("%04X", $i);
|
||||
$j =~ /(..)(..)/;
|
||||
$gif = "Small.Glyphs/$1/U$j.gif";
|
||||
$alt = name($i);
|
||||
print "<TD><img width=32 height=32 src=\"$gif\" alt=\"$alt\">";
|
||||
$subline .= "<TD><SMALL><SAMP>$j</SAMP></SMALL>";
|
||||
if (++$col == $width) {
|
||||
print "<TR align=center>$subline";
|
||||
$col = 0;
|
||||
$subline = "";
|
||||
}
|
||||
}
|
||||
print "<TR align=center>$subline" if ($col > 0);
|
||||
print "</TABLE>\n";
|
||||
} elsif (/^sources$/) {
|
||||
# count how many characters are attributed to the various source set combinations
|
||||
print "<P>Number of occurences of source character set combinations:\n<TABLE border=2>" if $html;
|
||||
for $i (keys(%used)) {
|
||||
next if ($name{$i} eq "<control>");
|
||||
$sources = $used{$i};
|
||||
$sources =~ s/\]\[/, /g;
|
||||
$sources =~ s/^\[//g;
|
||||
$sources =~ s/\]$//g;
|
||||
$sources =~ s/\{(..)\}//g;
|
||||
$contribs{$sources} += 1;
|
||||
}
|
||||
for $j (keys(%contribs)) {
|
||||
print "<TR><TD>$contribs{$j}<TD>$j\n" if $html;
|
||||
}
|
||||
print "</TABLE>\n" if $html;
|
||||
} elsif (/^compact$/) {
|
||||
# print compact table in P10 MES format
|
||||
print "<P>Compact representation of this character set:\n<TABLE border=2>" if $html;
|
||||
print "<TR><TD><B>Rows</B><TD><B>Positions (Cells)</B>" if $html;
|
||||
print "\n# Plane 00\n# Rows\tPositions (Cells)\n" unless $html;
|
||||
$current_row = '';
|
||||
$start_col = '';
|
||||
$last_col = '';
|
||||
for $i (sort({$a <=> $b} keys(%used))) {
|
||||
next if ($name{$i} eq "<control>");
|
||||
$row = sprintf("%02X", $i >> 8);
|
||||
$col = sprintf("%02X", $i & 0xff);
|
||||
if ($row ne $current_row) {
|
||||
if (($last_col ne '') and ($last_col ne $start_col)) {
|
||||
print "-$last_col";
|
||||
print "</SAMP>" if $html;
|
||||
}
|
||||
print "<TR><TD><SAMP>$row</SAMP><TD><SAMP>" if $html;
|
||||
print "\n $row\t" unless $html;
|
||||
$len = 0;
|
||||
$current_row = $row;
|
||||
$start_col = '';
|
||||
}
|
||||
if ($start_col eq '') {
|
||||
print "$col";
|
||||
$len += 2;
|
||||
$start_col = $col;
|
||||
$last_col = $col;
|
||||
} elsif (hex($col) == hex($last_col) + 1) {
|
||||
$last_col = $col;
|
||||
} else {
|
||||
if ($last_col ne $start_col) {
|
||||
print "-$last_col";
|
||||
$len += 3;
|
||||
}
|
||||
if ($len > 60 && !$html) {
|
||||
print "\n $row\t";
|
||||
$len = 0;
|
||||
};
|
||||
print " " if $len;
|
||||
print "$col";
|
||||
$len += 2 + !! $len;
|
||||
$start_col = $col;
|
||||
$last_col = $col;
|
||||
}
|
||||
}
|
||||
if (($last_col ne '') and ($last_col ne $start_col)) {
|
||||
print "-$last_col";
|
||||
print "</SAMP>" if $html;
|
||||
}
|
||||
print "\n" if ($current_row ne '');
|
||||
print "</TABLE>\n" if $html;
|
||||
print "\n";
|
||||
} elsif (/^c$/) {
|
||||
# print table as C interval array
|
||||
print "{";
|
||||
$last_i = '';
|
||||
$columns = 3;
|
||||
$col = $columns;
|
||||
for $i (sort({$a <=> $b} keys(%used))) {
|
||||
next if ($name{$i} eq "<control>");
|
||||
if ($last_i eq '') {
|
||||
if (++$col > $columns) { $col = 1; print "\n "; }
|
||||
printf(" { 0x%04X, ", $i);
|
||||
$last_i = $i;
|
||||
} elsif ($i == $last_i + 1) {
|
||||
$last_i = $i;
|
||||
} else {
|
||||
printf("0x%04X },", $last_i);
|
||||
if (++$col > $columns) { $col = 1; print "\n "; }
|
||||
printf(" { 0x%04X, ", $i);
|
||||
$last_i = $i;
|
||||
}
|
||||
}
|
||||
if ($last_i ne '') {
|
||||
printf("0x%04X }", $last_i);
|
||||
}
|
||||
print "\n};\n";
|
||||
} elsif (/^utf8-list$/) {
|
||||
$col = 0;
|
||||
$block = 0;
|
||||
$last = -1;
|
||||
for $i (sort({$a <=> $b} keys(%used))) {
|
||||
next if ($name{$i} eq "<control>");
|
||||
while ($blockend[$block] < $i && $block < $blocks - 1) {
|
||||
$block++;
|
||||
}
|
||||
if ($last <= $blockend[$block-1] &&
|
||||
$i < $blockstart[$block]) {
|
||||
print "\n" if ($col);
|
||||
printf "\nFree block (U+%04X-U+%04X):\n\n",
|
||||
$blockend[$block-1] + 1, $blockstart[$block] - 1;
|
||||
$col = 0;
|
||||
}
|
||||
if ($last < $blockstart[$block] && $i >= $blockstart[$block]) {
|
||||
print "\n" if ($col);
|
||||
printf "\n$blockname[$block] (U+%04X-U+%04X):\n\n",
|
||||
$blockstart[$block], $blockend[$block];
|
||||
$col = 0;
|
||||
}
|
||||
if ($category{$i} eq 'Mn') {
|
||||
# prefix non-spacing character with U+25CC DOTTED CIRCLE
|
||||
print "\x{25CC}";
|
||||
} elsif ($category{$i} eq 'Me') {
|
||||
# prefix enclosing non-spacing character with space
|
||||
print " ";
|
||||
}
|
||||
print pack("U", $i);
|
||||
$col += 1 + iswide($i);
|
||||
if ($col >= 64) {
|
||||
print "\n";
|
||||
$col = 0;
|
||||
}
|
||||
$last = $i;
|
||||
}
|
||||
print "\n" if ($col);
|
||||
} elsif (/^collections$/) {
|
||||
$block = 0;
|
||||
$last = -1;
|
||||
for $i (sort({$a <=> $b} keys(%used))) {
|
||||
next if ($name{$i} eq "<control>");
|
||||
while ($blockend[$block] < $i && $block < $blocks - 1) {
|
||||
$block++;
|
||||
}
|
||||
if ($last < $blockstart[$block] && $i >= $blockstart[$block]) {
|
||||
print $blockname[$block],
|
||||
" " x (40 - length($blockname[$block]));
|
||||
printf "%04X-%04X\n",
|
||||
$blockstart[$block], $blockend[$block];
|
||||
}
|
||||
$last = $i;
|
||||
}
|
||||
} elsif (/^nr$/) {
|
||||
print "<P>" if $html;
|
||||
print "# " unless $html;
|
||||
print "Number of characters in above table: ";
|
||||
$count = 0;
|
||||
for $i (keys(%used)) {
|
||||
$count++ unless $name{$i} eq "<control>";
|
||||
}
|
||||
print $count;
|
||||
print "\n";
|
||||
} elsif (/^clean$/) {
|
||||
# remove characters from set that are not in $unicodedata
|
||||
for $i (keys(%used)) {
|
||||
delete $used{$i} unless is_unicode($i);
|
||||
}
|
||||
} elsif (/^unknown$/) {
|
||||
# remove characters from set that are in $unicodedata
|
||||
for $i (keys(%used)) {
|
||||
delete $used{$i} if is_unicode($i);
|
||||
}
|
||||
} else {
|
||||
die("Unknown command line command '$_'\n");
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcpcpy>>---copy a wide-character string returning a pointer to its end
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
wchar_t *wcpcpy(wchar_t *<[s1]>, const wchar_t *<[s2]>);
|
||||
|
||||
DESCRIPTION
|
||||
The <<wcpcpy>> function copies the wide-character string pointed to by
|
||||
<[s2]> (including the terminating null wide-character code) into the
|
||||
array pointed to by <[s1]>. If copying takes place between objects that
|
||||
overlap, the behaviour is undefined.
|
||||
|
||||
RETURNS
|
||||
This function returns a pointer to the end of the destination string,
|
||||
thus pointing to the trailing '\0'.
|
||||
|
||||
PORTABILITY
|
||||
<<wcpcpy>> is a GNU extension.
|
||||
|
||||
No supporting OS subroutines are required.
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *
|
||||
wcpcpy (wchar_t *__restrict s1,
|
||||
const wchar_t *__restrict s2)
|
||||
{
|
||||
while ((*s1++ = *s2++))
|
||||
;
|
||||
return --s1;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcpncpy>>---copy part of a wide-character string returning a pointer to its end
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
wchar_t *wcpncpy(wchar_t *__restrict <[s1]>,
|
||||
const wchar_t *__restrict <[s2]>, size_t <[n]>);
|
||||
|
||||
DESCRIPTION
|
||||
The <<wcpncpy>> function copies not more than n wide-character codes
|
||||
(wide-character codes that follow a null wide-character code are not
|
||||
copied) from the array pointed to by <[s2]> to the array pointed to
|
||||
by <[s1]>. If copying takes place between objects that overlap, the
|
||||
behaviour is undefined.
|
||||
|
||||
If the array pointed to by <[s2]> is a wide-character string that is
|
||||
shorter than <[n]> wide-character codes, null wide-character codes are
|
||||
appended to the copy in the array pointed to by <[s1]>, until <[n]>
|
||||
wide-character codes in all are written.
|
||||
|
||||
RETURNS
|
||||
The <<wcpncpy>> function returns <[s1]>; no return value is reserved to
|
||||
indicate an error.
|
||||
|
||||
PORTABILITY
|
||||
<<wcpncpy>> is ISO/IEC 9899/AMD1:1995 (ISO C).
|
||||
|
||||
No supporting OS subroutines are required.
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *
|
||||
wcpncpy (wchar_t *__restrict dst,
|
||||
const wchar_t *__restrict src,
|
||||
size_t count)
|
||||
{
|
||||
wchar_t *ret = NULL;
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
--count;
|
||||
if ((*dst++ = *src++) == L'\0')
|
||||
{
|
||||
ret = dst - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (count-- > 0)
|
||||
*dst++ = L'\0';
|
||||
|
||||
return ret ? ret : dst;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcscasecmp>>---case-insensitive wide character string compare
|
||||
|
||||
INDEX
|
||||
wcscasecmp
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
int wcscasecmp(const wchar_t *<[a]>, const wchar_t *<[b]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<wcscasecmp>> compares the wide character string at <[a]> to
|
||||
the wide character string at <[b]> in a case-insensitive manner.
|
||||
|
||||
RETURNS
|
||||
|
||||
If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after
|
||||
both are converted to uppercase), <<wcscasecmp>> returns a
|
||||
number greater than zero. If the two strings match,
|
||||
<<wcscasecmp>> returns zero. If <<*<[a]>>> sorts
|
||||
lexicographically before <<*<[b]>>>, <<wcscasecmp>> returns a
|
||||
number less than zero.
|
||||
|
||||
PORTABILITY
|
||||
POSIX-1.2008
|
||||
|
||||
<<wcscasecmp>> requires no supporting OS subroutines. It uses
|
||||
tolower() from elsewhere in this library.
|
||||
|
||||
QUICKREF
|
||||
wcscasecmp
|
||||
*/
|
||||
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
|
||||
int
|
||||
wcscasecmp (const wchar_t *s1,
|
||||
const wchar_t *s2)
|
||||
{
|
||||
int d = 0;
|
||||
for ( ; ; )
|
||||
{
|
||||
const int c1 = towlower (*s1++);
|
||||
const int c2 = towlower (*s2++);
|
||||
if (((d = c1 - c2) != 0) || (c2 == '\0'))
|
||||
break;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcscasecmp_l>>---case-insensitive wide character string compare
|
||||
|
||||
INDEX
|
||||
wcscasecmp_l
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
int wcscasecmp_l(const wchar_t *<[a]>, const wchar_t *<[b]>,
|
||||
locale_t <[locale]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<wcscasecmp_l>> compares the wide character string at <[a]> to
|
||||
the wide character string at <[b]> in a case-insensitive manner.
|
||||
|
||||
if <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object,
|
||||
the behaviour is undefined.
|
||||
|
||||
RETURNS
|
||||
|
||||
If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after
|
||||
both are converted to uppercase), <<wcscasecmp_l>> returns a
|
||||
number greater than zero. If the two strings match,
|
||||
<<wcscasecmp_l>> returns zero. If <<*<[a]>>> sorts
|
||||
lexicographically before <<*<[b]>>>, <<wcscasecmp_l>> returns a
|
||||
number less than zero.
|
||||
|
||||
PORTABILITY
|
||||
<<wcscasecmp_l>> is POSIX-1.2008
|
||||
|
||||
<<wcscasecmp_l>> requires no supporting OS subroutines. It uses
|
||||
tolower() from elsewhere in this library.
|
||||
|
||||
QUICKREF
|
||||
wcscasecmp_l
|
||||
*/
|
||||
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
|
||||
int
|
||||
wcscasecmp_l (const wchar_t *s1, const wchar_t *s2, struct __locale_t *locale)
|
||||
{
|
||||
int d = 0;
|
||||
for ( ; ; )
|
||||
{
|
||||
const int c1 = towlower_l (*s1++, locale);
|
||||
const int c2 = towlower_l (*s2++, locale);
|
||||
if (((d = c1 - c2) != 0) || (c2 == '\0'))
|
||||
break;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcscat>>---concatenate two wide-character strings
|
||||
INDEX
|
||||
wcscat
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
wchar_t *wcscat(wchar_t *__restrict <[s1]>,
|
||||
const wchar_t *__restrict <[s2]>);
|
||||
|
||||
DESCRIPTION
|
||||
The <<wcscat>> function appends a copy of the wide-character string
|
||||
pointed to by <[s2]> (including the terminating null wide-character
|
||||
code) to the end of the wide-character string pointed to by <[s1]>.
|
||||
The initial wide-character code of <[s2]> overwrites the null
|
||||
wide-character code at the end of <[s1]>. If copying takes place between
|
||||
objects that overlap, the behaviour is undefined.
|
||||
|
||||
RETURNS
|
||||
The <<wcscat>> function returns <[s1]>;
|
||||
no return value is reserved to indicate an error.
|
||||
|
||||
PORTABILITY
|
||||
<<wcscat>> is ISO/IEC 9899/AMD1:1995 (ISO C).
|
||||
|
||||
No supporting OS subroutines are required.
|
||||
*/
|
||||
|
||||
/* $NetBSD: wcscat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c)1999 Citrus Project,
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* citrus Id: wcscat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *
|
||||
wcscat (wchar_t *__restrict s1,
|
||||
const wchar_t *__restrict s2)
|
||||
{
|
||||
wchar_t *p;
|
||||
wchar_t *q;
|
||||
const wchar_t *r;
|
||||
|
||||
p = s1;
|
||||
while (*p)
|
||||
p++;
|
||||
q = p;
|
||||
r = s2;
|
||||
while (*r)
|
||||
*q++ = *r++;
|
||||
*q = '\0';
|
||||
return s1;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcschr>>---wide-character string scanning operation
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
wchar_t *wcschr(const wchar_t *<[s]>, wchar_t <[c]>);
|
||||
|
||||
DESCRIPTION
|
||||
The <<wcschr>> function locates the first occurrence of <[c]> in the
|
||||
wide-character string pointed to by <[s]>. The value of <[c]> must be a
|
||||
character representable as a type wchar_t and must be a wide-character
|
||||
code corresponding to a valid character in the current locale.
|
||||
The terminating null wide-character string.
|
||||
|
||||
RETURNS
|
||||
Upon completion, <<wcschr>> returns a pointer to the wide-character
|
||||
code, or a null pointer if the wide-character code is not found.
|
||||
|
||||
PORTABILITY
|
||||
<<wcschr>> is ISO/IEC 9899/AMD1:1995 (ISO C).
|
||||
|
||||
No supporting OS subroutines are required.
|
||||
*/
|
||||
|
||||
/* $NetBSD: wcschr.c,v 1.1 2000/12/23 23:14:36 itojun Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c)1999 Citrus Project,
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* citrus Id: wcschr.c,v 1.2 2000/12/21 05:07:25 itojun Exp
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <stddef.h>
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *
|
||||
wcschr (const wchar_t * s,
|
||||
wchar_t c)
|
||||
{
|
||||
const wchar_t *p;
|
||||
|
||||
p = s;
|
||||
do
|
||||
{
|
||||
if (*p == c)
|
||||
{
|
||||
/* LINTED interface specification */
|
||||
return (wchar_t *) p;
|
||||
}
|
||||
} while (*p++);
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcscmp>>---compare two wide-character strings
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
int wcscmp(const wchar_t *<[s1]>, *<[s2]>);
|
||||
|
||||
DESCRIPTION
|
||||
The <<wcscmp>> function compares the wide-character string pointed to
|
||||
by <[s1]> to the wide-character string pointed to by <[s2]>.
|
||||
|
||||
The sign of a non-zero return value is determined by the sign of the
|
||||
difference between the values of the first pair of wide-character codes
|
||||
that differ in the objects being compared.
|
||||
|
||||
RETURNS
|
||||
Upon completion, <<wcscmp>> returns an integer greater than, equal to
|
||||
or less than 0, if the wide-character string pointed to by <[s1]> is
|
||||
greater than, equal to or less than the wide-character string pointed
|
||||
to by <[s2]> respectively.
|
||||
|
||||
PORTABILITY
|
||||
<<wcscmp>> is ISO/IEC 9899/AMD1:1995 (ISO C).
|
||||
|
||||
No supporting OS subroutines are required.
|
||||
*/
|
||||
|
||||
/* $NetBSD$ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Chris Torek.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <wchar.h>
|
||||
|
||||
/*
|
||||
* Compare strings.
|
||||
*/
|
||||
int
|
||||
wcscmp (const wchar_t * s1,
|
||||
const wchar_t * s2)
|
||||
{
|
||||
|
||||
while (*s1 == *s2++)
|
||||
if (*s1++ == 0)
|
||||
return (0);
|
||||
return (*s1 - *--s2);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcscoll>>---locale-specific wide-character string compare
|
||||
|
||||
INDEX
|
||||
wcscoll
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
int wcscoll(const wchar_t *<[stra]>, const wchar_t * <[strb]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<wcscoll>> compares the wide-character string pointed to by
|
||||
<[stra]> to the wide-character string pointed to by <[strb]>,
|
||||
using an interpretation appropriate to the current <<LC_COLLATE>>
|
||||
state.
|
||||
|
||||
(NOT Cygwin:) The current implementation of <<wcscoll>> simply
|
||||
uses <<wcscmp>> and does not support any language-specific sorting.
|
||||
|
||||
RETURNS
|
||||
If the first string is greater than the second string,
|
||||
<<wcscoll>> returns a number greater than zero. If the two
|
||||
strings are equivalent, <<wcscoll>> returns zero. If the first
|
||||
string is less than the second string, <<wcscoll>> returns a
|
||||
number less than zero.
|
||||
|
||||
PORTABILITY
|
||||
<<wcscoll>> is ISO/IEC 9899/AMD1:1995 (ISO C).
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <wchar.h>
|
||||
|
||||
int
|
||||
wcscoll (const wchar_t *a,
|
||||
const wchar_t *b)
|
||||
|
||||
{
|
||||
return wcscmp (a, b);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcscoll_l>>---locale-specific wide-character string compare
|
||||
|
||||
INDEX
|
||||
wcscoll_l
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
int wcscoll_l(const wchar_t *<[stra]>, const wchar_t * <[strb]>,
|
||||
locale_t <[locale]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<wcscoll_l>> compares the wide-character string pointed to by
|
||||
<[stra]> to the wide-character string pointed to by <[strb]>,
|
||||
using an interpretation appropriate to the current <<LC_COLLATE>>
|
||||
state.
|
||||
|
||||
(NOT Cygwin:) The current implementation of <<wcscoll_l>> simply
|
||||
uses <<wcscmp>> and does not support any language-specific sorting.
|
||||
|
||||
If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the
|
||||
behaviour is undefined.
|
||||
|
||||
RETURNS
|
||||
If the first string is greater than the second string,
|
||||
<<wcscoll_l>> returns a number greater than zero. If the two
|
||||
strings are equivalent, <<wcscoll_l>> returns zero. If the first
|
||||
string is less than the second string, <<wcscoll_l>> returns a
|
||||
number less than zero.
|
||||
|
||||
PORTABILITY
|
||||
<<wcscoll_l>> is POSIX-1.2008.
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <wchar.h>
|
||||
|
||||
int
|
||||
wcscoll_l (const wchar_t *a, const wchar_t *b, struct __locale_t *locale)
|
||||
{
|
||||
return wcscmp (a, b);
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcscpy>>---copy a wide-character string
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
wchar_t *wcscpy(wchar_t *__restrict <[s1]>,
|
||||
const wchar_t *__restrict <[s2]>);
|
||||
|
||||
DESCRIPTION
|
||||
The <<wcscpy>> function copies the wide-character string pointed to by
|
||||
<[s2]> (including the terminating null wide-character code) into the
|
||||
array pointed to by <[s1]>. If copying takes place between objects that
|
||||
overlap, the behaviour is undefined.
|
||||
|
||||
RETURNS
|
||||
The <<wcscpy>> function returns <[s1]>; no return value is reserved to
|
||||
indicate an error.
|
||||
|
||||
PORTABILITY
|
||||
<<wcscpy>> is ISO/IEC 9899/AMD1:1995 (ISO C).
|
||||
|
||||
No supporting OS subroutines are required.
|
||||
*/
|
||||
|
||||
/* $NetBSD: wcscpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c)1999 Citrus Project,
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* citrus Id: wcscpy.c,v 1.2 2000/12/21 04:51:09 itojun Exp
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *
|
||||
wcscpy (wchar_t *__restrict s1,
|
||||
const wchar_t *__restrict s2)
|
||||
{
|
||||
wchar_t *p;
|
||||
const wchar_t *q;
|
||||
|
||||
*s1 = '\0';
|
||||
p = s1;
|
||||
q = s2;
|
||||
while (*q)
|
||||
*p++ = *q++;
|
||||
*p = '\0';
|
||||
|
||||
return s1;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcscspn>>---get length of a complementary wide substring
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
size_t wcscspn(const wchar_t *<[s]>, wchar_t *<[set]>);
|
||||
|
||||
DESCRIPTION
|
||||
The <<wcscspn>> function computes the length of the maximum initial
|
||||
segment of the wide-character string pointed to by <[s]> which consists
|
||||
entirely of wide-character codes not from the wide-character string
|
||||
pointed to by <[set]>.
|
||||
|
||||
RETURNS
|
||||
The <<wcscspn>> function returns the length of the initial substring of
|
||||
<[s1]>; no return value is reserved to indicate an error.
|
||||
|
||||
PORTABILITY
|
||||
<<wcscspn>> is ISO/IEC 9899/AMD1:1995 (ISO C).
|
||||
|
||||
No supporting OS subroutines are required.
|
||||
*/
|
||||
|
||||
/* $NetBSD: wcscspn.c,v 1.1 2000/12/23 23:14:36 itojun Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c)1999 Citrus Project,
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* citrus Id: wcscspn.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <wchar.h>
|
||||
|
||||
size_t
|
||||
wcscspn (const wchar_t * s,
|
||||
const wchar_t * set)
|
||||
{
|
||||
const wchar_t *p;
|
||||
const wchar_t *q;
|
||||
|
||||
p = s;
|
||||
while (*p)
|
||||
{
|
||||
q = set;
|
||||
while (*q)
|
||||
{
|
||||
if (*p == *q)
|
||||
goto done;
|
||||
q++;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
done:
|
||||
return (p - s);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcsdup>>---wide character string duplicate
|
||||
|
||||
INDEX
|
||||
wcsdup
|
||||
INDEX
|
||||
_wcsdup_r
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
wchar_t *wcsdup(const wchar_t *<[str]>);
|
||||
|
||||
#include <wchar.h>
|
||||
wchar_t *_wcsdup_r(struct _reent *<[ptr]>, const wchar_t *<[str]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<wcsdup>> allocates a new wide character string using <<malloc>>,
|
||||
and copies the content of the argument <[str]> into the newly
|
||||
allocated string, thus making a copy of <[str]>.
|
||||
|
||||
RETURNS
|
||||
<<wcsdup>> returns a pointer to the copy of <[str]> if enough
|
||||
memory for the copy was available. Otherwise it returns NULL
|
||||
and errno is set to ENOMEM.
|
||||
|
||||
PORTABILITY
|
||||
POSIX-1.2008
|
||||
|
||||
QUICKREF
|
||||
wcsdup
|
||||
*/
|
||||
|
||||
#include <reent.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *
|
||||
_wcsdup_r (struct _reent *p, const wchar_t *str)
|
||||
{
|
||||
size_t len = wcslen (str) + 1;
|
||||
wchar_t *copy = _malloc_r (p, len * sizeof (wchar_t));
|
||||
if (copy)
|
||||
wmemcpy (copy, str, len);
|
||||
return copy;
|
||||
}
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
|
||||
wchar_t *
|
||||
wcsdup (const wchar_t *str)
|
||||
{
|
||||
return _wcsdup_r (_REENT, str);
|
||||
}
|
||||
|
||||
#endif /* !_REENT_ONLY */
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcslcat>>---concatenate wide-character strings to specified length
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
size_t wcslcat(wchar_t *<[dst]>, const wchar_t *<[src]>, size_t <[siz]>);
|
||||
|
||||
DESCRIPTION
|
||||
The <<wcslcat>> function appends wide characters from <[src]> to
|
||||
end of the <[dst]> wide-character string so that the resultant
|
||||
wide-character string is not more than <[siz]> wide characters
|
||||
including the terminating null wide-character code. A terminating
|
||||
null wide character is always added unless <[siz]> is 0. Thus,
|
||||
the maximum number of wide characters that can be appended from
|
||||
<[src]> is <[siz]> - 1. If copying takes place between objects
|
||||
that overlap, the behaviour is undefined.
|
||||
|
||||
RETURNS
|
||||
Wide-character string length of initial <[dst]> plus the
|
||||
wide-character string length of <[src]> (does not include
|
||||
terminating null wide-characters). If the return value is
|
||||
greater than or equal to <[siz]>, then truncation occurred and
|
||||
not all wide characters from <[src]> were appended.
|
||||
|
||||
PORTABILITY
|
||||
No supporting OS subroutines are required.
|
||||
*/
|
||||
|
||||
/* $OpenBSD: wcslcat.c,v 1.7 2019/01/25 00:19:25 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <wchar.h>
|
||||
|
||||
/*
|
||||
* Appends src to string dst of size dsize (unlike strncat, dsize is the
|
||||
* full size of dst, not space left). At most dsize-1 characters
|
||||
* will be copied. Always NUL terminates (unless dsize <= wcslen(dst)).
|
||||
* Returns wcslen(src) + MIN(dsize, wcslen(initial dst)).
|
||||
* If retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
wcslcat (wchar_t *dst,
|
||||
const wchar_t *src,
|
||||
size_t dsize)
|
||||
{
|
||||
const wchar_t *odst = dst;
|
||||
const wchar_t *osrc = src;
|
||||
size_t n = dsize;
|
||||
size_t dlen;
|
||||
|
||||
/* Find the end of dst and adjust bytes left but don't go past end. */
|
||||
while (n-- != 0 && *dst != L'\0')
|
||||
dst++;
|
||||
dlen = dst - odst;
|
||||
n = dsize - dlen;
|
||||
|
||||
if (n-- == 0)
|
||||
return(dlen + wcslen(src));
|
||||
while (*src != L'\0') {
|
||||
if (n != 0) {
|
||||
*dst++ = *src;
|
||||
n--;
|
||||
}
|
||||
src++;
|
||||
}
|
||||
*dst = L'\0';
|
||||
|
||||
return(dlen + (src - osrc)); /* count does not include NUL */
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcslcpy>>---copy a wide-character string to specified length
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
size_t wcslcpy(wchar_t *<[dst]>, const wchar_t *<[src]>, size_t <[siz]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<wcslcpy>> copies wide characters from <[src]> to <[dst]>
|
||||
such that up to <[siz]> - 1 characters are copied. A
|
||||
terminating null is appended to the result, unless <[siz]>
|
||||
is zero.
|
||||
|
||||
RETURNS
|
||||
<<wcslcpy>> returns the number of wide characters in <[src]>,
|
||||
not including the terminating null wide character. If the
|
||||
return value is greater than or equal to <[siz]>, then
|
||||
not all wide characters were copied from <[src]> and truncation
|
||||
occurred.
|
||||
|
||||
PORTABILITY
|
||||
No supporting OS subroutines are required.
|
||||
*/
|
||||
|
||||
/* $OpenBSD: wcslcpy.c,v 1.8 2019/01/25 00:19:25 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <wchar.h>
|
||||
|
||||
/*
|
||||
* Copy string src to buffer dst of size dsize. At most dsize-1
|
||||
* chars will be copied. Always NUL terminates (unless dsize == 0).
|
||||
* Returns wcslen(src); if retval >= dsize, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
wcslcpy (wchar_t *dst,
|
||||
const wchar_t *src,
|
||||
size_t dsize)
|
||||
{
|
||||
const wchar_t *osrc = src;
|
||||
size_t nleft = dsize;
|
||||
|
||||
/* Copy as many bytes as will fit. */
|
||||
if (nleft != 0) {
|
||||
while (--nleft != 0) {
|
||||
if ((*dst++ = *src++) == L'\0')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Not enough room in dst, add NUL and traverse rest of src. */
|
||||
if (nleft == 0) {
|
||||
if (dsize != 0)
|
||||
*dst = L'\0'; /* NUL-terminate dst */
|
||||
while (*src++)
|
||||
;
|
||||
}
|
||||
|
||||
return(src - osrc - 1); /* count does not include NUL */
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcslen>>---get wide-character string length
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
size_t wcslen(const wchar_t *<[s]>);
|
||||
|
||||
DESCRIPTION
|
||||
The <<wcslen>> function computes the number of wide-character codes
|
||||
in the wide-character string to which <[s]> points, not including the
|
||||
terminating null wide-character code.
|
||||
|
||||
RETURNS
|
||||
The <<wcslen>> function returns the length of <[s]>; no return value is
|
||||
reserved to indicate an error.
|
||||
|
||||
PORTABILITY
|
||||
<<wcslen>> is ISO/IEC 9899/AMD1:1995 (ISO C).
|
||||
|
||||
No supporting OS subroutines are required.
|
||||
*/
|
||||
|
||||
/* $NetBSD: wcslen.c,v 1.1 2000/12/23 23:14:36 itojun Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c)1999 Citrus Project,
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* citrus Id: wcslen.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <wchar.h>
|
||||
|
||||
size_t
|
||||
wcslen (const wchar_t * s)
|
||||
{
|
||||
const wchar_t *p;
|
||||
|
||||
p = s;
|
||||
while (*p)
|
||||
p++;
|
||||
|
||||
return p - s;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcsncasecmp>>---case-insensitive wide character string compare
|
||||
|
||||
INDEX
|
||||
wcsncasecmp
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
int wcsncasecmp(const wchar_t *<[a]>, const wchar_t * <[b]>, size_t <[length]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<wcsncasecmp>> compares up to <[length]> wide characters
|
||||
from the string at <[a]> to the string at <[b]> in a
|
||||
case-insensitive manner.
|
||||
|
||||
RETURNS
|
||||
|
||||
If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after
|
||||
both are converted to uppercase), <<wcsncasecmp>> returns a
|
||||
number greater than zero. If the two strings are equivalent,
|
||||
<<wcsncasecmp>> returns zero. If <<*<[a]>>> sorts
|
||||
lexicographically before <<*<[b]>>>, <<wcsncasecmp>> returns a
|
||||
number less than zero.
|
||||
|
||||
PORTABILITY
|
||||
POSIX-1.2008
|
||||
|
||||
<<wcsncasecmp>> requires no supporting OS subroutines. It uses
|
||||
tolower() from elsewhere in this library.
|
||||
|
||||
QUICKREF
|
||||
wcsncasecmp
|
||||
*/
|
||||
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
|
||||
int
|
||||
wcsncasecmp (const wchar_t *s1,
|
||||
const wchar_t *s2,
|
||||
size_t n)
|
||||
{
|
||||
int d = 0;
|
||||
for ( ; n != 0; n--)
|
||||
{
|
||||
const int c1 = towlower (*s1++);
|
||||
const int c2 = towlower (*s2++);
|
||||
if (((d = c1 - c2) != 0) || (c2 == '\0'))
|
||||
break;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcsncasecmp_l>>---case-insensitive wide character string compare
|
||||
|
||||
INDEX
|
||||
wcsncasecmp_l
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
int wcsncasecmp_l(const wchar_t *<[a]>, const wchar_t * <[b]>,
|
||||
size_t <[length]>, locale_t <[locale]>);
|
||||
|
||||
DESCRIPTION
|
||||
<<wcsncasecmp_l>> compares up to <[length]> wide characters
|
||||
from the string at <[a]> to the string at <[b]> in a
|
||||
case-insensitive manner.
|
||||
|
||||
if <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the
|
||||
behaviour is undefined.
|
||||
|
||||
RETURNS
|
||||
|
||||
If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after
|
||||
both are converted to uppercase), <<wcsncasecmp_l>> returns a
|
||||
number greater than zero. If the two strings are equivalent,
|
||||
<<wcsncasecmp_l>> returns zero. If <<*<[a]>>> sorts
|
||||
lexicographically before <<*<[b]>>>, <<wcsncasecmp_l>> returns a
|
||||
number less than zero.
|
||||
|
||||
PORTABILITY
|
||||
POSIX-1.2008
|
||||
|
||||
<<wcsncasecmp_l>> requires no supporting OS subroutines. It uses
|
||||
tolower() from elsewhere in this library.
|
||||
|
||||
QUICKREF
|
||||
wcsncasecmp_l
|
||||
*/
|
||||
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
|
||||
int
|
||||
wcsncasecmp_l (const wchar_t *s1, const wchar_t *s2, size_t n,
|
||||
struct __locale_t *locale)
|
||||
{
|
||||
int d = 0;
|
||||
for ( ; n != 0; n--)
|
||||
{
|
||||
const int c1 = towlower_l (*s1++, locale);
|
||||
const int c2 = towlower_l (*s2++, locale);
|
||||
if (((d = c1 - c2) != 0) || (c2 == '\0'))
|
||||
break;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcsncat>>---concatenate part of two wide-character strings
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
wchar_t *wcsncat(wchar_t *__restrict <[s1]>,
|
||||
const wchar_t *__restrict <[s2]>, size_t <[n]>);
|
||||
|
||||
DESCRIPTION
|
||||
The <<wcsncat>> function appends not more than <[n]> wide-character
|
||||
codes (a null wide-character code and wide-character codes that follow
|
||||
it are not appended) from the array pointed to by <[s2]> to the end of
|
||||
the wide-character string pointed to by <[s1]>. The initial
|
||||
wide-character code of <[s2]> overwrites the null wide-character code
|
||||
at the end of <[s1]>.
|
||||
A terminating null wide-character code is always appended to the result.
|
||||
If copying takes place between objects that overlap, the behaviour is
|
||||
undefined.
|
||||
|
||||
RETURNS
|
||||
The <<wcsncat>> function returns <[s1]>; no return value is reserved to
|
||||
indicate an error.
|
||||
|
||||
PORTABILITY
|
||||
<<wcsncat>> is ISO/IEC 9899/AMD1:1995 (ISO C).
|
||||
|
||||
No supporting OS subroutines are required.
|
||||
*/
|
||||
|
||||
/* $NetBSD: wcsncat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c)1999 Citrus Project,
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* citrus Id: wcsncat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *
|
||||
wcsncat (wchar_t *__restrict s1,
|
||||
const wchar_t *__restrict s2,
|
||||
size_t n)
|
||||
{
|
||||
wchar_t *p;
|
||||
wchar_t *q;
|
||||
const wchar_t *r;
|
||||
|
||||
p = s1;
|
||||
while (*p)
|
||||
p++;
|
||||
q = p;
|
||||
r = s2;
|
||||
while (*r && n)
|
||||
{
|
||||
*q++ = *r++;
|
||||
n--;
|
||||
}
|
||||
*q = '\0';
|
||||
return s1;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcsncmp>>---compare part of two wide-character strings
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
int wcsncmp(const wchar_t *<[s1]>, const wchar_t *<[s2]>, size_t <[n]>);
|
||||
|
||||
DESCRIPTION
|
||||
The <<wcsncmp>> function compares not more than <[n]> wide-character
|
||||
codes (wide-character codes that follow a null wide-character code are
|
||||
not compared) from the array pointed to by <[s1]> to the array pointed
|
||||
to by <[s2]>.
|
||||
|
||||
The sign of a non-zero return value is determined by the sign of the
|
||||
difference between the values of the first pair of wide-character codes
|
||||
that differ in the objects being compared.
|
||||
|
||||
RETURNS
|
||||
Upon successful completion, <<wcsncmp>> returns an integer greater than,
|
||||
equal to or less than 0, if the possibly null-terminated array pointed
|
||||
to by <[s1]> is greater than, equal to or less than the possibly
|
||||
null-terminated array pointed to by <[s2]> respectively.
|
||||
|
||||
PORTABILITY
|
||||
<<wcsncmp>> is ISO/IEC 9899/AMD1:1995 (ISO C).
|
||||
|
||||
No supporting OS subroutines are required.
|
||||
*/
|
||||
|
||||
/* $NetBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <wchar.h>
|
||||
|
||||
int
|
||||
wcsncmp (const wchar_t * s1,
|
||||
const wchar_t * s2,
|
||||
size_t n)
|
||||
{
|
||||
|
||||
if (n == 0)
|
||||
return (0);
|
||||
do
|
||||
{
|
||||
if (*s1 != *s2++)
|
||||
{
|
||||
return (*s1 - *--s2);
|
||||
}
|
||||
if (*s1++ == 0)
|
||||
break;
|
||||
}
|
||||
while (--n != 0);
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcsncpy>>---copy part of a wide-character string
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
wchar_t *wcsncpy(wchar_t *__restrict <[s1]>,
|
||||
const wchar_t *__restrict <[s2]>, size_t <[n]>);
|
||||
|
||||
DESCRIPTION
|
||||
The <<wcsncpy>> function copies not more than <[n]> wide-character codes
|
||||
(wide-character codes that follow a null wide-character code are not
|
||||
copied) from the array pointed to by <[s2]> to the array pointed to
|
||||
by <[s1]>. If copying takes place between objects that overlap, the
|
||||
behaviour is undefined. Note that if <[s1]> contains more than <[n]>
|
||||
wide characters before its terminating null, the result is not
|
||||
null-terminated.
|
||||
|
||||
If the array pointed to by <[s2]> is a wide-character string that is
|
||||
shorter than <[n]> wide-character codes, null wide-character codes are
|
||||
appended to the copy in the array pointed to by <[s1]>, until <[n]>
|
||||
wide-character codes in all are written.
|
||||
|
||||
RETURNS
|
||||
The <<wcsncpy>> function returns <[s1]>; no return value is reserved to
|
||||
indicate an error.
|
||||
|
||||
PORTABILITY
|
||||
ISO/IEC 9899; POSIX.1.
|
||||
|
||||
No supporting OS subroutines are required.
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *
|
||||
wcsncpy (wchar_t *__restrict s1,
|
||||
const wchar_t *__restrict s2,
|
||||
size_t n)
|
||||
{
|
||||
wchar_t *dscan=s1;
|
||||
|
||||
while(n > 0)
|
||||
{
|
||||
--n;
|
||||
if((*dscan++ = *s2++) == L'\0') break;
|
||||
}
|
||||
while(n-- > 0) *dscan++ = L'\0';
|
||||
|
||||
return s1;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<wcsnlen>>---get fixed-size wide-character string length
|
||||
|
||||
INDEX
|
||||
wcsnlen
|
||||
|
||||
SYNOPSIS
|
||||
#include <wchar.h>
|
||||
size_t wcsnlen(const wchar_t *<[s]>, size_t <[maxlen]>);
|
||||
|
||||
DESCRIPTION
|
||||
The <<wcsnlen>> function computes the number of wide-character codes
|
||||
in the wide-character string pointed to by <[s]> not including the
|
||||
terminating L'\0' wide character but at most <[maxlen]> wide
|
||||
characters.
|
||||
|
||||
RETURNS
|
||||
<<wcsnlen>> returns the length of <[s]> if it is less then <[maxlen]>,
|
||||
or <[maxlen]> if there is no L'\0' wide character in first <[maxlen]>
|
||||
characters.
|
||||
|
||||
PORTABILITY
|
||||
<<wcsnlen>> is a GNU extension.
|
||||
|
||||
<<wcsnlen>> requires no supporting OS subroutines.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, Artem B. Bityuckiy (dedekind@mail.ru).
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the above copyright notice,
|
||||
* this condition statement, and the following disclaimer are retained
|
||||
* in any redistributions of the source code.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <sys/types.h>
|
||||
#include <wchar.h>
|
||||
|
||||
size_t
|
||||
wcsnlen (const wchar_t *s,
|
||||
size_t maxlen)
|
||||
{
|
||||
const wchar_t *p;
|
||||
|
||||
p = s;
|
||||
while (*p && maxlen-- > 0)
|
||||
p++;
|
||||
|
||||
return (size_t)(p - s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loaded 100 of 2546 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user