summaryrefslogtreecommitdiffstats
path: root/clib/test/err.c
blob: 0cdb85909992e5bc36ecee2d67228c134006ab2c (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
77
78
79
80
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: clib/test/err.c $                                             */
/*                                                                        */
/* OpenPOWER FFS Project                                                  */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2014,2015                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include <libgen.h>

#include <clib/assert.h>
#include <clib/version.h>
#include <clib/err.h>

extern char * program_invocation_short_name;

#define FOO_MAJOR	0x01
#define FOO_MINOR	0x00
#define FOO_PATCH	0x00
#define FOO_VER		VER(FOO_MAJOR, FOO_MINOR, FOO_PATCH)

#define FOO_UNEXPECTED(f, ...)		({		\
	UNEXPECTED(f, ##__VA_ARGS__);			\
	VERSION(FOO_VER, "%s", program_invocation_short_name);	\
					})


int main (int argc, char * argv[]) {
	ERRNO(EINVAL);
	FOO_UNEXPECTED("cannot frob the ka-knob");

	goto error;

	if (false) {
		err_t * err = NULL;
error:
		while ((err = err_get()) != NULL) {
			switch (err_type(err)) {
			case ERR_VERSION:
				fprintf(stderr, "%s: %s : %s(%d) : v%d.%02d.%04d %.*s\n",
					basename((char *)argv[0]),
					err_type_name(err), basename(err_file(err)), err_line(err),
					VER_TO_MAJOR(err_code(err)), VER_TO_MINOR(err_code(err)),
					VER_TO_PATCH(err_code(err)),
					err_size(err), (char *)err_data(err));
				break;
			default:
				fprintf(stderr, "%s: %s : %s(%d) : (code=%d) %.*s\n",
					basename((char *)argv[0]),
					err_type_name(err), basename(err_file(err)), err_line(err),
					err_code(err), err_size(err), (char *)err_data(err));
			}
		}
	}

	return 0;
}

OpenPOWER on IntegriCloud