aboutsummaryrefslogtreecommitdiff
path: root/sendmail/libsm/t-types.c
blob: cb07f67571bfd2597787f72a616c3489e825afa3 (plain) (blame)
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
/*
 * Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers.
 *	All rights reserved.
 *
 * By using this file, you agree to the terms and conditions set
 * forth in the LICENSE file which can be found at the top level of
 * the sendmail distribution.
 */

#include <sm/gen.h>
SM_IDSTR(id, "@(#)$Id: t-types.c,v 1.18 2002/03/13 17:29:53 gshapiro Exp $")

#include <sm/limits.h>
#include <sm/io.h>
#include <sm/string.h>
#include <sm/test.h>
#include <sm/types.h>

int
main(argc, argv)
	int argc;
	char **argv;
{
	LONGLONG_T ll;
	LONGLONG_T volatile lt;
	ULONGLONG_T ull;
	char buf[128];
	char *r;

	sm_test_begin(argc, argv, "test standard integral types");

	SM_TEST(sizeof(LONGLONG_T) == sizeof(ULONGLONG_T));

	/*
	**  sendmail assumes that ino_t, off_t and void* can be cast
	**  to ULONGLONG_T without losing information.
	*/

	if (!SM_TEST(sizeof(ino_t) <= sizeof(ULONGLONG_T)) ||
	    !SM_TEST(sizeof(off_t) <= sizeof(ULONGLONG_T)) ||
	    !SM_TEST(sizeof(void*) <= sizeof(ULONGLONG_T)))
	{
		(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "\
Your C compiler appears to support a 64 bit integral type,\n\
but libsm is not configured to use it.  You will need to set\n\
either SM_CONF_LONGLONG or SM_CONF_QUAD_T to 1.  See libsm/README\n\
for more details.\n");
	}

	/*
	**  Most compilers notice that LLONG_MIN - 1 generate an underflow.
	**  Some compiler generate code that will use the 'X' status bit
	**  in a CPU and hence (LLONG_MIN - 1 > LLONG_MIN) will be false.
	**  So we have to decide whether we want compiler warnings or
	**  a wrong test...
	**  Question: where do we really need what this test tests?
	*/

#if SM_CONF_TEST_LLONG
	ll = LLONG_MIN;
	(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "\
Your C compiler maybe issued a warning during compilation,\n\
please IGNORE the compiler warning!.\n");
	lt = LLONG_MIN - 1;
	SM_TEST(lt > ll);
	sm_snprintf(buf, sizeof(buf), "%llx", ll);
	r = "0";
	if (!SM_TEST(buf[0] == '8')
	    || !SM_TEST(strspn(&buf[1], r) == sizeof(ll) * 2 - 1))
	{
		(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
			"oops: LLONG_MIN=%s\n", buf);
	}

	ll = LLONG_MAX;
	lt = ll + 1;
	SM_TEST(lt < ll);
	sm_snprintf(buf, sizeof(buf), "%llx", ll);
	r = "f";
	if (!SM_TEST(buf[0] == '7')
	    || !SM_TEST(strspn(&buf[1], r) == sizeof(ll) * 2 - 1))
	{
		(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
			"oops: LLONG_MAX=%s\n", buf);
	}
#endif /* SM_CONF_TEST_LLONG */

	ull = ULLONG_MAX;
	SM_TEST(ull + 1 == 0);
	sm_snprintf(buf, sizeof(buf), "%llx", ull);
	r = "f";
	SM_TEST(strspn(buf, r) == sizeof(ll) * 2);

	/*
	**  If QUAD_MAX is defined by <limits.h> then quad_t is defined.
	**  Make sure LONGLONG_T is at least as big as quad_t.
	*/
#ifdef QUAD_MAX
	SM_TEST(QUAD_MAX <= LLONG_MAX);
#endif

	return sm_test_end();
}