1 /*******************************************************************/
2 /*  slibtool: a skinny libtool implementation, written in C        */
3 /*  Copyright (C) 2016--2018  Z. Gilboa                            */
4 /*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
5 /*******************************************************************/
6 
7 #ifndef SLIBTOOL_ERRINFO_IMPL_H
8 #define SLIBTOOL_ERRINFO_IMPL_H
9 
10 #include <errno.h>
11 #include <slibtool/slibtool.h>
12 
13 int slbt_record_error(
14 	const struct slbt_driver_ctx *,
15 	int		esyscode,
16 	int		elibcode,
17 	const char *	efunction,
18 	int		eline,
19 	unsigned	eflags,
20 	void *		eany);
21 
22 #define SLBT_SYSTEM_ERROR(dctx,eany)      \
23 	slbt_record_error(                \
24 		dctx,                     \
25 		errno,                    \
26 		0,                        \
27 		__func__,                 \
28 		__LINE__,                 \
29 		SLBT_ERROR_TOP_LEVEL,     \
30 		(void *)eany)
31 
32 #define SLBT_BUFFER_ERROR(dctx)           \
33 	slbt_record_error(                \
34 		dctx,                     \
35 		ENOBUFS,                  \
36 		0,                        \
37 		__func__,                 \
38 		__LINE__,                 \
39 		SLBT_ERROR_TOP_LEVEL,     \
40 		0)
41 
42 #define SLBT_SPAWN_ERROR(dctx)            \
43 	slbt_record_error(                \
44 		dctx,                     \
45 		errno,                    \
46 		0,                        \
47 		__func__,                 \
48 		__LINE__,                 \
49 		SLBT_ERROR_TOP_LEVEL      \
50 		| (errno ? 0              \
51 		   : SLBT_ERROR_CHILD),   \
52 		0)
53 
54 #define SLBT_FILE_ERROR(dctx)             \
55 	slbt_record_error(                \
56 		dctx,                     \
57 		EIO,                      \
58 		0,                        \
59 		__func__,                 \
60 		__LINE__,                 \
61 		SLBT_ERROR_TOP_LEVEL,     \
62 		0)
63 
64 #define SLBT_CUSTOM_ERROR(dctx,elibcode)  \
65 	slbt_record_error(                \
66 		dctx,                     \
67 		0,                        \
68 		elibcode,                 \
69 		__func__,                 \
70 		__LINE__,                 \
71 		SLBT_ERROR_TOP_LEVEL      \
72 		| SLBT_ERROR_CUSTOM,      \
73 		0)
74 
75 #define SLBT_NESTED_ERROR(dctx)           \
76 	slbt_record_error(                \
77 		dctx,                     \
78 		0,                        \
79 		0,                        \
80 		__func__,                 \
81 		__LINE__,                 \
82 		SLBT_ERROR_NESTED,        \
83 		0)
84 
85 #endif
86