~ubuntu-branches/ubuntu/karmic/dante/karmic

« back to all changes in this revision

Viewing changes to libscompat/strerror.c

  • Committer: Bazaar Package Importer
  • Author(s): Adrian Bridgett
  • Date: 2002-04-07 12:45:55 UTC
  • Revision ID: james.westby@ubuntu.com-20020407124555-qke8rt2tdor0naz2
Tags: upstream-1.1.11.12p1
ImportĀ upstreamĀ versionĀ 1.1.11.12p1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: strerror.c,v 1.3 1999/05/13 16:35:58 karls Exp $ */
 
2
 
 
3
#ifdef HAVE_CONFIG_H
 
4
#include "autoconf.h"
 
5
#endif  /* HAVE_CONFIG_H */
 
6
 
 
7
#include "common.h"
 
8
 
 
9
#if !HAVE_STRERROR
 
10
 
 
11
/*
 
12
 * Copyright (c) 1988 Regents of the University of California.
 
13
 * All rights reserved.
 
14
 *
 
15
 * Redistribution and use in source and binary forms, with or without
 
16
 * modification, are permitted provided that the following conditions
 
17
 * are met:
 
18
 * 1. Redistributions of source code must retain the above copyright
 
19
 *    notice, this list of conditions and the following disclaimer.
 
20
 * 2. Redistributions in binary form must reproduce the above copyright
 
21
 *    notice, this list of conditions and the following disclaimer in the
 
22
 *    documentation and/or other materials provided with the distribution.
 
23
 * 3. All advertising materials mentioning features or use of this software
 
24
 *    must display the following acknowledgement:
 
25
 *      This product includes software developed by the University of
 
26
 *      California, Berkeley and its contributors.
 
27
 * 4. Neither the name of the University nor the names of its contributors
 
28
 *    may be used to endorse or promote products derived from this software
 
29
 *    without specific prior written permission.
 
30
 *
 
31
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 
32
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
33
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
34
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 
35
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
36
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 
37
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
38
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
39
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 
40
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
41
 * SUCH DAMAGE.
 
42
 */
 
43
 
 
44
#if defined(LIBC_SCCS) && !defined(lint)
 
45
static char *rcsid = "$OpenBSD: __strerror.c,v 1.6 1996/09/25 08:17:30 deraadt Exp $";
 
46
#endif /* LIBC_SCCS and not lint */
 
47
 
 
48
#ifndef NL_TEXTMAX
 
49
#define NL_TEXTMAX 255
 
50
#endif  /* !NL_TEXTMAX */
 
51
 
 
52
int sys_nerr;
 
53
char *sys_errlist[];
 
54
int errno;
 
55
 
 
56
#if 0
 
57
#include <errno.h>
 
58
#include <limits.h>
 
59
#include <stdio.h>
 
60
#include <string.h>
 
61
#endif
 
62
 
 
63
static char *itoa(num)
 
64
        int num;
 
65
{
 
66
        static char buffer[11];
 
67
        char *p;
 
68
 
 
69
        p = buffer + 4;
 
70
        while (num >= 10) {
 
71
                *--p = (num % 10) + '0';
 
72
                num /= 10;
 
73
        }
 
74
        *p = (num % 10) + '0';
 
75
        return p;
 
76
}
 
77
 
 
78
/*
 
79
 * Since perror() is not allowed to change the contents of strerror()'s
 
80
 * static buffer, both functions supply their own buffers to the
 
81
 * internal function __strerror().
 
82
 */
 
83
 
 
84
char *
 
85
__strerror(num, buf)
 
86
        int num;
 
87
        char *buf;
 
88
{
 
89
#define UPREFIX "Unknown error: "
 
90
        register unsigned int errnum;
 
91
 
 
92
 
 
93
        errnum = num;                           /* convert to unsigned */
 
94
        if (errnum < sys_nerr) {
 
95
                return(sys_errlist[errnum]);
 
96
        } else {
 
97
                strcpy(buf, UPREFIX);
 
98
                strncat(buf, itoa(errnum), NL_TEXTMAX-strlen(buf)-1);
 
99
        }
 
100
 
 
101
        return buf;
 
102
}
 
103
 
 
104
/*
 
105
 * Copyright (c) 1988 Regents of the University of California.
 
106
 * All rights reserved.
 
107
 *
 
108
 * Redistribution and use in source and binary forms, with or without
 
109
 * modification, are permitted provided that the following conditions
 
110
 * are met:
 
111
 * 1. Redistributions of source code must retain the above copyright
 
112
 *    notice, this list of conditions and the following disclaimer.
 
113
 * 2. Redistributions in binary form must reproduce the above copyright
 
114
 *    notice, this list of conditions and the following disclaimer in the
 
115
 *    documentation and/or other materials provided with the distribution.
 
116
 * 3. All advertising materials mentioning features or use of this software
 
117
 *    must display the following acknowledgement:
 
118
 *      This product includes software developed by the University of
 
119
 *      California, Berkeley and its contributors.
 
120
 * 4. Neither the name of the University nor the names of its contributors
 
121
 *    may be used to endorse or promote products derived from this software
 
122
 *    without specific prior written permission.
 
123
 *
 
124
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 
125
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
126
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
127
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 
128
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
129
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 
130
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
131
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
132
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 
133
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
134
 * SUCH DAMAGE.
 
135
 */
 
136
 
 
137
#if defined(LIBC_SCCS) && !defined(lint)
 
138
static char *rcsid = "$OpenBSD: strerror.c,v 1.2 1996/08/19 08:34:17 tholo Exp $";
 
139
#endif /* LIBC_SCCS and not lint */
 
140
 
 
141
#if 0
 
142
#include <string.h>
 
143
#include <limits.h>
 
144
#endif
 
145
 
 
146
/*
 
147
 * Since perror() is not allowed to change the contents of strerror()'s
 
148
 * static buffer, both functions supply their own buffers to the
 
149
 * internal function __strerror().
 
150
 */
 
151
 
 
152
char *
 
153
strerror(num)
 
154
        int num;
 
155
{
 
156
        static char buf[NL_TEXTMAX];
 
157
        return __strerror(num, buf);
 
158
}
 
159
#else
 
160
static void avoid_error __P((void));
 
161
static void avoid_error()
 
162
{
 
163
        avoid_error();
 
164
}
 
165
#endif /* HAVE_STRERROR */