strerror2.c

Go to the documentation of this file.
00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1997, 1998, 1999
00005  *      Sleepycat Software.  All rights reserved.
00006  */
00007 /*
00008  * Copyright (c) 1988, 1993
00009  *      The Regents of the University of California.  All rights reserved.
00010  *
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions
00013  * are met:
00014  * 1. Redistributions of source code must retain the above copyright
00015  *    notice, this list of conditions and the following disclaimer.
00016  * 2. Redistributions in binary form must reproduce the above copyright
00017  *    notice, this list of conditions and the following disclaimer in the
00018  *    documentation and/or other materials provided with the distribution.
00019  * 3. Neither the name of the University nor the names of its contributors
00020  *    may be used to endorse or promote products derived from this software
00021  *    without specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00024  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00027  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00028  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00029  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00032  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00033  * SUCH DAMAGE.
00034  */
00035 
00036 #ifdef HAVE_CONFIG_H
00037 #include "config.h"
00038 #endif /* HAVE_CONFIG_H */
00039 
00040 #ifndef HAVE_STRERROR
00041 
00042 /*
00043  * strerror --
00044  *      Return the string associated with an errno.
00045  *
00046  * PUBLIC: #ifndef HAVE_STRERROR
00047  * PUBLIC: char *strerror __P((int));
00048  * PUBLIC: #endif
00049  */
00050 char *
00051 strerror(num)
00052         int num;
00053 {
00054         extern int sys_nerr;
00055         extern char *sys_errlist[];
00056 #undef  UPREFIX
00057 #define UPREFIX "Unknown error: "
00058         static char ebuf[40] = UPREFIX;         /* 64-bit number + slop */
00059         int errnum;
00060         char *p, *t, tmp[40];
00061 
00062         errnum = num;                           /* convert to unsigned */
00063         if (errnum < sys_nerr)
00064                 return(sys_errlist[errnum]);
00065 
00066         /* Do this by hand, so we don't include stdio(3). */
00067         t = tmp;
00068         do {
00069                 *t++ = "0123456789"[errnum % 10];
00070         } while (errnum /= 10);
00071         for (p = ebuf + sizeof(UPREFIX) - 1;;) {
00072                 *p++ = *--t;
00073                 if (t <= tmp)
00074                         break;
00075         }
00076         return(ebuf);
00077 }
00078 
00079 #endif /* HAVE_STRERROR */

Generated on Sun Jun 8 10:56:34 2008 for GNUmifluz by  doxygen 1.5.5