~ubuntu-branches/ubuntu/maverick/texinfo/maverick

« back to all changes in this revision

Viewing changes to lib/strerror.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2005-10-28 15:10:30 UTC
  • mto: (2.1.1 dapper) (3.1.4 hardy)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20051028151030-9nsf2s2k2z3fktjt
Tags: upstream-4.8
ImportĀ upstreamĀ versionĀ 4.8

Show diffs side-by-side

added added

removed removed

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