/src/types.h

https://code.google.com/ · C Header · 154 lines · 84 code · 38 blank · 32 comment · 4 complexity · 7af292a2e4e8b6322304fb04b4d18966 MD5 · raw file

  1. /*
  2. $Id: types.h 231 2011-06-27 13:46:19Z marc.noirot $
  3. FLV Metadata updater
  4. Copyright (C) 2007-2012 Marc Noirot <marc.noirot AT gmail.com>
  5. This file is part of FLVMeta.
  6. FLVMeta 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 2 of the License, or
  9. (at your option) any later version.
  10. FLVMeta is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with FLVMeta; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef __TYPES_H__
  19. #define __TYPES_H__
  20. /* Configuration of the sources */
  21. #ifdef HAVE_CONFIG_H
  22. # include <config.h>
  23. #endif
  24. #ifdef HAVE_STDINT_H
  25. # include <stdint.h>
  26. #endif
  27. #ifdef HAVE_SYS_TYPES_H
  28. # include <sys/types.h> /* off_t */
  29. #endif
  30. #ifdef HAVE_INTTYPES_H
  31. # include <inttypes.h>
  32. #endif
  33. #include <stdio.h>
  34. typedef uint8_t byte, uint8, uint8_bitmask;
  35. typedef uint16_t uint16, uint16_be, uint16_le;
  36. typedef int16_t sint16, sint16_be, sint16_le;
  37. typedef uint32_t uint32, uint32_be, uint32_le;
  38. typedef int32_t sint32, sint32_be, sint32_le;
  39. typedef struct __uint24 {
  40. uint8 b[3];
  41. } uint24, uint24_be, uint24_le;
  42. typedef uint64_t uint64, uint64_le, uint64_be;
  43. typedef int64_t sint64, sint64_le, sint64_be;
  44. typedef
  45. #if SIZEOF_FLOAT == 8
  46. float
  47. #elif SIZEOF_DOUBLE == 8
  48. double
  49. #elif SIZEOF_LONG_DOUBLE == 8
  50. long double
  51. #else
  52. uint64_t
  53. #endif
  54. number64, number64_le, number64_be;
  55. #ifdef __cplusplus
  56. extern "C" {
  57. #endif /* __cplusplus */
  58. #ifdef WORDS_BIGENDIAN
  59. # define swap_uint16(x) (x)
  60. # define swap_sint16(x) (x)
  61. # define swap_uint32(x) (x)
  62. # define swap_number64(x) (x)
  63. #else /* !defined WORDS_BIGENDIAN */
  64. /* swap 16 bits integers */
  65. # define swap_uint16(x) ((uint16)((((x) & 0x00FFU) << 8) | \
  66. (((x) & 0xFF00U) >> 8)))
  67. # define swap_sint16(x) ((sint16)((((x) & 0x00FF) << 8) | \
  68. (((x) & 0xFF00) >> 8)))
  69. /* swap 32 bits integers */
  70. # define swap_uint32(x) ((uint32)((((x) & 0x000000FFU) << 24) | \
  71. (((x) & 0x0000FF00U) << 8) | \
  72. (((x) & 0x00FF0000U) >> 8) | \
  73. (((x) & 0xFF000000U) >> 24)))
  74. /* swap 64 bits doubles */
  75. number64 swap_number64(number64);
  76. #endif /* WORDS_BIGENDIAN */
  77. /* convert big endian 24 bits integers to native integers */
  78. # define uint24_be_to_uint32(x) ((uint32)(((x).b[0] << 16) | \
  79. ((x).b[1] << 8) | (x).b[2]))
  80. /* convert native integers into 24 bits big endian integers */
  81. uint24_be uint32_to_uint24_be(uint32);
  82. /* large file support */
  83. #ifdef HAVE_FSEEKO
  84. # define lfs_ftell ftello
  85. # define lfs_fseek fseeko
  86. # define FILE_OFFSET_T_64_BITS 1
  87. typedef off_t file_offset_t;
  88. #else /* !HAVE_SEEKO */
  89. # ifdef WIN32
  90. # define FILE_OFFSET_T_64_BITS 1
  91. typedef long long int file_offset_t;
  92. /* Win32 large file support */
  93. file_offset_t lfs_ftell(FILE * stream);
  94. int lfs_fseek(FILE * stream, file_offset_t offset, int whence);
  95. # else /* !defined WIN32 */
  96. # define lfs_ftell ftell
  97. # define lfs_fseek fseek
  98. typedef long file_offset_t;
  99. # endif /* WIN32 */
  100. #endif /* HAVE_FSEEKO */
  101. /* file offset printf specifier */
  102. #ifdef FILE_OFFSET_T_64_BITS
  103. # define FILE_OFFSET_PRINTF_FORMAT "ll"
  104. #else
  105. # define FILE_OFFSET_PRINTF_FORMAT "l"
  106. #endif
  107. #ifdef __cplusplus
  108. }
  109. #endif /* __cplusplus */
  110. #endif /* __TYPES_H__ */