1 /*
2  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3  */
4 
5 #pragma ident	"@(#)mkerrno.sh	1.2	08/07/31	SMI"
6 
7 #include <strings.h>
8 #include <scsi/libsmp.h>
9 
10 static const struct {
11 	char *name;		/* error name */
12 	char *msg;		/* error message */
13 } _smp_errstr[] = {
14 	{ "ESMP_NONE",	"no error" },
15 	{ "ESMP_NOMEM",	"no memory" },
16 	{ "ESMP_ZERO_LENGTH","zero-length allocation requested" },
17 	{ "ESMP_VERSION",	"library version mismatch" },
18 	{ "ESMP_BADTARGET",	"invalid target specification" },
19 	{ "ESMP_BADFUNC",	"invalid SMP function" },
20 	{ "ESMP_BADENGINE",	"engine library corrupt" },
21 	{ "ESMP_NOENGINE",	"engine library not found" },
22 	{ "ESMP_ENGINE_INIT","engine initialization failed" },
23 	{ "ESMP_ENGINE_VER","engine version mismatch" },
24 	{ "ESMP_ENGINE_BADPATH","engine path contains no usable components" },
25 	{ "ESMP_BADLENGTH",	"buffer length overflow or size error" },
26 	{ "ESMP_NEEDBUF",	"missing required buffer" },
27 	{ "ESMP_PLUGIN",	"no plugins found" },
28 	{ "ESMP_IO",	"I/O operation failed" },
29 	{ "ESMP_SYS",	"system call failed" },
30 	{ "ESMP_PERM",	"insufficient permissions" },
31 	{ "ESMP_RANGE",	"parameter outside valid range" },
32 	{ "ESMP_NOTSUP",	"operation not supported" },
33 	{ "ESMP_UNKNOWN",	"error of unknown type" },
34 	{ "ESMP_REPGEN_FAILED","initial report general command failed" },
35 	{ "ESMP_MAX",	"maximum libsmp errno value" },
36 };
37 
38 static int _smp_nerrno = sizeof (_smp_errstr) /
39     sizeof (_smp_errstr[0]);
40 
41 const char *
42 smp_strerror(smp_errno_t err)
43 {
44 	return (err < 0 || err >= _smp_nerrno ? "unknown error" :
45 	     _smp_errstr[err].msg);
46 }
47 
48 const char *
49 smp_errname(smp_errno_t err)
50 {
51 	return (err < 0 || err >= _smp_nerrno ? NULL :
52 	     _smp_errstr[err].name);
53 }
54 
55 smp_errno_t
56 smp_errcode(const char *name)
57 {
58 	smp_errno_t err;
59 
60 	for (err = 0; err < _smp_nerrno; err++) {
61 		if (strcmp(name, _smp_errstr[err].name) == 0)
62 			return (err);
63 	}
64 
65 	return (ESMP_UNKNOWN);
66 }
67