Mercurial > hg > octave-kai > gnulib-hg
annotate lib/strerror.c @ 4739:04758f7475fd
Merge changes from glibc.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Fri, 26 Sep 2003 07:35:01 +0000 |
parents | e9cc723f9777 |
children | a48fb0e98c8c |
rev | line source |
---|---|
3928 | 1 /* strerror.c --- ANSI C compatible system error routine |
2 | |
4487
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
3 Copyright (C) 1986, 1988, 1989, 1991, 2002, 2003 Free Software |
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
4 Foundation, Inc. |
3928 | 5 |
6 This program is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 2, or (at your option) | |
9 any later version. | |
10 | |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with this program; if not, write to the Free Software Foundation, | |
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
19 | |
4487
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
20 #if HAVE_CONFIG_H |
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
21 # include <config.h> |
3928 | 22 #endif |
23 | |
4487
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
24 #include <limits.h> |
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
25 |
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
26 /* Don't include <stdio.h>, since it may or may not declare |
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
27 sys_errlist and its declarations may collide with ours. Just |
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
28 declare the stuff that we need directly. Standard hosted C89 |
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
29 implementations define strerror and they don't need this strerror |
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
30 function, so take some liberties with the standard to cater to |
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
31 ancient or limited freestanding implementations. */ |
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
32 int sprintf (char *, char const *, ...); |
3928 | 33 extern int sys_nerr; |
34 extern char *sys_errlist[]; | |
35 | |
36 char * | |
4487
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
37 strerror (int n) |
3928 | 38 { |
4487
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
39 static char const fmt[] = "Unknown error (%d)"; |
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
40 static char mesg[sizeof fmt + sizeof n * CHAR_BIT / 3]; |
3928 | 41 |
4487
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
42 if (n < 0 || n >= sys_nerr) |
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
43 { |
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
44 sprintf (mesg, fmt, n); |
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
45 return mesg; |
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
46 } |
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
47 else |
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
48 return sys_errlist[n]; |
3928 | 49 } |