xref: /netbsd-src/sys/lib/libsa/strerror.c (revision 1c038e6834cae6806ebb97ae00a41d67e4d72ae1)
1*1c038e68Sisaki /*	$NetBSD: strerror.c,v 1.20 2007/11/24 13:20:57 isaki Exp $	*/
26668f51cScgd 
336b52a82Sbrezak /*-
436b52a82Sbrezak  * Copyright (c) 1993
536b52a82Sbrezak  *	The Regents of the University of California.  All rights reserved.
636b52a82Sbrezak  *
736b52a82Sbrezak  * Redistribution and use in source and binary forms, with or without
836b52a82Sbrezak  * modification, are permitted provided that the following conditions
936b52a82Sbrezak  * are met:
1036b52a82Sbrezak  * 1. Redistributions of source code must retain the above copyright
1136b52a82Sbrezak  *    notice, this list of conditions and the following disclaimer.
1236b52a82Sbrezak  * 2. Redistributions in binary form must reproduce the above copyright
1336b52a82Sbrezak  *    notice, this list of conditions and the following disclaimer in the
1436b52a82Sbrezak  *    documentation and/or other materials provided with the distribution.
15aad01611Sagc  * 3. Neither the name of the University nor the names of its contributors
1636b52a82Sbrezak  *    may be used to endorse or promote products derived from this software
1736b52a82Sbrezak  *    without specific prior written permission.
1836b52a82Sbrezak  *
1936b52a82Sbrezak  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2036b52a82Sbrezak  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2136b52a82Sbrezak  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2236b52a82Sbrezak  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2336b52a82Sbrezak  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2436b52a82Sbrezak  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2536b52a82Sbrezak  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2636b52a82Sbrezak  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2736b52a82Sbrezak  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2836b52a82Sbrezak  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2936b52a82Sbrezak  * SUCH DAMAGE.
3036b52a82Sbrezak  */
3136b52a82Sbrezak 
3258642764Scgd #include <sys/types.h>
3336b52a82Sbrezak #include "saerrno.h"
3482e5cf06Spk #include "stand.h"
3536b52a82Sbrezak 
362c4edf02Sdsl static const struct mi {
372c4edf02Sdsl 	int	errno;
38b508e546Schristos 	const char *msg;
392c4edf02Sdsl } errlist[] = {
402c4edf02Sdsl 	{ EADAPT,	"bad adaptor number" },
412c4edf02Sdsl 	{ ECTLR,	"bad controller number" },
422c4edf02Sdsl 	{ EUNIT,	"bad drive number" },
432c4edf02Sdsl 	{ EPART,	"bad partition" },
442c4edf02Sdsl 	{ ERDLAB,	"can't read disk label" },
452c4edf02Sdsl 	{ EUNLAB,	"unlabeled" },
462c4edf02Sdsl 	{ ENXIO,	"Device not configured" },
472c4edf02Sdsl 	{ EPERM,	"Operation not permitted" },
482c4edf02Sdsl 	{ ENOENT,	"No such file or directory" },
492c4edf02Sdsl 	{ ESTALE,	"Stale NFS file handle" },
502c4edf02Sdsl 	{ EFTYPE,	"Inappropriate file type or format" },
512c4edf02Sdsl 	{ ENOEXEC,	"Exec format error" },
522c4edf02Sdsl 	{ EIO,		"Input/output error" },
532c4edf02Sdsl 	{ EINVAL,	"Invalid argument" },
542c4edf02Sdsl 	{ ENOTDIR,	"Not a directory" },
552c4edf02Sdsl 	{ EOFFSET,	"invalid file offset" },
56dd688f88Sdrochner 	{ EACCES,	"Permission denied" },
57*1c038e68Sisaki 	{ 0, 0 },
58*1c038e68Sisaki };
592c4edf02Sdsl 
6036b52a82Sbrezak char *
strerror(int err)612c4edf02Sdsl strerror(int err)
6236b52a82Sbrezak {
632c4edf02Sdsl 	static	char ebuf[36];
642c4edf02Sdsl 	const struct mi *mi;
6536b52a82Sbrezak 
662c4edf02Sdsl 	for (mi = errlist; mi->msg; mi++)
672c4edf02Sdsl 		if (mi->errno == err)
68af063921Schristos 			return __UNCONST(mi->msg);
6936b52a82Sbrezak 
702c4edf02Sdsl 	snprintf(ebuf, sizeof ebuf, "Unknown error: code %d", err);
7136b52a82Sbrezak 	return ebuf;
7236b52a82Sbrezak }
73