libcdio  2.1.0
types.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2008, 2012, 2017 2019
3  Rocky Bernstein <rocky@gnu.org>
4  Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
24 
25 #ifndef CDIO_TYPES_H_
26 #define CDIO_TYPES_H_
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31 
32 /* If <sys/types.h> is not available on your platform please
33  contact the libcdio mailing list so that we can fix it! */
34 #if !defined(ARE_THERE_STILL_ENVS_WITHOUT_SYS_TYPES)
35 #include <sys/types.h>
36 #endif
37 
38 #if defined(AMIGA)
39 typedef u_int8_t uint8_t;
40 typedef u_int16_t uint16_t;
41 typedef u_int32_t uint32_t;
42 typedef u_int64_t uint64_t;
43 #else
44 /* If <stdint.h> is not available on your platform please
45  contact the libcdio mailing list so that we can fix it!
46  For MSVC, you can find both a public domain stdint.h and
47  inttypes.h in the MSVC/missing directory of libcdio. */
48 #include <stdint.h>
49 #endif
50 
51 typedef uint8_t ubyte;
52 
53 /* MSVC does not define mode_t and ssize_t by default. The way
54  to compensate for missing UNIX types is to include a custom
55  unistd.h that defines them. Such a file is provided with
56  the libcdio source, in the MSVC/missing directory */
57 #if defined(_MSC_VER)
58 #include <unistd.h>
59 #endif
60 
61  /* default HP/UX macros are broken */
62 #if defined(__hpux__)
63 # undef UINT16_C
64 # undef UINT32_C
65 # undef UINT64_C
66 # undef INT64_C
67 #endif
68 
69  /* if it's still not defined, take a good guess... should work for
70  most 32bit and 64bit archs */
71 
72 #ifndef UINT16_C
73 # define UINT16_C(c) c ## U
74 #endif
75 
76 #ifndef UINT32_C
77 # if defined (SIZEOF_INT) && SIZEOF_INT == 4
78 # define UINT32_C(c) c ## U
79 # elif defined (SIZEOF_LONG) && SIZEOF_LONG == 4
80 # define UINT32_C(c) c ## UL
81 # else
82 # define UINT32_C(c) c ## U
83 # endif
84 #endif
85 
86 #ifndef UINT64_C
87 # if defined (SIZEOF_LONG) && SIZEOF_LONG == 8
88 # define UINT64_C(c) c ## UL
89 # elif defined (SIZEOF_INT) && SIZEOF_INT == 8
90 # define UINT64_C(c) c ## U
91 # else
92 # define UINT64_C(c) c ## ULL
93 # endif
94 #endif
95 
96 #ifndef INT64_C
97 # if defined (SIZEOF_LONG) && SIZEOF_LONG == 8
98 # define INT64_C(c) c ## L
99 # elif defined (SIZEOF_INT) && SIZEOF_INT == 8
100 # define INT64_C(c) c
101 # else
102 # define INT64_C(c) c ## LL
103 # endif
104 #endif
105 
106 #ifndef __cplusplus
107 
108 /* All the stdbool.h seem to define those */
109 #ifndef __bool_true_false_are_defined
110 #define __bool_true_false_are_defined 1
111 
112 #undef bool
113 #undef true
114 #undef false
115 
116 #ifdef _Bool
117 #define bool _Bool
118 #else
119 #define bool unsigned char
120 #endif
121 #define true 1
122 #define false 0
123 
124 #endif /* __bool_true_false_are_defined */
125 #endif /*C++*/
126 
127  /* some GCC optimizations -- gcc 2.5+ */
128 
129 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
130 #define GNUC_PRINTF( format_idx, arg_idx ) \
131  __attribute__((format (printf, format_idx, arg_idx)))
132 #define GNUC_SCANF( format_idx, arg_idx ) \
133  __attribute__((format (scanf, format_idx, arg_idx)))
134 #define GNUC_FORMAT( arg_idx ) \
135  __attribute__((format_arg (arg_idx)))
136 #define GNUC_NORETURN \
137  __attribute__((noreturn))
138 #define GNUC_CONST \
139  __attribute__((const))
140 #define GNUC_UNUSED \
141  __attribute__((unused))
142 #define GNUC_PACKED \
143  __attribute__((packed))
144 #else /* !__GNUC__ */
145 #define GNUC_PRINTF( format_idx, arg_idx )
146 #define GNUC_SCANF( format_idx, arg_idx )
147 #define GNUC_FORMAT( arg_idx )
148 #define GNUC_NORETURN
149 #define GNUC_CONST
150 #define GNUC_UNUSED
151 #define GNUC_PACKED
152 #endif /* !__GNUC__ */
153 
154 #if defined(__MINGW32__) || (defined( __clang__major_) && __clang_major__ > 9)
155 # define PRAGMA_BEGIN_PACKED _Pragma("pack(push)") \
156  _Pragma("pack(1)")
157 # define PRAGMA_END_PACKED _Pragma("pack(pop)")
158 #elif __GNUC__ > 4 || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901)
159  /* should work with GCC > 4.0 clang and most EDG-frontend based C
160  and C++ compilers */
161 # define PRAGMA_BEGIN_PACKED _Pragma("pack(1)")
162 # define PRAGMA_END_PACKED _Pragma("pack()")
163 #elif defined(_MSC_VER)
164 # define PRAGMA_BEGIN_PACKED __pragma(pack(push, 1))
165 # define PRAGMA_END_PACKED __pragma(pack(pop))
166 #else /* neither gcc nor _Pragma() available... */
167  /* ...so let's be naive and hope the regression testsuite is run... */
168 # define PRAGMA_BEGIN_PACKED
169 # define PRAGMA_END_PACKED
170 #endif
171 
172  /*
173  * user directed static branch prediction gcc 2.96+
174  */
175 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 95)
176 # define GNUC_LIKELY(x) __builtin_expect((x),true)
177 # define GNUC_UNLIKELY(x) __builtin_expect((x),false)
178 #else
179 # define GNUC_LIKELY(x) (x)
180 # define GNUC_UNLIKELY(x) (x)
181 #endif
182 
183 #ifndef NULL
184 # define NULL ((void*) 0)
185 #endif
186 
189 #if defined(__GNUC__)
190 # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)
191 # define LIBCDIO_DEPRECATED(object, notice) object __attribute__ ((deprecated(notice)))
192 # else
193 # define LIBCDIO_DEPRECATED(object, notice) object __attribute__ ((deprecated))
194 # endif
195 #elif defined(_MSC_VER)
196 #define LIBCDIO_DEPRECATED(object, notice) __declspec(deprecated(notice)) object
197 #else
198 #define LIBCDIO_DEPRECATED(object, notice)
199 #endif
200 
202 #define __cd_offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
203 
219  struct msf_s {
220  uint8_t m, s, f; /* BCD encoded! */
221  } GNUC_PACKED;
223 
224  typedef struct msf_s msf_t;
225 
226 #define msf_t_SIZEOF 3
227 
234  typedef char cdio_utf8_t;
235 
236  typedef enum {
237  nope = 0,
238  yep = 1,
239  dunno = 2
240  } bool_3way_t;
241 
242  /* type used for bit-fields in structs (1 <= bits <= 8) */
243 #if defined(__GNUC__)
244  /* this is strict ISO C99 which allows only 'unsigned int', 'signed
245  int' and '_Bool' explicitly as bit-field type */
246  typedef unsigned int bitfield_t;
247 #else
248  /* other compilers might increase alignment requirements to match the
249  'unsigned int' type -- fixme: find out how unalignment accesses can
250  be pragma'ed on non-gcc compilers */
251  typedef uint8_t bitfield_t;
252 #endif
253 
259  typedef int32_t lba_t;
260 
266  typedef int32_t lsn_t;
267 
268  /* Address in either MSF or logical format */
270  {
272  lba_t lba;
273  };
274 
276  typedef uint8_t track_t;
277 
279  typedef uint8_t session_t;
280 
284 #define CDIO_INVALID_SESSION 0xFF
285 
291 #define CDIO_INVALID_LBA -45301
292 
296 #define CDIO_INVALID_LSN CDIO_INVALID_LBA
297 
302 #define CDIO_MCN_SIZE 13
303 
308  typedef char cdio_mcn_t[CDIO_MCN_SIZE+1];
309 
310 
314 #define CDIO_ISRC_SIZE 12
315 
320  typedef char cdio_isrc_t[CDIO_ISRC_SIZE+1];
321 
322  typedef int cdio_fs_anal_t;
323 
328  typedef enum {
337 
338 
339 /* Note that this matches the free() prototype.*/
340 typedef void (*CdioDataFree_t)(void *ptr);
341 
342 #ifdef __cplusplus
343 }
344 #endif /* __cplusplus */
345 
346 #endif /* CDIO_TYPES_H_ */
347 
348 
349 /*
350  * Local variables:
351  * c-file-style: "gnu"
352  * tab-width: 8
353  * indent-tabs-mode: nil
354  * End:
355  */
Definition: types.h:332
#define PRAGMA_END_PACKED
Definition: types.h:169
int cdio_fs_anal_t
Definition: types.h:322
char cdio_mcn_t[CDIO_MCN_SIZE+1]
Definition: types.h:308
Definition: types.h:237
int32_t lsn_t
Definition: types.h:266
#define PRAGMA_BEGIN_PACKED
Definition: types.h:168
Definition: types.h:269
Definition: types.h:330
uint8_t track_t
Definition: types.h:276
typedefPRAGMA_END_PACKED struct msf_s msf_t
Definition: types.h:224
void(* CdioDataFree_t)(void *ptr)
Definition: types.h:340
uint8_t session_t
Definition: types.h:279
#define CDIO_MCN_SIZE
Definition: types.h:302
int32_t lba_t
Definition: types.h:259
Definition: types.h:329
Definition: types.h:238
Definition: types.h:334
uint8_t ubyte
Definition: types.h:51
Definition: types.h:335
uint8_t f
Definition: types.h:220
uint8_t m
Definition: types.h:220
Definition: types.h:239
#define CDIO_ISRC_SIZE
Definition: types.h:314
uint8_t s
Definition: types.h:220
char cdio_utf8_t
UTF-8 char definition.
Definition: types.h:234
lba_t lba
Definition: types.h:272
bool_3way_t
Definition: types.h:236
Definition: types.h:333
char cdio_isrc_t[CDIO_ISRC_SIZE+1]
Definition: types.h:320
MSF (minute/second/frame) structure.
Definition: types.h:219
#define GNUC_PACKED
Definition: types.h:151
cdio_track_flag
Definition: types.h:328
uint8_t bitfield_t
Definition: types.h:251
msf_t msf
Definition: types.h:271