~ubuntu-branches/ubuntu/trusty/grfcodec/trusty

« back to all changes in this revision

Viewing changes to src/typesize.h

  • Committer: Bazaar Package Importer
  • Author(s): Matthijs Kooijman
  • Date: 2010-08-23 14:45:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100823144552-4qggmf9izixsw8li
Tags: 1.0.0+debian1-1
* [30caa6a] Repackaged upstream source, to remove a duplicate file (which
  the lenny version of tar --keep-old-files doesn't like.
* [331d12b] Update watch file to upstream's new versioning scheme.
* [28b6b51] Mangle the +debian suffix in the watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef _TYPESIZE_H
 
2
#define _TYPESIZE_H
 
3
 
 
4
/*****************************************\
 
5
*                                         *
 
6
* TYPESIZE.H - Defines variable types     *
 
7
*         with a known memory size        *
 
8
*         Also defines macros for dealing *
 
9
*         with C/C++ exports              *
 
10
*                                         *
 
11
* Copyright (C) 2000 by Josef Drexler     *
 
12
*               <jdrexler@julian.uwo.ca>  *
 
13
*                                         *
 
14
* Permission granted to copy and redist-  *
 
15
* ribute under the terms of the GNU GPL.  *
 
16
* For more info please read the file      *
 
17
* COPYING which should have come with     *
 
18
* this file.                              *
 
19
*                                         *
 
20
\*****************************************/
 
21
 
 
22
#define maketype(type,size) \
 
23
        typedef   signed type S ## size; \
 
24
        typedef unsigned type U ## size;
 
25
 
 
26
#ifndef _MSC_VER
 
27
#define strnicmp strncasecmp
 
28
#define stricmp strcasecmp
 
29
#endif
 
30
 
 
31
#ifdef __BORLANDC__
 
32
 
 
33
#       define HAVE_BYTES
 
34
#       define HAVE_SHORTS
 
35
#       define HAVE_LONGS
 
36
 
 
37
        maketype(char,8)
 
38
        maketype(short,16)
 
39
        maketype(long,32)
 
40
 
 
41
// disable warnings for "condition is always false" and "unreachable code"
 
42
#pragma warn -ccc
 
43
#pragma warn -rch
 
44
 
 
45
#elif WIN32
 
46
 
 
47
#       define HAVE_BYTES
 
48
#       define HAVE_SHORTS
 
49
#       define HAVE_LONGS
 
50
#       define HAVE_LONGLONGS
 
51
 
 
52
        maketype(char,8)
 
53
        maketype(short int,16)
 
54
        maketype(long int,32)
 
55
        maketype(long long,64)
 
56
 
 
57
#elif GCC32
 
58
 
 
59
#   define HAVE_BYTES
 
60
#   define HAVE_SHORTS
 
61
#   define HAVE_LONGS
 
62
#   define HAVE_LONGLONGS
 
63
 
 
64
    maketype(char,8)
 
65
    maketype(short int,16)
 
66
    maketype(int,32)
 
67
    maketype(long long,64)
 
68
 
 
69
#elif GCC64
 
70
 
 
71
#   define HAVE_BYTES
 
72
#   define HAVE_SHORTS
 
73
#   define HAVE_LONGS
 
74
#   define HAVE_LONGLONGS
 
75
 
 
76
    maketype(char,8)
 
77
    maketype(short int,16)
 
78
    maketype(int,32)
 
79
    maketype(long int,64)
 
80
 
 
81
#else
 
82
#       error Unknown variables sizes, please define.
 
83
#endif
 
84
 
 
85
#ifdef _MSC_VER
 
86
// disable warnings: conversion from $LARGE_SIZE to $SMALL_SIZE
 
87
#pragma warning(disable:4267 4244)
 
88
// ... conditional expression is constant
 
89
#pragma warning(disable:4127)
 
90
#endif
 
91
 
 
92
#undef maketype
 
93
 
 
94
#ifdef DOCHECK
 
95
void checksizes()
 
96
{
 
97
  if (
 
98
#ifdef HAVE_BYTES
 
99
        (sizeof( S8) != 1) ||
 
100
        (sizeof( U8) != 1) ||
 
101
#endif
 
102
#ifdef HAVE_SHORTS
 
103
        (sizeof(S16) != 2) ||
 
104
        (sizeof(U16) != 2) ||
 
105
#endif
 
106
#ifdef HAVE_LONGS
 
107
        (sizeof(S32) != 4) ||
 
108
        (sizeof(U32) != 4) ||
 
109
#endif
 
110
#ifdef HAVE_LONGLONGS
 
111
        (sizeof(S64) != 8) ||
 
112
        (sizeof(U64) != 8) ||
 
113
#endif
 
114
        (0)     // the ||(0) is so that all previous lines can end in ||
 
115
     )
 
116
        {
 
117
                printf("Fatal: Incorrectly sized variables.\n");
 
118
#define PRINT_SZ(t,s) printf("%s size = %d, expected = %d\n", #t, (int)sizeof(t), s)
 
119
#ifdef HAVE_BYTES
 
120
                        PRINT_SZ(S8,1);
 
121
                        PRINT_SZ(U8,1);
 
122
#endif
 
123
#ifdef HAVE_SHORTS
 
124
                        PRINT_SZ(S16,2);
 
125
                        PRINT_SZ(U16,2);
 
126
#endif
 
127
#ifdef HAVE_LONGS
 
128
                        PRINT_SZ(S32,4);
 
129
                        PRINT_SZ(U32,4);
 
130
#endif
 
131
#ifdef HAVE_LONGLONGS
 
132
                        PRINT_SZ(S64,8);
 
133
                        PRINT_SZ(U64,8);
 
134
#endif
 
135
#undef PRINT_SZ
 
136
                exit(254);
 
137
        }
 
138
 
 
139
}
 
140
#endif /* DOCHECK */
 
141
 
 
142
union multitype {
 
143
        U32 u32;
 
144
        S32 s32;
 
145
        U16 u16[2];
 
146
        S16 s16[2];
 
147
        U8  u8[4];
 
148
        S8  s8[4];
 
149
};
 
150
 
 
151
#ifdef __BIG_ENDIAN__
 
152
#       define BE_SWAP16(b) (*((U8*)(&b))+(*(((U8*)(&b))+1)<<8))
 
153
#       define BE_SWAP32(b) (*((U8*)(&b))+(*(((U8*)(&b))+1)<<8)+(*(((U8*)(&b))+2)<<16)+(*(((U8*)(&b))+3)<<24))
 
154
#       define BYTE_OFSL 1
 
155
#       define BYTE_OFSH 0
 
156
#else
 
157
#       define BE_SWAP16(b) (b)
 
158
#       define BE_SWAP32(b) (b)
 
159
#       define BYTE_OFSL 0
 
160
#       define BYTE_OFSH 1
 
161
#endif
 
162
 
 
163
#ifdef __cplusplus
 
164
#define BEGINC extern "C" {
 
165
#define ENDC }
 
166
#else
 
167
#define BEGINC
 
168
#define ENDC
 
169
#endif
 
170
 
 
171
 
 
172
#endif /* _TYPESIZE_H */