home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / mipsABI / examples / sup / errmsg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  1.8 KB  |  64 lines

  1. /*
  2.  * Copyright (c) 1991 Carnegie Mellon University
  3.  * All Rights Reserved.
  4.  * 
  5.  * Permission to use, copy, modify and distribute this software and its
  6.  * documentation is hereby granted, provided that both the copyright
  7.  * notice and this permission notice appear in all copies of the
  8.  * software, derivative works or modified versions, and any portions
  9.  * thereof, and that both notices appear in supporting documentation.
  10.  *
  11.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  12.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  13.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  14.  *
  15.  * Carnegie Mellon requests users of this software to return to
  16.  *
  17.  *  Software Distribution Coordinator   or   Software.Distribution@CS.CMU.EDU
  18.  *  School of Computer Science
  19.  *  Carnegie Mellon University
  20.  *  Pittsburgh PA 15213-3890
  21.  *
  22.  * any improvements or extensions that they make and grant Carnegie the rights
  23.  * to redistribute these changes.
  24.  */
  25. /*****************************************************************
  26.  * HISTORY
  27.  * 04-Mar-85  Rudy Nedved (ern) at Carnegie-Mellon University
  28.  *    Create a CMU version of the BBN errmsg routine from scratch. It
  29.  *    differs from the BBN errmsg routine in the fact that it uses a
  30.  *    negative value to indicate using the current errno value...the
  31.  *    BBN uses a negative OR zero value.
  32.  */
  33.  
  34. extern int    errno;
  35. extern int    sys_nerr;
  36. extern char    *sys_errlist[];
  37.  
  38. static char *itoa(p,n)
  39. char *p;
  40. unsigned n;
  41. {
  42.     if (n >= 10)
  43.     p =itoa(p,n/10);
  44.     *p++ = (n%10)+'0';
  45.     return(p);
  46. }
  47.  
  48. char *errmsg(cod)
  49. int cod;
  50. {
  51.     static char unkmsg[] = "Unknown error ";
  52.     static char unk[sizeof(unkmsg)+11];        /* trust us */
  53.  
  54.     if (cod < 0) cod = errno;
  55.  
  56.     if((cod >= 0) && (cod < sys_nerr))
  57.         return(sys_errlist[cod]);
  58.  
  59.     strcpy(unk,unkmsg);
  60.     *itoa(&unk[sizeof(unkmsg)-1],cod) = '\0';
  61.  
  62.     return(unk);
  63. }
  64.