OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [misc/] [error/] [error.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* Error handler for noninteractive utilities
2
   Copyright (C) 1990-1998, 2000, 2001 Free Software Foundation, Inc.
3
 
4
   This file is part of the GNU C Library.  Its master source is NOT part of
5
   the C library, however.  The master source lives in /gd/gnu/lib.
6
 
7
   The GNU C Library is free software; you can redistribute it and/or
8
   modify it under the terms of the GNU Library General Public License as
9
   published by the Free Software Foundation; either version 2 of the
10
   License, or (at your option) any later version.
11
 
12
   The GNU C Library is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
   Library General Public License for more details.
16
 
17
   You should have received a copy of the GNU Library General Public
18
   License along with the GNU C Library; see the file COPYING.LIB.  If not,
19
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
   Boston, MA 02111-1307, USA.  */
21
 
22
/* Written by David MacKenzie <djm@gnu.ai.mit.edu>.  */
23
/* Adjusted slightly by Erik Andersen <andersen@uclibc.org> */
24
 
25
#include <stdio.h>
26
#include <stdarg.h>
27
#include <stdlib.h>
28
#include <string.h>
29
#include "error.h"
30
 
31
 
32
/* This variable is incremented each time `error' is called.  */
33
unsigned int error_message_count;
34
/* Sometimes we want to have at most one error per line.  This
35
   variable controls whether this mode is selected or not.  */
36
int error_one_per_line;
37
/* If NULL, error will flush stdout, then print on stderr the program
38
   name, a colon and a space.  Otherwise, error will call this
39
   function without parameters instead.  */
40
void (*error_print_progname) (void) = NULL;
41
 
42
 
43
void __error (int status, int errnum, const char *message, ...)
44
{
45
    va_list args;
46
 
47
    fflush (stdout);
48
 
49
    va_start (args, message);
50
    vfprintf (stderr, message, args);
51
    va_end (args);
52
    ++error_message_count;
53
    if (errnum) {
54
        fprintf (stderr, ": %s", strerror (errnum));
55
    }
56
    putc ('\n', stderr);
57
    if (status)
58
        exit (status);
59
}
60
 
61
void __error_at_line (int status, int errnum, const char *file_name,
62
               unsigned int line_number, const char *message, ...)
63
{
64
    va_list args;
65
 
66
    if (error_one_per_line) {
67
        static const char *old_file_name;
68
        static unsigned int old_line_number;
69
 
70
        if (old_line_number == line_number &&
71
                (file_name == old_file_name || !strcmp (old_file_name, file_name)))
72
            /* Simply return and print nothing.  */
73
            return;
74
 
75
        old_file_name = file_name;
76
        old_line_number = line_number;
77
    }
78
 
79
    fflush (stdout);
80
 
81
    if (file_name != NULL)
82
        fprintf (stderr, "%s:%d: ", file_name, line_number);
83
 
84
    va_start (args, message);
85
    vfprintf (stderr, message, args);
86
    va_end (args);
87
 
88
    ++error_message_count;
89
    if (errnum) {
90
        fprintf (stderr, ": %s", strerror (errnum));
91
    }
92
    putc ('\n', stderr);
93
    if (status)
94
        exit (status);
95
}
96
 
97
/* Use the weaks here in an effort at controlling namespace pollution */
98
#undef error
99
#undef error_at_line
100
weak_alias (__error, error)
101
weak_alias (__error_at_line, error_at_line)
102
 
103
 
104
 
105
#include "err.h"
106
#include "errno.h"
107
 
108
/* NORETURN */
109
void verr (int status, const char *message, va_list args)
110
{
111
    fflush (stdout);
112
 
113
    vfprintf (stderr, message, args);
114
    if (errno) {
115
        fprintf (stderr, ": %s", strerror (errno));
116
    }
117
    putc ('\n', stderr);
118
    if (status)
119
        exit (status);
120
}
121
 
122
/* NORETURN */
123
void verrx (int status, const char *message, va_list args)
124
{
125
    fflush (stdout);
126
 
127
    vfprintf (stderr, message, args);
128
    if (status)
129
        exit (status);
130
}
131
 
132
void vwarn (const char *message, va_list args)
133
{
134
    verr (0, message, args);
135
}
136
 
137
void vwarnx (const char *message, va_list args)
138
{
139
    verrx (0, message, args);
140
}
141
 
142
void err (int status, const char *message, ...)
143
{
144
    va_list args;
145
 
146
    va_start (args, message);
147
    verr (status, message, args);
148
    va_end (args);
149
}
150
 
151
void errx (int status, const char *message, ...)
152
{
153
    va_list args;
154
 
155
    va_start (args, message);
156
    verrx (status, message, args);
157
    va_end (args);
158
}
159
 
160
void warn (const char *message, ...)
161
{
162
    va_list args;
163
 
164
    va_start (args, message);
165
    verr (0, message, args);
166
    va_end (args);
167
}
168
 
169
void warnx (const char *message, ...)
170
{
171
    va_list args;
172
 
173
    va_start (args, message);
174
    verrx (0, message, args);
175
    va_end (args);
176
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.