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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/* stdc.h -- JT standard C/C++ header file, cut-down for modern code only */
/* $Id$ */
/*
* ***** THIS VERSION IS FOR ANSI/ISO C AND C++ *****
*/
/* this header file is idempotent */
#ifndef STDC_H_SEEN
#define STDC_H_SEEN
/******************************************************************************/
/*
* C/C++ compatability:
*/
/* use this in prototypes like this: extern C_FUNCTION void foo(...) */
#ifdef __cplusplus
#define C_FUNCTION "C"
#else
#define C_FUNCTION /* empty */
#endif
/******************************************************************************/
/*
* New C/C++ "keywords" and types:
*/
#define then /* empty */ /* usage: if (foo) then bar; else baz; */
/* this makes "then" and "else" symmetrical */
/******************************************************************************/
/*
* *** KLUDGE ***
*
* These macros suffer form the same "redefinition in system headers"
* as my MIN/MAX macros (below). The fix here is the same as for MIN/MAX,
* but this time conditional on linux:
*/
#ifndef FILENAME_MAX
#if defined(LINUX)
#define FILENAME_MAX 4095
#elif defined(ALPHA)
/* gcc already defines this */
#else /* other systems */
#define FILENAME_MAX BUFSIZ
#endif /* LINUX */
#endif
/* printf(3) and scanf(3) formats and cast-types to print/read a pointer */
/* unfortunately, the ANSI/ISO C "%p" format isn't universal yet :-( */
/* even more unfortunately, ANSI/ISO printf() need not support length, */
/* precision, or indeed _any_ modifiers for the %p conversion */
#ifdef HAS_ISO_C_LIBRARY
#define PRINTF_POINTER_FORMAT "%p"
#define PRINTF_POINTER_TYPE void *
#define SCANF_POINTER_FORMAT "%p"
#define PRINTF_POINTER_TYPE void *
#else
#define PRINTF_POINTER_FORMAT "0x%08x" /* for 32-bit pointers */
#define PRINTF_POINTER_TYPE unsigned long
#define SCANF_POINTER_FORMAT "0x%08x" /* for 32-bit pointers */
#define PRINTF_POINTER_TYPE unsigned long
#endif
/******************************************************************************/
#ifdef __cplusplus
namespace jtutil {
#endif
/*
* All my error handling is done with my error_exit() routine. It
* prints an error message to stderr, then does an exit() or abort().
* It does *not* return to its caller. It's declared to return an
* int , however, so it may be easily used in conditional expressions
* like
* foo = bar_ok ? baz(bar) : error_exit(...);
*/
extern C_FUNCTION int error_exit(int exit_code, const char *format, ...)
#ifdef __GNUC__
__attribute__ ((noreturn))
__attribute__ ((format(printf,2,3)))
#endif
;
/*
* error_exit() uses the following exit() codes:
* OK_EXIT ==> everything's under control
* ERROR_EXIT ==> something bad has happened
* PANIC_EXIT ==> diasaster ==> force (eg) core dump, stack trace
*/
#ifdef VMS
#define OK_EXIT 1
#define ERROR_EXIT 3
#define PANIC_EXIT (-1)
#else
#define OK_EXIT 0
#define ERROR_EXIT 1
#define PANIC_EXIT (-1)
#endif
#ifdef __cplusplus
} /* close namespace jtutil */
using jtutil::error_exit; /* bring error_exit() into global namespace */
#endif
/******************************************************************************/
#define iabs abs /* C library uses abs() for integer absolute value */
#define INT_SENTINAL_VALUE (~ INT_MAX) /* from <limits.h> */
/* usually 10...0 binary for */
/* a 2's complement system */
#define FLOAT_SENTINAL_VALUE (- FLT_MAX) /* from <float.h> */
#define DOUBLE_SENTINAL_VALUE (- DBL_MAX) /* from <float.h> */
/* misc integer sentinal value */
#define SENTINAL_VALUE INT_SENTINAL_VALUE
/******************************************************************************/
#endif /* STDC_H_SEEN */
|