| @@ -1,17 +1,35 @@ | |||
| 1 | + | ## macOS | |
| 2 | + | ||
| 1 | 3 | ``` | |
| 2 | 4 | $ uname -a | |
| 3 | 5 | Darwin tessier.local 25.5.0 Darwin Kernel Version 25.5.0: Tue Jun 9 22:27:52 PDT 2026; root:xnu-12377.121.10~1/RELEASE_ARM64_T8112 arm64 | |
| 4 | 6 | ||
| 5 | 7 | $ sh | |
| 6 | 8 | sh-3.2$ cc -o wat wat.c $(ldns-config --cflags --libs) -I$(brew --prefix openssl@3)/include | |
| 9 | + | ||
| 7 | 10 | sh-3.2$ LC_ALL=C ./wat | |
| 8 | 11 | LC_CTYPE=C isprint(255)=0 | |
| 9 | 12 | in example.net. 300 IN TXT "a\255b" | |
| 10 | 13 | out 22 61 5c 32 35 35 62 22 <- ASCII, ok | |
| 11 | - | sh-3.2$ | |
| 12 | - | LC_ALL=e | |
| 14 | + | ||
| 13 | 15 | sh-3.2$ LC_ALL=en_US.UTF-8 ./wat | |
| 14 | 16 | LC_CTYPE=en_US.UTF-8 isprint(255)=1 | |
| 15 | 17 | in example.net. 300 IN TXT "a\255b" | |
| 16 | 18 | out 22 61 ff 62 22 <- raw 0xff, expected \255 | |
| 17 | 19 | ``` | |
| 20 | + | ||
| 21 | + | ## FreeBSD | |
| 22 | + | ||
| 23 | + | ``` | |
| 24 | + | dch@wintermute /tmp> cc -o wat wat.c -L/usr/local/lib -lcrypto -lldns -I/usr/local/include | |
| 25 | + | ||
| 26 | + | dch@wintermute /tmp> LC_ALL=en_US.UTF-8 ./wat | |
| 27 | + | LC_CTYPE=en_US.UTF-8 isprint(255)=0 | |
| 28 | + | in example.net. 300 IN TXT "a\255b" | |
| 29 | + | out 22 61 5c 32 35 35 62 22 <- ASCII, ok | |
| 30 | + | ||
| 31 | + | dch@wintermute /tmp> LC_ALL=C ./wat | |
| 32 | + | LC_CTYPE=C isprint(255)=0 | |
| 33 | + | in example.net. 300 IN TXT "a\255b" | |
| 34 | + | out 22 61 5c 32 35 35 62 22 <- ASCII, ok | |
| 35 | + | ``` | |
Expires 4 months from now
locale-dependent output
| @@ -0,0 +1,40 @@ | |||
| 1 | + | /* | |
| 2 | + | * ldns_rdf2str() output depends on the caller's LC_CTYPE. | |
| 3 | + | * | |
| 4 | + | * cc -o wat wat.c $(ldns-config --cflags --libs) \ | |
| 5 | + | * -I$(brew --prefix openssl@3)/include | |
| 6 | + | * | |
| 7 | + | * LC_ALL=C ./wat | |
| 8 | + | * LC_ALL=en_US.UTF-8 ./wat | |
| 9 | + | */ | |
| 10 | + | #include <ldns/ldns.h> | |
| 11 | + | #include <ctype.h> | |
| 12 | + | #include <locale.h> | |
| 13 | + | #include <stdio.h> | |
| 14 | + | ||
| 15 | + | int | |
| 16 | + | main(void) | |
| 17 | + | { | |
| 18 | + | ldns_rr *rr = NULL; | |
| 19 | + | const char *zone = "example.net. 300 IN TXT \"a\\255b\""; | |
| 20 | + | ||
| 21 | + | /* the Erlang emulator does this on the way up; so do many others */ | |
| 22 | + | printf("LC_CTYPE=%-12s isprint(255)=%d\n", setlocale(LC_CTYPE, ""), | |
| 23 | + | isprint(255)); | |
| 24 | + | ||
| 25 | + | if (ldns_rr_new_frm_str(&rr, zone, 0, NULL, NULL) != LDNS_STATUS_OK) | |
| 26 | + | return 1; | |
| 27 | + | ||
| 28 | + | char *str = ldns_rdf2str(ldns_rr_rdf(rr, 0)); | |
| 29 | + | printf("in %s\nout ", zone); | |
| 30 | + | for (unsigned char *p = (unsigned char *)str; *p; p++) | |
| 31 | + | printf("%02x ", *p); | |
| 32 | + | ||
| 33 | + | for (unsigned char *p = (unsigned char *)str; *p; p++) | |
| 34 | + | if (*p >= 0x80) { | |
| 35 | + | printf("<- raw 0x%02x, expected \\%03u\n", *p, *p); | |
| 36 | + | return 1; | |
| 37 | + | } | |
| 38 | + | printf("<- ASCII, ok\n"); | |
| 39 | + | return 0; | |
| 40 | + | } | |
| @@ -0,0 +1,17 @@ | |||
| 1 | + | ``` | |
| 2 | + | $ uname -a | |
| 3 | + | Darwin tessier.local 25.5.0 Darwin Kernel Version 25.5.0: Tue Jun 9 22:27:52 PDT 2026; root:xnu-12377.121.10~1/RELEASE_ARM64_T8112 arm64 | |
| 4 | + | ||
| 5 | + | $ sh | |
| 6 | + | sh-3.2$ cc -o wat wat.c $(ldns-config --cflags --libs) -I$(brew --prefix openssl@3)/include | |
| 7 | + | sh-3.2$ LC_ALL=C ./wat | |
| 8 | + | LC_CTYPE=C isprint(255)=0 | |
| 9 | + | in example.net. 300 IN TXT "a\255b" | |
| 10 | + | out 22 61 5c 32 35 35 62 22 <- ASCII, ok | |
| 11 | + | sh-3.2$ | |
| 12 | + | LC_ALL=e | |
| 13 | + | sh-3.2$ LC_ALL=en_US.UTF-8 ./wat | |
| 14 | + | LC_CTYPE=en_US.UTF-8 isprint(255)=1 | |
| 15 | + | in example.net. 300 IN TXT "a\255b" | |
| 16 | + | out 22 61 ff 62 22 <- raw 0xff, expected \255 | |
| 17 | + | ``` | |