| ... | ... | @@ -0,0 +1,192 @@ |
| 1 | const std = @import("std"); |
| 2 | const common = @import("common.zig"); |
| 3 | const builtin = @import("builtin"); |
| 4 | |
| 5 | comptime { |
| 6 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { |
| 7 | // Functions specific to musl and wasi-libc. |
| 8 | @export(&isalnum, .{ .name = "isalnum", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | @export(&isalpha, .{ .name = "isalpha", .linkage = common.linkage, .visibility = common.visibility }); |
| 10 | @export(&isblank, .{ .name = "isblank", .linkage = common.linkage, .visibility = common.visibility }); |
| 11 | @export(&iscntrl, .{ .name = "iscntrl", .linkage = common.linkage, .visibility = common.visibility }); |
| 12 | @export(&isdigit, .{ .name = "isdigit", .linkage = common.linkage, .visibility = common.visibility }); |
| 13 | @export(&isgraph, .{ .name = "isgraph", .linkage = common.linkage, .visibility = common.visibility }); |
| 14 | @export(&islower, .{ .name = "islower", .linkage = common.linkage, .visibility = common.visibility }); |
| 15 | @export(&isprint, .{ .name = "isprint", .linkage = common.linkage, .visibility = common.visibility }); |
| 16 | @export(&ispunct, .{ .name = "ispunct", .linkage = common.linkage, .visibility = common.visibility }); |
| 17 | @export(&isspace, .{ .name = "isspace", .linkage = common.linkage, .visibility = common.visibility }); |
| 18 | @export(&isupper, .{ .name = "isupper", .linkage = common.linkage, .visibility = common.visibility }); |
| 19 | @export(&isxdigit, .{ .name = "isxdigit", .linkage = common.linkage, .visibility = common.visibility }); |
| 20 | @export(&tolower, .{ .name = "tolower", .linkage = common.linkage, .visibility = common.visibility }); |
| 21 | @export(&toupper, .{ .name = "toupper", .linkage = common.linkage, .visibility = common.visibility }); |
| 22 | |
| 23 | @export(&__isalnum_l, .{ .name = "__isalnum_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 24 | @export(&__isalpha_l, .{ .name = "__isalpha_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 25 | @export(&__isblank_l, .{ .name = "__isblank_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 26 | @export(&__iscntrl_l, .{ .name = "__iscntrl_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 27 | @export(&__isdigit_l, .{ .name = "__isdigit_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 28 | @export(&__isgraph_l, .{ .name = "__isgraph_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 29 | @export(&__islower_l, .{ .name = "__islower_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 30 | @export(&__isprint_l, .{ .name = "__isprint_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 31 | @export(&__ispunct_l, .{ .name = "__ispunct_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 32 | @export(&__isspace_l, .{ .name = "__isspace_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 33 | @export(&__isupper_l, .{ .name = "__isupper_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 34 | @export(&__isxdigit_l, .{ .name = "__isxdigit_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 35 | @export(&__tolower_l, .{ .name = "__tolower_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 36 | @export(&__toupper_l, .{ .name = "__toupper_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 37 | |
| 38 | @export(&__isalnum_l, .{ .name = "isalnum_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 39 | @export(&__isalpha_l, .{ .name = "isalpha_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 40 | @export(&__isblank_l, .{ .name = "isblank_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 41 | @export(&__iscntrl_l, .{ .name = "iscntrl_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 42 | @export(&__isdigit_l, .{ .name = "isdigit_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 43 | @export(&__isgraph_l, .{ .name = "isgraph_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 44 | @export(&__islower_l, .{ .name = "islower_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 45 | @export(&__isprint_l, .{ .name = "isprint_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 46 | @export(&__ispunct_l, .{ .name = "ispunct_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 47 | @export(&__isspace_l, .{ .name = "isspace_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 48 | @export(&__isupper_l, .{ .name = "isupper_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 49 | @export(&__isxdigit_l, .{ .name = "isxdigit_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 50 | @export(&__tolower_l, .{ .name = "tolower_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 51 | @export(&__toupper_l, .{ .name = "toupper_l", .linkage = common.linkage, .visibility = common.visibility }); |
| 52 | |
| 53 | @export(&isascii, .{ .name = "isascii", .linkage = common.linkage, .visibility = common.visibility }); |
| 54 | @export(&toascii, .{ .name = "toascii", .linkage = common.linkage, .visibility = common.visibility }); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | // NOTE: If the input is not representable as an unsigned char or is not EOF the behaviour is undefined. |
| 59 | |
| 60 | fn isalnum(c: c_int) callconv(.c) c_int { |
| 61 | return @intFromBool(std.ascii.isAlphanumeric(@intCast(c))); |
| 62 | } |
| 63 | |
| 64 | fn __isalnum_l(c: c_int, locale: *anyopaque) callconv(.c) c_int { |
| 65 | _ = locale; |
| 66 | return isalnum(c); |
| 67 | } |
| 68 | |
| 69 | fn isalpha(c: c_int) callconv(.c) c_int { |
| 70 | return @intFromBool(std.ascii.isAlphabetic(@intCast(c))); |
| 71 | } |
| 72 | |
| 73 | fn __isalpha_l(c: c_int, locale: *anyopaque) callconv(.c) c_int { |
| 74 | _ = locale; |
| 75 | return isalpha(c); |
| 76 | } |
| 77 | |
| 78 | fn isblank(c: c_int) callconv(.c) c_int { |
| 79 | return @intFromBool(c == ' ' or c == '\t'); |
| 80 | } |
| 81 | |
| 82 | fn __isblank_l(c: c_int, locale: *anyopaque) callconv(.c) c_int { |
| 83 | _ = locale; |
| 84 | return isblank(c); |
| 85 | } |
| 86 | |
| 87 | fn iscntrl(c: c_int) callconv(.c) c_int { |
| 88 | return @intFromBool(std.ascii.isControl(@intCast(c))); |
| 89 | } |
| 90 | |
| 91 | fn __iscntrl_l(c: c_int, locale: *anyopaque) callconv(.c) c_int { |
| 92 | _ = locale; |
| 93 | return iscntrl(c); |
| 94 | } |
| 95 | |
| 96 | fn isdigit(c: c_int) callconv(.c) c_int { |
| 97 | return @intFromBool(std.ascii.isDigit(@intCast(c))); |
| 98 | } |
| 99 | |
| 100 | fn __isdigit_l(c: c_int, locale: *anyopaque) callconv(.c) c_int { |
| 101 | _ = locale; |
| 102 | return isdigit(c); |
| 103 | } |
| 104 | |
| 105 | fn isgraph(c: c_int) callconv(.c) c_int { |
| 106 | return @intFromBool(std.ascii.isGraphical(@intCast(c))); |
| 107 | } |
| 108 | |
| 109 | fn __isgraph_l(c: c_int, locale: *anyopaque) callconv(.c) c_int { |
| 110 | _ = locale; |
| 111 | return isgraph(c); |
| 112 | } |
| 113 | |
| 114 | fn islower(c: c_int) callconv(.c) c_int { |
| 115 | return @intFromBool(std.ascii.isLower(@intCast(c))); |
| 116 | } |
| 117 | |
| 118 | fn __islower_l(c: c_int, locale: *anyopaque) callconv(.c) c_int { |
| 119 | _ = locale; |
| 120 | return islower(c); |
| 121 | } |
| 122 | |
| 123 | fn isprint(c: c_int) callconv(.c) c_int { |
| 124 | return @intFromBool(std.ascii.isPrint(@intCast(c))); |
| 125 | } |
| 126 | |
| 127 | fn __isprint_l(c: c_int, locale: *anyopaque) callconv(.c) c_int { |
| 128 | _ = locale; |
| 129 | return isprint(c); |
| 130 | } |
| 131 | |
| 132 | fn ispunct(c: c_int) callconv(.c) c_int { |
| 133 | return @intFromBool(std.ascii.isPunctuation(@intCast(c))); |
| 134 | } |
| 135 | |
| 136 | fn __ispunct_l(c: c_int, locale: *anyopaque) callconv(.c) c_int { |
| 137 | _ = locale; |
| 138 | return ispunct(c); |
| 139 | } |
| 140 | |
| 141 | fn isspace(c: c_int) callconv(.c) c_int { |
| 142 | return @intFromBool(std.ascii.isWhitespace(@intCast(c))); |
| 143 | } |
| 144 | |
| 145 | fn __isspace_l(c: c_int, locale: *anyopaque) callconv(.c) c_int { |
| 146 | _ = locale; |
| 147 | return isspace(c); |
| 148 | } |
| 149 | |
| 150 | fn isupper(c: c_int) callconv(.c) c_int { |
| 151 | return @intFromBool(std.ascii.isUpper(@intCast(c))); |
| 152 | } |
| 153 | |
| 154 | fn __isupper_l(c: c_int, locale: *anyopaque) callconv(.c) c_int { |
| 155 | _ = locale; |
| 156 | return isupper(c); |
| 157 | } |
| 158 | |
| 159 | fn isxdigit(c: c_int) callconv(.c) c_int { |
| 160 | return @intFromBool(std.ascii.isHex(@intCast(c))); |
| 161 | } |
| 162 | |
| 163 | fn __isxdigit_l(c: c_int, locale: *anyopaque) callconv(.c) c_int { |
| 164 | _ = locale; |
| 165 | return isxdigit(c); |
| 166 | } |
| 167 | |
| 168 | fn tolower(c: c_int) callconv(.c) c_int { |
| 169 | return std.ascii.toLower(@intCast(c)); |
| 170 | } |
| 171 | |
| 172 | fn __tolower_l(c: c_int, locale: *anyopaque) callconv(.c) c_int { |
| 173 | _ = locale; |
| 174 | return tolower(c); |
| 175 | } |
| 176 | |
| 177 | fn toupper(c: c_int) callconv(.c) c_int { |
| 178 | return std.ascii.toUpper(@intCast(c)); |
| 179 | } |
| 180 | |
| 181 | fn __toupper_l(c: c_int, locale: *anyopaque) callconv(.c) c_int { |
| 182 | _ = locale; |
| 183 | return toupper(c); |
| 184 | } |
| 185 | |
| 186 | fn isascii(c: c_int) callconv(.c) c_int { |
| 187 | return @intFromBool(std.ascii.isAscii(@intCast(c))); |
| 188 | } |
| 189 | |
| 190 | fn toascii(c: c_int) callconv(.c) c_int { |
| 191 | return c & 0x7F; |
| 192 | } |