err.h (3550B)
1 /* $Id: //depot/blt/netboot/err.h#2 $ 2 ** 3 ** Copyright 1998 Brian J. Swetland 4 ** All rights reserved. 5 ** 6 ** Redistribution and use in source and binary forms, with or without 7 ** modification, are permitted provided that the following conditions 8 ** are met: 9 ** 1. Redistributions of source code must retain the above copyright 10 ** notice, this list of conditions, and the following disclaimer. 11 ** 2. Redistributions in binary form must reproduce the above copyright 12 ** notice, this list of conditions, and the following disclaimer in the 13 ** documentation and/or other materials provided with the distribution. 14 ** 3. The name of the author may not be used to endorse or promote products 15 ** derived from this software without specific prior written permission. 16 ** 17 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 #ifndef __ERR 29 #define __ERR 30 31 /* NOTE If ret is negative then it is an error otherwise it returns a 32 // success code. */ 33 34 #define NUM_ERR 19 35 #define NOERR 0 36 #define ERR -1 37 #define ERRNOMEM -2 38 #define ERRRESOURCE -3 39 #define ERRMEMCORRUPT -4 40 #define ERRFORMAT -5 41 #define ERRNOTFOUND -6 42 #define ERRTYPE -7 43 #define ERRTIMEOUT -8 44 #define ERRNOTSUPPORTED -9 45 #define ERROUTOFRANGE -10 46 #define ERRPRIV -11 47 #define ERRNOTREADY -12 48 #define ERRNONEFREE -13 49 #define ERRARG -14 50 #define ERRINVALID -15 51 #define ERRNOTOPEN -16 52 #define ERRALREADYDONE -17 53 #define ERRVER -18 54 55 #define SFOUND 1 56 #define SNOTFOUND 2 57 #define SALT 3 58 59 /* Bits 16-31 are reserved for the facility code. */ 60 #define OWNOS 0x70 61 #define OWNNOMAD 0x70 62 63 #define MAX_ERR_MSG 32 64 const char err_msg[NUM_ERR][MAX_ERR_MSG] = { "success", 65 "error", 66 "out of memory", 67 "resource allocation", 68 "memory corrupt!!!", 69 "format", 70 "not found", 71 "type", 72 "timeout", 73 "not supported", 74 "out of range", 75 "access denied", 76 "not ready", 77 "none free", 78 "bad argument", 79 "invalid", 80 "not open", 81 "already done", 82 "incorrect version" }; 83 84 #ifdef __CPP_BINDING 85 extern "C" void kprintf(char *, ...); 86 class ret { 87 private: 88 int val; 89 public: 90 ret() { val=ERR; } 91 ret(int src) { val=src; } 92 ret operator=(const ret& src) { return val=src.val; } 93 ret operator=(int src) { return val=src; } 94 int operator==(const ret& cmp) { return val==cmp.val; } 95 int operator!() { return val<0; } 96 // returns 1 if error, 0 if success 97 int operator<(int cmp) { 98 //kprintf(" %d < %d\n",val,cmp); 99 // TODO implement some severity check 100 return (val<cmp); } 101 int operator<(ret& cmp) { 102 //kprintf(" %d < %d\n",val,cmp.val); 103 return (val<cmp.val); } 104 operator int() const { return val; } 105 // operator bool() { return (val<0); } 106 const char *disp() { 107 if(((val & 0x70) != 0x70) && ((val & 0x70) != 0x00)) 108 return "Unknown facility"; 109 return err_msg[-val]; } 110 }; 111 #else 112 typedef int ret; 113 #endif /* __CPP_BINDING */ 114 115 #endif /* __ERR */