OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uC-libc/] [error/] [error.c] - Blame information for rev 1775

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/* Copyright (C) 1996 Robert de Bath <robert@debath.thenet.co.uk>
2
 * This file is part of the Linux-8086 C library and is distributed
3
 * under the GNU Library General Public License.
4
 */
5
#include <string.h>
6
 
7
char **__sys_errlist =0;
8
int __sys_nerr = 0;
9
 
10
char *
11
strerror(err)
12
int err;
13
{
14
   int fd;
15
   static char retbuf[80];
16
   char inbuf[256];
17
   int cc;
18
   int bufoff = 0;
19
 
20
   if( __sys_nerr )
21
   {
22
      if( err < 0 || err >= __sys_nerr ) goto unknown;
23
      return __sys_errlist[err];
24
   }
25
 
26
   if( err <= 0 ) goto unknown;  /* NB the <= allows comments in the file */
27
   fd = open("/usr/lib/liberror.txt", 0);
28
   if (fd < 0) fd = open("/lib/liberror.txt", 0);
29
   if( fd < 0 ) goto unknown;
30
 
31
   while( (cc=read(fd, inbuf, sizeof(inbuf))) > 0 )
32
   {
33
      int i;
34
      for(i=0; i<cc; i++)
35
      {
36
         if( inbuf[i] == '\n' )
37
         {
38
            retbuf[bufoff] = '\0';
39
            if( err == atoi(retbuf) )
40
            {
41
               char * p = strchr(retbuf, ' ');
42
               if( p == 0 ) goto unknown;
43
               while(*p == ' ') p++;
44
               close(fd);
45
               return p;
46
            }
47
            bufoff = 0;
48
         }
49
         else if( bufoff < sizeof(retbuf)-1 )
50
            retbuf[bufoff++] = inbuf[i];
51
      }
52
   }
53
unknown:;
54
   if( fd >= 0 ) close(fd);
55
   strcpy(retbuf, "Unknown error ");
56
   strcpy(retbuf+14, itoa(err));
57
   return retbuf;
58
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.