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 20 /** \file types.h 21 * \brief Common type definitions used pervasively in libcdio. 22 */ 23 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 187 /** Provide a notice for deprecated elements. Before gcc 4.5 'deprecated' 188 takes no arguments. */ 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 201 /** our own offsetof()-like macro */ 202 #define __cd_offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 203 204 /*! 205 \brief MSF (minute/second/frame) structure 206 207 One CD-ROMs addressing scheme especially used in audio formats 208 (Red Book) is an address by minute, sector and frame which 209 BCD-encoded in three bytes. An alternative format is an lba_t. 210 211 Note: the fields in this structure are BCD encoded. Use 212 cdio_to_bcd8() or cdio_from_bcd8() to convert an integer into or 213 out of this format. The format specifier %x (not %d) can be used 214 if you need to format or print values in this structure. 215 216 @see lba_t 217 */ 218 PRAGMA_BEGIN_PACKED 219 struct msf_s { 220 uint8_t m, s, f; /* BCD encoded! */ 221 } GNUC_PACKED; 222 PRAGMA_END_PACKED 223 224 typedef struct msf_s msf_t; 225 226 #define msf_t_SIZEOF 3 227 228 /*! 229 \brief UTF-8 char definition 230 231 Type to denote UTF-8 strings. 232 */ 233 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 254 /*! The type of a Logical Block Address. We allow for an lba to be 255 negative to be consistent with an lba, although I'm not sure this 256 this is possible. 257 258 */ 259 typedef int32_t lba_t; 260 261 /*! The type of a Logical Sector Number. Note that an lba can be negative 262 and the MMC3 specs allow for a conversion of a negative lba. 263 264 @see msf_t 265 */ 266 typedef int32_t lsn_t; 267 268 /* Address in either MSF or logical format */ 269 union cdio_cdrom_addr 270 { 271 msf_t msf; 272 lba_t lba; 273 }; 274 275 /*! The type of a track number 0..99. */ 276 typedef uint8_t track_t; 277 278 /*! The type of a session number 0..99. */ 279 typedef uint8_t session_t; 280 281 /*! 282 Constant for invalid session number 283 */ 284 #define CDIO_INVALID_SESSION 0xFF 285 286 /*! 287 Constant for invalid LBA. It is 151 less than the most negative 288 LBA -45150. This provide slack for the 150-frame offset in 289 LBA to LSN 150 conversions 290 */ 291 #define CDIO_INVALID_LBA -45301 292 293 /*! 294 Constant for invalid LSN 295 */ 296 #define CDIO_INVALID_LSN CDIO_INVALID_LBA 297 298 /*! 299 Number of ASCII bytes in a media catalog number (MCN). 300 We include an extra 0 byte so these can be used as C strings. 301 */ 302 #define CDIO_MCN_SIZE 13 303 304 /*! 305 Type to hold ASCII bytes in a media catalog number (MCN). 306 We include an extra 0 byte so these can be used as C strings. 307 */ 308 typedef char cdio_mcn_t[CDIO_MCN_SIZE+1]; 309 310 311 /*! 312 Number of ASCII bytes in International Standard Recording Codes (ISRC) 313 */ 314 #define CDIO_ISRC_SIZE 12 315 316 /*! 317 Type to hold ASCII bytes in a ISRC. 318 We include an extra 0 byte so these can be used as C strings. 319 */ 320 typedef char cdio_isrc_t[CDIO_ISRC_SIZE+1]; 321 322 typedef int cdio_fs_anal_t; 323 324 /*! 325 track flags 326 Q Sub-channel Control Field (4.2.3.3) 327 */ 328 typedef enum { 329 CDIO_TRACK_FLAG_NONE = 0x00, /**< no flags set */ 330 CDIO_TRACK_FLAG_PRE_EMPHASIS = 0x01, /**< audio track recorded with 331 pre-emphasis */ 332 CDIO_TRACK_FLAG_COPY_PERMITTED = 0x02, /**< digital copy permitted */ 333 CDIO_TRACK_FLAG_DATA = 0x04, /**< data track */ 334 CDIO_TRACK_FLAG_FOUR_CHANNEL_AUDIO = 0x08, /**< 4 audio channels */ 335 CDIO_TRACK_FLAG_SCMS = 0x10 /**< SCMS (5.29.2.7) */ 336 } cdio_track_flag; 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 */ 356