xref: /freebsd/lib/libc/gen/uexterr_format.c (revision a56fe703c2065069cf756bbafcb3dc35c25f5343)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2025 The FreeBSD Foundation
5  * All rights reserved.
6  *
7  * This software were developed by Konstantin Belousov <kib@FreeBSD.org>
8  * under sponsorship from the FreeBSD Foundation.
9  */
10 
11 #include <sys/types.h>
12 #include <sys/exterrvar.h>
13 #include <exterr.h>
14 #include <stdio.h>
15 #include <string.h>
16 
17 int
__uexterr_format(const struct uexterror * ue,char * buf,size_t bufsz)18 __uexterr_format(const struct uexterror *ue, char *buf, size_t bufsz)
19 {
20 	if (bufsz > UEXTERROR_MAXLEN)
21 		bufsz = UEXTERROR_MAXLEN;
22 	if (ue->error == 0) {
23 		strlcpy(buf, "No error", bufsz);
24 		return (0);
25 	}
26 	snprintf(buf, bufsz,
27 	    "errno %d category %u (src line %u) p1 %#jx p2 %#jx %s",
28 	    ue->error, ue->cat, ue->src_line,
29 	    (uintmax_t)ue->p1, (uintmax_t)ue->p2, ue->msg);
30 	return (0);
31 }
32