File: err.c

package info (click to toggle)
tworld 1.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 6,620 kB
  • ctags: 1,407
  • sloc: ansic: 12,442; perl: 2,465; makefile: 191; sh: 16
file content (53 lines) | stat: -rw-r--r-- 1,146 bytes parent folder | download | duplicates (6)
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
/* err.c: Error handling and reporting.
 *
 * Copyright (C) 2001-2006 by Brian Raiter, under the GNU General Public
 * License. No warranty. See COPYING for details.
 */

#include	<stdlib.h>
#include	<stdarg.h>
#include	"oshw.h"
#include	"err.h"

/* "Hidden" arguments to _warn, _errmsg, and _die.
 */
char const      *_err_cfile = NULL;
unsigned long	_err_lineno = 0;

/* Log a warning message.
 */
void _warn(char const *fmt, ...)
{
    va_list	args;

    va_start(args, fmt);
    usermessage(NOTIFY_LOG, NULL, _err_cfile, _err_lineno, fmt, args);
    va_end(args);
    _err_cfile = NULL;
    _err_lineno = 0;
}

/* Display an error message to the user.
 */
void _errmsg(char const *prefix, char const *fmt, ...)
{
    va_list	args;

    va_start(args, fmt);
    usermessage(NOTIFY_ERR, prefix, _err_cfile, _err_lineno, fmt, args);
    va_end(args);
    _err_cfile = NULL;
    _err_lineno = 0;
}

/* Display an error message to the user and exit.
 */
void _die(char const *fmt, ...)
{
    va_list	args;

    va_start(args, fmt);
    usermessage(NOTIFY_DIE, NULL, _err_cfile, _err_lineno, fmt, args);
    va_end(args);
    exit(EXIT_FAILURE);
}