Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/strerror.c @ 8623:27cfd50b8f6c
Fix missing escape.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Tue, 03 Apr 2007 22:45:13 +0000 |
parents | 3e28c7035f38 |
children | 404ee875898f |
rev | line source |
---|---|
3928 | 1 /* strerror.c --- ANSI C compatible system error routine |
2 | |
8309
e5ee9891c553
Make it possible to compile strerror.c separately, unconditionally.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
3 Copyright (C) 1986, 1988, 1989, 1991, 2002, 2003, 2006, 2007 Free |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
4 Software 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, | |
5848
a48fb0e98c8c
*** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents:
4487
diff
changeset
|
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
3928 | 19 |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
20 #include <config.h> |
3928 | 21 |
8320
3e28c7035f38
Oops, really avoid an empty translation unit.
Bruno Haible <bruno@clisp.org>
parents:
8309
diff
changeset
|
22 #if !HAVE_STRERROR |
4487
e9cc723f9777
Include config.h, limits.h. Declare sprintf.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3928
diff
changeset
|
23 |
8320
3e28c7035f38
Oops, really avoid an empty translation unit.
Bruno Haible <bruno@clisp.org>
parents:
8309
diff
changeset
|
24 #include <limits.h> |
8309
e5ee9891c553
Make it possible to compile strerror.c separately, unconditionally.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
25 |
4487
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 } |
8309
e5ee9891c553
Make it possible to compile strerror.c separately, unconditionally.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
50 |
8320
3e28c7035f38
Oops, really avoid an empty translation unit.
Bruno Haible <bruno@clisp.org>
parents:
8309
diff
changeset
|
51 #else |
3e28c7035f38
Oops, really avoid an empty translation unit.
Bruno Haible <bruno@clisp.org>
parents:
8309
diff
changeset
|
52 |
3e28c7035f38
Oops, really avoid an empty translation unit.
Bruno Haible <bruno@clisp.org>
parents:
8309
diff
changeset
|
53 /* This declaration is solely to ensure that after preprocessing |
3e28c7035f38
Oops, really avoid an empty translation unit.
Bruno Haible <bruno@clisp.org>
parents:
8309
diff
changeset
|
54 this file is never empty. */ |
3e28c7035f38
Oops, really avoid an empty translation unit.
Bruno Haible <bruno@clisp.org>
parents:
8309
diff
changeset
|
55 typedef int dummy; |
3e28c7035f38
Oops, really avoid an empty translation unit.
Bruno Haible <bruno@clisp.org>
parents:
8309
diff
changeset
|
56 |
3e28c7035f38
Oops, really avoid an empty translation unit.
Bruno Haible <bruno@clisp.org>
parents:
8309
diff
changeset
|
57 #endif |