strerror.c revision 84221
1304565Sed/*	$NetBSD: strerror.c,v 1.12 1997/01/25 00:37:50 cgd Exp $	*/
2304565Sed
3304565Sed/*-
4304565Sed * Copyright (c) 1993
5304565Sed *	The Regents of the University of California.  All rights reserved.
6304565Sed *
7304565Sed * Redistribution and use in source and binary forms, with or without
8304565Sed * modification, are permitted provided that the following conditions
9304565Sed * are met:
10304565Sed * 1. Redistributions of source code must retain the above copyright
11304565Sed *    notice, this list of conditions and the following disclaimer.
12304565Sed * 2. Redistributions in binary form must reproduce the above copyright
13304565Sed *    notice, this list of conditions and the following disclaimer in the
14304565Sed *    documentation and/or other materials provided with the distribution.
15304565Sed * 3. All advertising materials mentioning features or use of this software
16304565Sed *    must display the following acknowledgement:
17304565Sed *	This product includes software developed by the University of
18304565Sed *	California, Berkeley and its contributors.
19304565Sed * 4. Neither the name of the University nor the names of its contributors
20304565Sed *    may be used to endorse or promote products derived from this software
21304565Sed *    without specific prior written permission.
22304565Sed *
23304565Sed * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24304565Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25304565Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26304565Sed * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27304565Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28304565Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29304565Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30304565Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31304565Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32304565Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33304565Sed * SUCH DAMAGE.
34304565Sed */
35304565Sed
36304565Sed#include <sys/cdefs.h>
37304565Sed__FBSDID("$FreeBSD: head/lib/libstand/strerror.c 84221 2001-09-30 22:28:01Z dillon $");
38304565Sed
39304565Sed#include "stand.h"
40304565Sed
41304565Sedstatic struct
42324250Sed{
43324250Sed    int		err;
44324250Sed    char	*msg;
45324250Sed} errtab[] = {
46324250Sed    {0,		"no error"},
47325858Sed    /* standard errors */
48325858Sed    {EPERM,		"operation not permitted"},
49325858Sed    {ENOENT,		"no such file or directory"},
50325858Sed    {EIO,		"input/output error"},
51325858Sed    {ENXIO,		"device not configured"},
52325858Sed    {ENOEXEC,		"exec format error"},
53325858Sed    {EBADF,		"bad file descriptor"},
54325858Sed    {ENOMEM,		"cannot allocate memory"},
55325858Sed    {ENODEV,		"operation not supported by device"},
56325858Sed    {ENOTDIR,		"not a directory"},
57325858Sed    {EISDIR,		"is a directory"},
58304565Sed    {EINVAL,		"invalid argument"},
59    {EMFILE,		"too many open files"},
60    {EFBIG,		"file too large"},
61    {EROFS,		"read-only filesystem"},
62    {EOPNOTSUPP,	"operation not supported"},
63    {ETIMEDOUT,		"operation timed out"},
64    {ESTALE,		"stale NFS file handle"},
65    {EBADRPC,		"RPC struct is bad"},
66    {EFTYPE,		"inappropriate file type or format"},
67
68    {EADAPT,		"bad adaptor number"},
69    {ECTLR,		"bad controller number"},
70    {EUNIT,		"bad unit number"},
71    {ESLICE,		"bad slice number"},
72    {EPART,		"bad partition"},
73    {ERDLAB,		"can't read disk label"},
74    {EUNLAB,		"disk unlabelled"},
75    {EOFFSET,		"illegal seek"},
76    {0,		NULL}
77};
78
79
80char *
81strerror(int err)
82{
83    static char	msg[32];
84    int		i;
85
86    for (i = 0; errtab[i].msg != NULL; i++)
87	if (errtab[i].err == err)
88	    return(errtab[i].msg);
89    sprintf(msg, "unknown error (%d)", err);
90    return(msg);
91}
92