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.
14 * Copyright 2024 Oxide Computer Company
21 #include <sys/debug.h>
24 * This is designed to test strerorr and strerror_l's ability to react properly
25 * to being in various locales. This also serves as a regression test for
26 * illumos#6133. This also tests that strerrordesc_np() does not translate
29 * For this test, we utilize the poorly named 'zz_AA.UTF_8' locale which
30 * was created because it actually has a translation! It 'translates'
33 * "No such file or directory" -> "It's a trap!"
35 * It's otherwise a boring en_US.UTF-8 locale under the hood.
37 * We explicitly want to verify the following cases:
39 * + strerror() honors the global locale before uselocale
40 * + strerror() honors the per-thread locale
41 * + strerror_l() always reflects the chosen locale
44 static int terr
= ENOENT
;
45 static const char *en
= "No such file or directory";
46 static const char *trans
= "It's a trap!";
49 strerror_verify(const char *exp
)
55 VERIFY0(strcmp(r
, exp
));
59 strerror_l_verify(locale_t loc
, const char *exp
)
63 r
= strerror_l(terr
, loc
);
65 VERIFY0(strcmp(r
, exp
));
69 strerrordesc_verify(const char *exp
)
73 r
= strerrordesc_np(terr
);
75 VERIFY0(strcmp(r
, exp
));
79 strerrorname_verify(int errnum
, const char *exp
)
83 r
= strerrorname_np(errnum
);
85 VERIFY0(strcmp(r
, exp
));
93 (void) setlocale(LC_ALL
, "C");
95 strerrordesc_verify(en
);
96 strerrorname_verify(0, "0");
97 strerrorname_verify(EIO
, "EIO");
99 (void) setlocale(LC_ALL
, "zz_AA.UTF-8");
100 strerror_verify(trans
);
101 strerrordesc_verify(en
);
102 strerrorname_verify(ENOENT
, "ENOENT");
103 strerrorname_verify(ENOTSUP
, "ENOTSUP");
105 (void) setlocale(LC_MESSAGES
, "C");
107 strerrordesc_verify(en
);
108 strerrorname_verify(EMFILE
, "EMFILE");
110 (void) setlocale(LC_ALL
, "C");
111 loc
= newlocale(LC_MESSAGES_MASK
, "zz_AA.UTF-8", NULL
);
115 strerror_l_verify(NULL
, en
);
116 strerror_l_verify(loc
, trans
);
117 strerrordesc_verify(en
);
118 strerrorname_verify(ENFILE
, "ENFILE");
120 (void) uselocale(loc
);
121 strerror_verify(trans
);
122 strerror_l_verify(NULL
, trans
);
123 strerror_l_verify(loc
, trans
);
124 strerrordesc_verify(en
);
125 strerrorname_verify(EL2HLT
, "EL2HLT");
127 (void) uselocale(LC_GLOBAL_LOCALE
);
129 strerror_l_verify(NULL
, en
);
130 strerror_l_verify(loc
, trans
);
131 strerrordesc_verify(en
);
132 strerrorname_verify(ENOTSUP
, "ENOTSUP");
135 * Validate a few different error cases. 135 is a Xenix special and 102
136 * is reserved. They both have an error message, but no actual constant.
138 VERIFY3P(strerrordesc_np(1234567), ==, NULL
);
139 VERIFY3P(strerrordesc_np(102), !=, NULL
);
140 VERIFY3P(strerrordesc_np(135), !=, NULL
);
141 VERIFY3P(strerrorname_np(1234567), ==, NULL
);
142 VERIFY3P(strerrorname_np(102), ==, NULL
);
143 VERIFY3P(strerrorname_np(135), ==, NULL
);