xref: /freebsd/lib/libc/gen/uexterr_gettext.c (revision a5b0b2a7d4219ae86f152433b6fcecd9e8c767d6)
1a56fe703SKonstantin Belousov /*-
2a56fe703SKonstantin Belousov  * SPDX-License-Identifier: BSD-2-Clause
3a56fe703SKonstantin Belousov  *
4a56fe703SKonstantin Belousov  * Copyright (c) 2025 The FreeBSD Foundation
5a56fe703SKonstantin Belousov  * All rights reserved.
6a56fe703SKonstantin Belousov  *
7a56fe703SKonstantin Belousov  * This software were developed by Konstantin Belousov <kib@FreeBSD.org>
8a56fe703SKonstantin Belousov  * under sponsorship from the FreeBSD Foundation.
9a56fe703SKonstantin Belousov  */
10a56fe703SKonstantin Belousov 
11*a5b0b2a7SBrooks Davis #define	_WANT_P_OSREL
12*a5b0b2a7SBrooks Davis #include <sys/param.h>
13b9c8a07dSKonstantin Belousov #include <sys/exterrvar.h>
14b9c8a07dSKonstantin Belousov #include <exterr.h>
15b9c8a07dSKonstantin Belousov #include <string.h>
16a56fe703SKonstantin Belousov #include "libc_private.h"
17b9c8a07dSKonstantin Belousov 
18b9c8a07dSKonstantin Belousov static struct uexterror uexterr = {
19b9c8a07dSKonstantin Belousov 	.ver = UEXTERROR_VER,
20b9c8a07dSKonstantin Belousov };
21b9c8a07dSKonstantin Belousov 
22*a5b0b2a7SBrooks Davis int __getosreldate(void);
23*a5b0b2a7SBrooks Davis 
24b9c8a07dSKonstantin Belousov static void uexterr_ctr(void) __attribute__((constructor));
25b9c8a07dSKonstantin Belousov static void
uexterr_ctr(void)26b9c8a07dSKonstantin Belousov uexterr_ctr(void)
27b9c8a07dSKonstantin Belousov {
28*a5b0b2a7SBrooks Davis 	if (__getosreldate() >= P_OSREL_EXTERRCTL)
29b9c8a07dSKonstantin Belousov 		exterrctl(EXTERRCTL_ENABLE, 0, &uexterr);
30b9c8a07dSKonstantin Belousov }
31a56fe703SKonstantin Belousov 
32a56fe703SKonstantin Belousov int
__libc_uexterr_gettext(char * buf,size_t bufsz)33a56fe703SKonstantin Belousov __libc_uexterr_gettext(char *buf, size_t bufsz)
34a56fe703SKonstantin Belousov {
35a56fe703SKonstantin Belousov 	return (__uexterr_format(&uexterr, buf, bufsz));
36a56fe703SKonstantin Belousov }
37a56fe703SKonstantin Belousov 
38a56fe703SKonstantin Belousov int
uexterr_gettext(char * buf,size_t bufsz)39a56fe703SKonstantin Belousov uexterr_gettext(char *buf, size_t bufsz)
40a56fe703SKonstantin Belousov {
41a56fe703SKonstantin Belousov 	return (((int (*)(char *, size_t))
42a56fe703SKonstantin Belousov 	    __libc_interposing[INTERPOS_uexterr_gettext])(buf, bufsz));
43a56fe703SKonstantin Belousov }
44