summaryrefslogtreecommitdiffstats
path: root/usr.bin/compile_et/perror.c
blob: ef50e07fb690b3ae98c0c29705c3f387ca2741fd (plain)
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
/*
 * Copyright 1987 by MIT Student Information Processing Board
 * For copyright info, see Copyright.SIPB
 *
 *	$Id: perror.c,v 1.2 1994/07/19 19:21:30 g89r4222 Exp $
 */

#include <stdio.h>
#include <sys/types.h>
#include <sys/uio.h>
#include "error_table.h"

typedef int (*int_func)();

#if defined(mips) && defined(ultrix)
int errno;		/* this is needed to keep the loader from complaining */
#endif

int_func com_err_hook = (int_func) NULL;
char *error_message();

void
com_err(whoami, code, message)
	char *whoami;
	int code;
	char *message;
{
	struct iovec strings[6];

	if (com_err_hook) {
		(*com_err_hook)(whoami, code, message);
		return;
	}

	strings[0].iov_base = whoami;
	strings[0].iov_len = strlen(whoami);
	if (whoami) {
		strings[1].iov_base = ": ";
		strings[1].iov_len = 2;
	} else
		strings[1].iov_len = 0;
	if (code) {
		register char *errmsg = error_message(code);
		strings[2].iov_base = errmsg;
		strings[2].iov_len = strlen(errmsg);
	} else
		strings[2].iov_len = 0;
	strings[3].iov_base = " ";
	strings[3].iov_len = 1;
	strings[4].iov_base = message;
	strings[4].iov_len = strlen(message);
	strings[5].iov_base = "\n";
	strings[5].iov_len = 1;
	(void) writev(2, strings, 6);
}

int_func
set_com_err_hook(new_proc)
	int_func new_proc;
{
	register int_func x = com_err_hook;
	com_err_hook = new_proc;
	return (x);
}

reset_com_err_hook()
{
	com_err_hook = (int_func) NULL;
}

void
perror(msg)
	register const char *msg;
{
	com_err(msg, errno, (char *)NULL);
}
OpenPOWER on IntegriCloud