1*58a2b000SEvgeniy Ivanov /* $NetBSD: strerror.c,v 1.20 2007/11/24 13:20:57 isaki Exp $ */
2*58a2b000SEvgeniy Ivanov
3*58a2b000SEvgeniy Ivanov /*-
4*58a2b000SEvgeniy Ivanov * Copyright (c) 1993
5*58a2b000SEvgeniy Ivanov * The Regents of the University of California. All rights reserved.
6*58a2b000SEvgeniy Ivanov *
7*58a2b000SEvgeniy Ivanov * Redistribution and use in source and binary forms, with or without
8*58a2b000SEvgeniy Ivanov * modification, are permitted provided that the following conditions
9*58a2b000SEvgeniy Ivanov * are met:
10*58a2b000SEvgeniy Ivanov * 1. Redistributions of source code must retain the above copyright
11*58a2b000SEvgeniy Ivanov * notice, this list of conditions and the following disclaimer.
12*58a2b000SEvgeniy Ivanov * 2. Redistributions in binary form must reproduce the above copyright
13*58a2b000SEvgeniy Ivanov * notice, this list of conditions and the following disclaimer in the
14*58a2b000SEvgeniy Ivanov * documentation and/or other materials provided with the distribution.
15*58a2b000SEvgeniy Ivanov * 3. Neither the name of the University nor the names of its contributors
16*58a2b000SEvgeniy Ivanov * may be used to endorse or promote products derived from this software
17*58a2b000SEvgeniy Ivanov * without specific prior written permission.
18*58a2b000SEvgeniy Ivanov *
19*58a2b000SEvgeniy Ivanov * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*58a2b000SEvgeniy Ivanov * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*58a2b000SEvgeniy Ivanov * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*58a2b000SEvgeniy Ivanov * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*58a2b000SEvgeniy Ivanov * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*58a2b000SEvgeniy Ivanov * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*58a2b000SEvgeniy Ivanov * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*58a2b000SEvgeniy Ivanov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*58a2b000SEvgeniy Ivanov * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*58a2b000SEvgeniy Ivanov * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*58a2b000SEvgeniy Ivanov * SUCH DAMAGE.
30*58a2b000SEvgeniy Ivanov */
31*58a2b000SEvgeniy Ivanov
32*58a2b000SEvgeniy Ivanov #include <sys/types.h>
33*58a2b000SEvgeniy Ivanov #include "saerrno.h"
34*58a2b000SEvgeniy Ivanov #include "stand.h"
35*58a2b000SEvgeniy Ivanov
36*58a2b000SEvgeniy Ivanov static const struct mi {
37*58a2b000SEvgeniy Ivanov int errno;
38*58a2b000SEvgeniy Ivanov const char *msg;
39*58a2b000SEvgeniy Ivanov } errlist[] = {
40*58a2b000SEvgeniy Ivanov { EADAPT, "bad adaptor number" },
41*58a2b000SEvgeniy Ivanov { ECTLR, "bad controller number" },
42*58a2b000SEvgeniy Ivanov { EUNIT, "bad drive number" },
43*58a2b000SEvgeniy Ivanov { EPART, "bad partition" },
44*58a2b000SEvgeniy Ivanov { ERDLAB, "can't read disk label" },
45*58a2b000SEvgeniy Ivanov { EUNLAB, "unlabeled" },
46*58a2b000SEvgeniy Ivanov { ENXIO, "Device not configured" },
47*58a2b000SEvgeniy Ivanov { EPERM, "Operation not permitted" },
48*58a2b000SEvgeniy Ivanov { ENOENT, "No such file or directory" },
49*58a2b000SEvgeniy Ivanov { ESTALE, "Stale NFS file handle" },
50*58a2b000SEvgeniy Ivanov { EFTYPE, "Inappropriate file type or format" },
51*58a2b000SEvgeniy Ivanov { ENOEXEC, "Exec format error" },
52*58a2b000SEvgeniy Ivanov { EIO, "Input/output error" },
53*58a2b000SEvgeniy Ivanov { EINVAL, "Invalid argument" },
54*58a2b000SEvgeniy Ivanov { ENOTDIR, "Not a directory" },
55*58a2b000SEvgeniy Ivanov { EOFFSET, "invalid file offset" },
56*58a2b000SEvgeniy Ivanov { EACCES, "Permission denied" },
57*58a2b000SEvgeniy Ivanov { 0, 0 },
58*58a2b000SEvgeniy Ivanov };
59*58a2b000SEvgeniy Ivanov
60*58a2b000SEvgeniy Ivanov char *
strerror(int err)61*58a2b000SEvgeniy Ivanov strerror(int err)
62*58a2b000SEvgeniy Ivanov {
63*58a2b000SEvgeniy Ivanov static char ebuf[36];
64*58a2b000SEvgeniy Ivanov const struct mi *mi;
65*58a2b000SEvgeniy Ivanov
66*58a2b000SEvgeniy Ivanov for (mi = errlist; mi->msg; mi++)
67*58a2b000SEvgeniy Ivanov if (mi->errno == err)
68*58a2b000SEvgeniy Ivanov return __UNCONST(mi->msg);
69*58a2b000SEvgeniy Ivanov
70*58a2b000SEvgeniy Ivanov snprintf(ebuf, sizeof ebuf, "Unknown error: code %d", err);
71*58a2b000SEvgeniy Ivanov return ebuf;
72*58a2b000SEvgeniy Ivanov }
73