xref: /minix/minix/servers/rs/error.c (revision 0a6a1f1d)
1 /*
2  * Changes:
3  *   Mar 07, 2010:  Created  (Cristiano Giuffrida)
4  */
5 
6 #include "inc.h"
7 
8 /* A single error entry. */
9 struct errentry {
10     int errnum;
11     char* errstr;
12 };
13 
14 /* Initialization errors. */
15 static struct errentry init_errlist[] = {
16   { ENOSYS,     "service does not support the requested initialization type"  },
17   { ERESTART,     "service requested an initialization reset"  }
18 };
19 static const int init_nerr = sizeof(init_errlist) / sizeof(init_errlist[0]);
20 
21 /* Live update errors. */
22 static struct errentry lu_errlist[] = {
23   { ENOSYS,     "service does not support live update"                        },
24   { EINVAL,     "service does not support the required state"                 },
25   { EBUSY,      "service is not able to prepare for the update now"           },
26   { EGENERIC,   "generic error occurred while preparing for the update"       }
27 };
28 static const int lu_nerr = sizeof(lu_errlist) / sizeof(lu_errlist[0]);
29 
30 /*===========================================================================*
31  *				  rs_strerror				     *
32  *===========================================================================*/
33 static char * rs_strerror(int errnum, struct errentry *errlist, const int nerr)
34 {
35   int i;
36 
37   for(i=0; i < nerr; i++) {
38       if(errnum == errlist[i].errnum)
39           return errlist[i].errstr;
40   }
41 
42   return strerror(-errnum);
43 }
44 
45 /*===========================================================================*
46  *				  init_strerror				     *
47  *===========================================================================*/
48 char * init_strerror(int errnum)
49 {
50   return rs_strerror(errnum, init_errlist, init_nerr);
51 }
52 
53 /*===========================================================================*
54  *				   lu_strerror				     *
55  *===========================================================================*/
56 char * lu_strerror(int errnum)
57 {
58   return rs_strerror(errnum, lu_errlist, lu_nerr);
59 }
60