vm: fix potential null deref
[minix.git] / servers / rs / error.c
blob24d1342dfb65268655c8b80bff17d95fdacaca20
1 /*
2 * Changes:
3 * Mar 07, 2010: Created (Cristiano Giuffrida)
4 */
6 #include "inc.h"
8 /* A single error entry. */
9 struct errentry {
10 int errnum;
11 char* errstr;
14 /* Initialization errors. */
15 static struct errentry init_errlist[] = {
16 { ENOSYS, "service does not support the requested initialization type" }
18 static const int init_nerr = sizeof(init_errlist) / sizeof(init_errlist[0]);
20 /* Live update errors. */
21 static struct errentry lu_errlist[] = {
22 { ENOSYS, "service does not support live update" },
23 { EINVAL, "service does not support the required state" },
24 { EBUSY, "service is not able to prepare for the update now" },
25 { EGENERIC, "generic error occurred while preparing for the update" }
27 static const int lu_nerr = sizeof(lu_errlist) / sizeof(lu_errlist[0]);
29 /*===========================================================================*
30 * rs_strerror *
31 *===========================================================================*/
32 static char * rs_strerror(int errnum, struct errentry *errlist, const int nerr)
34 int i;
36 for(i=0; i < nerr; i++) {
37 if(errnum == errlist[i].errnum)
38 return errlist[i].errstr;
41 return strerror(-errnum);
44 /*===========================================================================*
45 * init_strerror *
46 *===========================================================================*/
47 char * init_strerror(int errnum)
49 return rs_strerror(errnum, init_errlist, init_nerr);
52 /*===========================================================================*
53 * lu_strerror *
54 *===========================================================================*/
55 char * lu_strerror(int errnum)
57 return rs_strerror(errnum, lu_errlist, lu_nerr);