str_error.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010 Martin Decky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #include <errno.h>
00036 #include <str_error.h>
00037 #include <stdio.h>
00038 #include <fibril.h>
00039 
00040 #define MIN_ERRNO  -17
00041 #define NOERR_LEN  64
00042 
00043 static const char* err_desc[] = {
00044         "No error",
00045         "No such entry",
00046         "Not enough memory",
00047         "Limit exceeded", 
00048         "Connection refused",
00049         "Forwarding error",
00050         "Permission denied",
00051         "Answerbox closed connection",
00052         "Other party error",
00053         "Entry already exists",
00054         "Bad memory pointer",
00055         "Not supported",
00056         "Address not available",
00057         "Timeout expired",
00058         "Invalid value",
00059         "Resource is busy",
00060         "Result does not fit its size",
00061         "Operation interrupted"
00062 };
00063 
00064 static fibril_local char noerr[NOERR_LEN];
00065 
00066 const char *str_error(const int e)
00067 {
00068         if ((e <= 0) && (e >= MIN_ERRNO))
00069                 return err_desc[-e];
00070         
00071         /* Ad hoc descriptions of error codes interesting for USB. */
00072         switch (e) {
00073                 case EBADCHECKSUM:
00074                         return "Bad checksum";
00075                 case ESTALL:
00076                         return "Operation stalled";
00077                 case EAGAIN:
00078                         return "Resource temporarily unavailable";
00079                 case EEMPTY:
00080                         return "Resource is empty";
00081                 default:
00082                         break;
00083         }
00084 
00085         snprintf(noerr, NOERR_LEN, "Unkown error code %d", e);
00086         return noerr;
00087 }
00088 

Generated on Thu Jun 2 07:45:46 2011 for HelenOS/USB by  doxygen 1.4.7