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> 37154815Sphk#include "printf.h" 38154815Sphk 39154815Sphkint 40154815Sphk__printf_arginfo_errno(const struct printf_info *pi __unused, size_t n, int *argt) 41154815Sphk{ 42154815Sphk 43154815Sphk assert(n >= 1); 44154815Sphk argt[0] = PA_INT; 45154815Sphk return (1); 46154815Sphk} 47154815Sphk 48154815Sphkint 49154815Sphk__printf_render_errno(struct __printf_io *io, const struct printf_info *pi __unused, const void *const *arg) 50154815Sphk{ 51154815Sphk int ret, error; 52154815Sphk char buf[64]; 53154815Sphk const char *p; 54154815Sphk 55154815Sphk ret = 0; 56154815Sphk error = *((const int *)arg[0]); 57154815Sphk if (error >= 0 && error < sys_nerr) { 58154815Sphk p = strerror(error); 59154815Sphk return (__printf_out(io, pi, p, strlen(p))); 60154815Sphk } 61154815Sphk sprintf(buf, "errno=%d/0x%x", error, error); 62154815Sphk ret += __printf_out(io, pi, buf, strlen(buf)); 63154815Sphk __printf_flush(io); 64154815Sphk return(ret); 65154815Sphk} 66