/* * ldns_rdf2str() output depends on the caller's LC_CTYPE. * * cc -o wat wat.c $(ldns-config --cflags --libs) \ * -I$(brew --prefix openssl@3)/include * * LC_ALL=C ./wat * LC_ALL=en_US.UTF-8 ./wat */ #include #include #include #include int main(void) { ldns_rr *rr = NULL; const char *zone = "example.net. 300 IN TXT \"a\\255b\""; /* the Erlang emulator does this on the way up; so do many others */ printf("LC_CTYPE=%-12s isprint(255)=%d\n", setlocale(LC_CTYPE, ""), isprint(255)); if (ldns_rr_new_frm_str(&rr, zone, 0, NULL, NULL) != LDNS_STATUS_OK) return 1; char *str = ldns_rdf2str(ldns_rr_rdf(rr, 0)); printf("in %s\nout ", zone); for (unsigned char *p = (unsigned char *)str; *p; p++) printf("%02x ", *p); for (unsigned char *p = (unsigned char *)str; *p; p++) if (*p >= 0x80) { printf("<- raw 0x%02x, expected \\%03u\n", *p, *p); return 1; } printf("<- ASCII, ok\n"); return 0; }