138451Smsmith/*	$NetBSD: strerror.c,v 1.12 1997/01/25 00:37:50 cgd Exp $	*/
238451Smsmith
338451Smsmith/*-
438451Smsmith * Copyright (c) 1993
538451Smsmith *	The Regents of the University of California.  All rights reserved.
638451Smsmith *
738451Smsmith * Redistribution and use in source and binary forms, with or without
838451Smsmith * modification, are permitted provided that the following conditions
938451Smsmith * are met:
1038451Smsmith * 1. Redistributions of source code must retain the above copyright
1138451Smsmith *    notice, this list of conditions and the following disclaimer.
1238451Smsmith * 2. Redistributions in binary form must reproduce the above copyright
1338451Smsmith *    notice, this list of conditions and the following disclaimer in the
1438451Smsmith *    documentation and/or other materials provided with the distribution.
1538451Smsmith * 4. Neither the name of the University nor the names of its contributors
1638451Smsmith *    may be used to endorse or promote products derived from this software
1738451Smsmith *    without specific prior written permission.
1838451Smsmith *
1938451Smsmith * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2038451Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2138451Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2238451Smsmith * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2338451Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2438451Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2538451Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2638451Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2738451Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2838451Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2938451Smsmith * SUCH DAMAGE.
3038451Smsmith */
3138451Smsmith
3284221Sdillon#include <sys/cdefs.h>
3384221Sdillon__FBSDID("$FreeBSD$");
3484221Sdillon
3538451Smsmith#include "stand.h"
3638451Smsmith
3738451Smsmithstatic struct
3838451Smsmith{
3938451Smsmith    int		err;
4038451Smsmith    char	*msg;
4138451Smsmith} errtab[] = {
4238451Smsmith    {0,		"no error"},
4338451Smsmith    /* standard errors */
4438451Smsmith    {EPERM,		"operation not permitted"},
4538451Smsmith    {ENOENT,		"no such file or directory"},
4638451Smsmith    {EIO,		"input/output error"},
4738451Smsmith    {ENXIO,		"device not configured"},
4838451Smsmith    {ENOEXEC,		"exec format error"},
4938451Smsmith    {EBADF,		"bad file descriptor"},
5038451Smsmith    {ENOMEM,		"cannot allocate memory"},
5138451Smsmith    {ENODEV,		"operation not supported by device"},
5238451Smsmith    {ENOTDIR,		"not a directory"},
5338451Smsmith    {EISDIR,		"is a directory"},
5438451Smsmith    {EINVAL,		"invalid argument"},
5538451Smsmith    {EMFILE,		"too many open files"},
5638451Smsmith    {EFBIG,		"file too large"},
5738451Smsmith    {EROFS,		"read-only filesystem"},
5838451Smsmith    {EOPNOTSUPP,	"operation not supported"},
5938451Smsmith    {ETIMEDOUT,		"operation timed out"},
6038451Smsmith    {ESTALE,		"stale NFS file handle"},
6138451Smsmith    {EBADRPC,		"RPC struct is bad"},
6238451Smsmith    {EFTYPE,		"inappropriate file type or format"},
6338451Smsmith
6438451Smsmith    {EADAPT,		"bad adaptor number"},
6538451Smsmith    {ECTLR,		"bad controller number"},
6638451Smsmith    {EUNIT,		"bad unit number"},
6738451Smsmith    {ESLICE,		"bad slice number"},
6838451Smsmith    {EPART,		"bad partition"},
6938451Smsmith    {ERDLAB,		"can't read disk label"},
7038451Smsmith    {EUNLAB,		"disk unlabelled"},
7138451Smsmith    {EOFFSET,		"illegal seek"},
7238451Smsmith    {0,		NULL}
7338451Smsmith};
7438451Smsmith
7538451Smsmith
7638451Smsmithchar *
7738451Smsmithstrerror(int err)
7838451Smsmith{
7938451Smsmith    static char	msg[32];
8038451Smsmith    int		i;
8138451Smsmith
8238451Smsmith    for (i = 0; errtab[i].msg != NULL; i++)
8338451Smsmith	if (errtab[i].err == err)
8438451Smsmith	    return(errtab[i].msg);
8538451Smsmith    sprintf(msg, "unknown error (%d)", err);
8638451Smsmith    return(msg);
8738451Smsmith}
88