Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <errno.h>
  5. #include <libc/unconst.h>
  6.  
  7. char *
  8. strerror(int errnum)
  9. {
  10.   static char ebuf[40];         /* 64-bit number + slop */
  11.   char *cp;
  12.   int v=1000000, lz=0;
  13.  
  14.   if (errnum >= 0 && errnum < __sys_nerr)
  15.     return(unconst(__sys_errlist[errnum], char *));
  16.  
  17.   strcpy(ebuf, "Unknown error: ");
  18.   cp = ebuf + 15;
  19.   if (errnum < 0)
  20.   {
  21.     *cp++ = '-';
  22.     errnum = -errnum;
  23.   }
  24.   while (v)
  25.   {
  26.     int d = errnum / v;
  27.     if (d || lz || (v == 1))
  28.     {
  29.       *cp++ = d+'0';
  30.       lz = 1;
  31.     }
  32.     errnum %= v;
  33.     v /= 10;
  34.   }
  35.  
  36.   return ebuf;
  37. }
  38.