Menu

[a2fca3]: / make_addr_width.cpp  Maximize  Restore  History

Download this file

100 lines (84 with data), 3.0 kB

 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
/*
* Copyright 2017 transmission.aquitaine@yahoo.com
*
* 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.
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#ifdef _MSC_VER /* Microsoft compiler */
#include <tchar.h>
#ifdef _UNICODE
#define fopen_s _wfopen_s
#endif
#endif
#ifdef __GNUC__ /* GNU compiler */
#define TCHAR char
#define _T(s) s
#define _tmain main
#define _tprintf printf
#define _ftprintf fprintf
#define _tfopen fopen
typedef int errno_t;
static errno_t fopen_s(FILE **f, const char *name, const char *mode)
{
*f = fopen(name, mode);
return f ? 0 : 1;
}
#endif
union EndianTester
{
unsigned long ul;
char ca[4];
};
int _tmain(int argc, TCHAR* argv[])
{
FILE *fout;
errno_t e = fopen_s(&fout, _T("addr_width.h"), _T("w"));
if (e)
{
_tprintf(_T("Unable to open addr_width.h for writing.\n"));
return 1;
}
_ftprintf(fout, _T("\n#ifndef ADDR_WIDTH\n"));
_ftprintf(fout, _T("#define ADDR_WIDTH (%u)\n"), (unsigned int)(8*sizeof(void*)));
_ftprintf(fout, _T("#endif\n\n"));
EndianTester et;
et.ul = 1;
if (et.ca[0])
{
_ftprintf(fout, _T("#ifndef IS_INTEL_ENDIAN\n"));
_ftprintf(fout, _T("#define IS_INTEL_ENDIAN (1)\n"));
_ftprintf(fout, _T("#endif\n\n"));
_ftprintf(fout, _T("#ifdef IS_MOTOROLA_ENDIAN\n"));
_ftprintf(fout, _T("#undef IS_MOTOROLA_ENDIAN\n"));
_ftprintf(fout, _T("#endif\n"));
_tprintf(_T("\n **************************************************\n"));
_tprintf(_T(" * This is a %u-bit little endian executable. *\n"), (unsigned int)(8*sizeof(void*)));
_tprintf(_T(" **************************************************\n\n"));
}
else
{
_ftprintf(fout, _T("#ifdef IS_INTEL_ENDIAN\n"));
_ftprintf(fout, _T("#undef IS_INTEL_ENDIAN\n"));
_ftprintf(fout, _T("#endif\n\n"));
_ftprintf(fout, _T("#ifndef IS_MOTOROLA_ENDIAN\n"));
_ftprintf(fout, _T("#define IS_MOTOROLA_ENDIAN (1)\n"));
_ftprintf(fout, _T("#endif\n"));
_tprintf(_T("\n ********************************************\n"));
_tprintf(_T(" * This a %u-bit big endian executable. *\n"), (unsigned int)(8*sizeof(void*)));
_tprintf(_T(" ********************************************\n\n"));
}
fclose(fout);
return 0;
}
MongoDB Logo MongoDB