Subject: Re: 64-bit daddr_t problems with libsa
To: <>
From: David Laight <david@l8s.co.uk>
List: tech-kern
Date: 01/30/2003 15:24:05
> On pmax however, we're still 40 bytes over...

This change to strerror.c might win that back.
I'll commit it now if you want...

	David

Index: strerror.c
===================================================================
RCS file: /cvsroot/src/sys/lib/libsa/strerror.c,v
retrieving revision 1.13
diff -u -r1.13 strerror.c
--- strerror.c	2002/02/17 23:18:32	1.13
+++ strerror.c	2003/01/30 15:18:32
@@ -37,48 +37,38 @@
 #include "saerrno.h"
 #include "stand.h"
 
+static struct mi {
+	int	errno;
+	char	*msg;
+} errlist[] = {
+	{ EADAPT,	"bad adaptor number" },
+	{ ECTLR,	"bad controller number" },
+	{ EUNIT,	"bad drive number" },
+	{ EPART,	"bad partition" },
+	{ ERDLAB,	"can't read disk label" },
+	{ EUNLAB,	"unlabeled" },
+	{ ENXIO,	"Device not configured" },
+	{ EPERM,	"Operation not permitted" },
+	{ ENOENT,	"No such file or directory" },
+	{ ESTALE,	"Stale NFS file handle" },
+	{ EFTYPE,	"Inappropriate file type or format" },
+	{ ENOEXEC,	"Exec format error" },
+	{ EIO,		"Input/output error" },
+	{ EINVAL,	"Invalid argument" },
+	{ ENOTDIR,	"Not a directory" },
+	{ EOFFSET,	"invalid file offset" },
+	{ 0, 0 } };
+
 char *
-strerror(err)
-	int err;
+strerror(int err)
 {
-static	char ebuf[64];
+	static	char ebuf[] = "Unknown error: code 999";
+	struct mi *mi;
 
-	switch (err) {
-	case EADAPT:
-		return "bad adaptor number";
-	case ECTLR:
-		return "bad controller number";
-	case EUNIT:
-		return "bad drive number";
-	case EPART:
-		return "bad partition";
-	case ERDLAB:
-		return "can't read disk label";
-	case EUNLAB:
-		return "unlabeled";
-	case ENXIO:
-		return "Device not configured";
-	case EPERM:
-		return "Operation not permitted";
-	case ENOENT:
-		return "No such file or directory";
-	case ESTALE:
-		return "Stale NFS file handle";
-	case EFTYPE:
-		return "Inappropriate file type or format";
-	case ENOEXEC:
-		return "Exec format error";
-	case EIO:
-		return "Input/output error";
-	case EINVAL:
-		return "Invalid argument";
-	case ENOTDIR:
-		return "Not a directory";
-	case EOFFSET:
-		return "invalid file offset";
+	for (mi = errlist; mi->msg; mi++)
+		if (mi->errno == err)
+			return mi->msg;
 
-	default:
-		sprintf(ebuf, "Unknown error: code %d", err);
-		return ebuf;
-	}
+	snprintf(ebuf + sizeof ebuf - 4, 3, "%d", err);
+	return ebuf;
 }

-- 
David Laight: david@l8s.co.uk