File: string.c

package info (click to toggle)
fhist 1.18-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 2,564 kB
  • ctags: 1,332
  • sloc: ansic: 15,161; sh: 4,749; makefile: 1,027; awk: 154; yacc: 101
file content (220 lines) | stat: -rw-r--r-- 4,836 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
 *      fhist - file history and comparison tools
 *      Copyright (C) 1993, 1994, 1998, 2002, 2008 Peter Miller
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 3 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program. If not, see
 *      <http://www.gnu.org/licenses/>.
 *
 * This file contains functions for use with non-ANSI conforming systems
 * to implement absent ANSI functionality.
 */

#include <ac/stddef.h>
#include <ac/stdlib.h>
#include <ac/string.h>
#include <ac/stdio.h>

#include <main.h>


/*
 *  NAME
 *      strerror - string for error number
 *
 *  SYNOPSIS
 *      char *strerror(int errnum);
 *
 *  DESCRIPTION
 *      The strerror function maps the error number in errnum to an error
 *      message string.
 *
 *  RETURNS
 *      The strerror function returns a pointer to the string, the contents of
 *      which are implementation-defined.  The array pointed to shall not be
 *      modified by the program, but may be overwritten by a subsequent call to
 *      the strerror function.
 *
 *  CAVEAT
 *      Unknown errors will be rendered in the form "Error %d", where %d will
 *      be replaced by a decimal representation of the error number.
 */

#ifndef HAVE_STRERROR

char *
strerror(int n)
{
    extern int      sys_nerr;
    extern char     *sys_errlist[];
    static char     buffer[30];

    if (n < 1 || n > sys_nerr)
    {
        sprintf(buffer, "Error %d", n);
        return buffer;
    }
    return sys_errlist[n];
}

#endif /* !HAVE_STRERROR */


#ifndef HAVE_STRCASECMP

int
strcasecmp(const char *s1, const char *s2)
{
    int             c1;
    int             c2;

    for (;;)
    {
        c1 = *s1++;
        if (islower(c1))
            c1 = toupper(c1);
        c2 = *s2++;
        if (islower(c2))
            c2 = toupper(c2);
        if (c1 != c2)
        {
            /*
             * if s1 is a leading substring of s2, must
             * return -1, even if the next character of s2
             * is negative.
             */
            if (!c1)
                return -1;
            if (c1 < c2)
                return -1;
            return 1;
        }
        if (!c1)
            return 0;
    }
}

#endif /* !HAVE_STRCASECMP */


#ifndef HAVE_STRSIGNAL

char *
strsignal(int n)
{
    static char     buffer[16];

    switch (n)
    {
#ifdef SIGHUP
    case SIGHUP:
        return "hang up [SIGHUP]";
#endif /* SIGHUP */

#ifdef SIGINT
    case SIGINT:
        return "user interrupt [SIGINT]";
#endif /* SIGINT */

#ifdef SIGQUIT
    case SIGQUIT:
        return "user quit [SIGQUIT]";
#endif /* SIGQUIT */

#ifdef SIGILL
    case SIGILL:
        return "illegal instruction [SIGILL]";
#endif /* SIGILL */

#ifdef SIGTRAP
    case SIGTRAP:
        return "trace trap [SIGTRAP]";
#endif /* SIGTRAP */

#ifdef SIGIOT
    case SIGIOT:
        return "abort [SIGIOT]";
#endif /* SIGIOT */

#ifdef SIGEMT
    case SIGEMT:
        return "EMT instruction [SIGEMT]";
#endif /* SIGEMT */

#ifdef SIGFPE
    case SIGFPE:
        return "floating point exception [SIGFPE]";
#endif /* SIGFPE */

#ifdef SIGKILL
    case SIGKILL:
        return "kill [SIGKILL]";
#endif /* SIGKILL */

#ifdef SIGBUS
    case SIGBUS:
        return "bus error [SIGBUS]";
#endif /* SIGBUS */

#ifdef SIGSEGV
    case SIGSEGV:
        return "segmentation violation [SIGSEGV]";
#endif /* SIGSEGV */

#ifdef SIGSYS
    case SIGSYS:
        return "bad argument to system call [SIGSYS]";
#endif /* SIGSYS */

#ifdef SIGPIPE
    case SIGPIPE:
        return "write on a pipe with no one to read it [SIGPIPE]";
#endif /* SIGPIPE */

#ifdef SIGALRM
    case SIGALRM:
        return "alarm clock [SIGALRM]";
#endif /* SIGALRM */

#ifdef SIGTERM
    case SIGTERM:
        return "software termination [SIGTERM]";
#endif /* SIGTERM */

#ifdef SIGUSR1
    case SIGUSR1:
        return "user defined signal one [SIGUSR1]";
#endif /* SIGUSR1 */

#ifdef SIGUSR2
    case SIGUSR2:
        return "user defined signal two [SIGUSR2]";
#endif /* SIGUSR2 */

#ifdef SIGCLD
    case SIGCLD:
        return "death of child [SIGCLD]";
#endif /* SIGCLD */

#ifdef SIGPWR
    case SIGPWR:
        return "power failure [SIGPWR]";
#endif /* SIGPWR */

    default:
        sprintf(buffer, "signal %d", n);
        return buffer;
    }
}

#endif /* !HAVE_STRSIGNAL */