1154815Sphk/*-
2154815Sphk * Copyright (c) 2005 Poul-Henning Kamp
3154815Sphk * All rights reserved.
4154815Sphk *
5154815Sphk * Redistribution and use in source and binary forms, with or without
6154815Sphk * modification, are permitted provided that the following conditions
7154815Sphk * are met:
8154815Sphk * 1. Redistributions of source code must retain the above copyright
9154815Sphk *    notice, this list of conditions and the following disclaimer.
10154815Sphk * 2. Redistributions in binary form must reproduce the above copyright
11154815Sphk *    notice, this list of conditions and the following disclaimer in the
12154815Sphk *    documentation and/or other materials provided with the distribution.
13154815Sphk *
14154815Sphk * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15154815Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16154815Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17154815Sphk * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18154815Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19154815Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20154815Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21154815Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22154815Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23154815Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24154815Sphk * SUCH DAMAGE.
25154815Sphk *
26154815Sphk * $FreeBSD$
27154815Sphk */
28154815Sphk
29154815Sphk#include <namespace.h>
30154815Sphk#include <stdio.h>
31154815Sphk#include <string.h>
32154815Sphk#include <stdlib.h>
33154815Sphk#include <wchar.h>
34154815Sphk#include <vis.h>
35154815Sphk#include <assert.h>
36154815Sphk#include <sys/time.h>
37255108Sjilles#include "errlst.h"
38154815Sphk#include "printf.h"
39154815Sphk
40154815Sphkint
41154815Sphk__printf_arginfo_errno(const struct printf_info *pi __unused, size_t n, int *argt)
42154815Sphk{
43154815Sphk
44154815Sphk	assert(n >= 1);
45154815Sphk	argt[0] = PA_INT;
46154815Sphk	return (1);
47154815Sphk}
48154815Sphk
49154815Sphkint
50154815Sphk__printf_render_errno(struct __printf_io *io, const struct printf_info *pi __unused, const void *const *arg)
51154815Sphk{
52154815Sphk	int ret, error;
53154815Sphk	char buf[64];
54154815Sphk	const char *p;
55154815Sphk
56154815Sphk	ret = 0;
57154815Sphk	error = *((const int *)arg[0]);
58255108Sjilles	if (error >= 0 && error < __hidden_sys_nerr) {
59154815Sphk		p = strerror(error);
60154815Sphk		return (__printf_out(io, pi, p, strlen(p)));
61154815Sphk	}
62154815Sphk	sprintf(buf, "errno=%d/0x%x", error, error);
63154815Sphk	ret += __printf_out(io, pi, buf, strlen(buf));
64154815Sphk	__printf_flush(io);
65154815Sphk	return(ret);
66154815Sphk}
67