2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2015 Joyent, Inc.
23 * This is designed to test strerorr and strerror_l's ability to react properly
24 * to being in various locales. This also serves as a regression test for
27 * For this test, we utilize the poorly named 'zz_AA.UTF_8' locale which
28 * was created because it actually has a translation! It 'translates'
31 * "No such file or directory" -> "It's a trap!"
33 * It's otherwise a boring en_US.UTF-8 locale under the hood.
35 * We explicitly want to verify the following cases:
37 * + strerror() honors the global locale before uselocale
38 * + strerror() honors the per-thread locale
39 * + strerror_l() always reflects the chosen locale
42 static int err
= ENOENT
;
43 static const char *en
= "No such file or directory";
44 static const char *trans
= "It's a trap!";
47 strerror_verify(const char *exp
)
53 assert(strcmp(r
, exp
) == 0);
57 strerror_l_verify(locale_t loc
, const char *exp
)
61 r
= strerror_l(err
, loc
);
63 assert(strcmp(r
, exp
) == 0);
71 (void) setlocale(LC_ALL
, "C");
74 (void) setlocale(LC_ALL
, "zz_AA.UTF-8");
75 strerror_verify(trans
);
77 (void) setlocale(LC_MESSAGES
, "C");
80 (void) setlocale(LC_ALL
, "C");
81 loc
= newlocale(LC_MESSAGES_MASK
, "zz_AA.UTF-8", NULL
);
85 strerror_l_verify(NULL
, en
);
86 strerror_l_verify(loc
, trans
);
88 (void) uselocale(loc
);
89 strerror_verify(trans
);
90 strerror_l_verify(NULL
, trans
);
91 strerror_l_verify(loc
, trans
);
93 (void) uselocale(LC_GLOBAL_LOCALE
);
95 strerror_l_verify(NULL
, en
);
96 strerror_l_verify(loc
, trans
);