wave-nix.cpp

Go to the documentation of this file.
00001 /*
00002  * wave-nix.cpp
00003  *
00004  * Copyright (C) 2011  Thomas A. Vaughan
00005  * All rights reserved.
00006  *
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *     * Redistributions of source code must retain the above copyright
00011  *       notice, this list of conditions and the following disclaimer.
00012  *     * Redistributions in binary form must reproduce the above copyright
00013  *       notice, this list of conditions and the following disclaimer in the
00014  *       documentation and/or other materials provided with the distribution.
00015  *     * Neither the name of the <organization> nor the
00016  *       names of its contributors may be used to endorse or promote products
00017  *       derived from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY
00020  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022  * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY
00023  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00024  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00026  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  *
00031  * Very basic helper routines and classes for working with *nix APIs.
00032  */
00033 
00034 
00035 // includes --------------------------------------------------------------------
00036 #include "wave-nix.h"           // always include our own header first!
00037 
00038 #include "linux/errno.h"
00039 
00040 
00041 ////////////////////////////////////////////////////////////////////////////////
00042 //
00043 //      static helper methods
00044 //
00045 ////////////////////////////////////////////////////////////////////////////////
00046 
00047 
00048 
00049 ////////////////////////////////////////////////////////////////////////////////
00050 //
00051 //      public API
00052 //
00053 ////////////////////////////////////////////////////////////////////////////////
00054 
00055 #define DIAGNOSE_CODE(x) case x :                                       \
00056                 stream << "Error code " << x << ": " << #x << "\n";     \
00057                 break;
00058 
00059 
00060 void
00061 dumpErrorInfo
00062 (
00063 IN std::ostream& stream,
00064 IN int errorCode
00065 )
00066 {
00067         ASSERT_THROW(stream.good(), "bad stream?");
00068 
00069         switch (errorCode) {
00070 
00071         // list common *nix error codes in alphabetical order
00072         DIAGNOSE_CODE(EACCES)
00073         DIAGNOSE_CODE(EADDRINUSE)
00074         DIAGNOSE_CODE(EAGAIN)
00075         DIAGNOSE_CODE(EBADF)
00076         DIAGNOSE_CODE(EBUSY)
00077         DIAGNOSE_CODE(EDEADLK)
00078         DIAGNOSE_CODE(EFAULT)
00079         DIAGNOSE_CODE(EINVAL)
00080         DIAGNOSE_CODE(EIO)
00081         DIAGNOSE_CODE(ENOENT)
00082         DIAGNOSE_CODE(ENOSPC)
00083         DIAGNOSE_CODE(ENOSTR)
00084         DIAGNOSE_CODE(ENOTBLK)
00085         DIAGNOSE_CODE(ENOTSOCK)
00086         DIAGNOSE_CODE(ENXIO)
00087         DIAGNOSE_CODE(EPERM)
00088         DIAGNOSE_CODE(EPIPE)
00089 
00090         default:
00091                 stream << "Unknown error code! " << errorCode << "\n";
00092         }
00093 }
00094