w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

bin-io.h
Go to the documentation of this file.
1 #ifndef CARYLL_SUPPORT_BIN_IO_H
2 #define CARYLL_SUPPORT_BIN_IO_H
3 
4 #include <stdint.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 
8 #ifndef INLINE
9 #ifdef _MSC_VER
10 #define INLINE __forceinline /* use __forceinline (VC++ specific) */
11 #else
12 #define INLINE inline /* use standard inline */
13 #endif
14 #endif
15 
16 static INLINE bool otfcc_check_endian(void) {
17  union {
18  uint8_t i1[2];
19  uint16_t i2;
20  } check_union = {.i2 = 1}; // if you don't have a new VC, upgrade it
21 
22  return (check_union.i1[0] == 1);
23 }
24 
26  if (otfcc_check_endian()) {
27  union {
28  uint8_t i1[2];
29  uint16_t i2;
30  } src, des;
31 
32  src.i2 = i;
33 
34  des.i1[0] = src.i1[1];
35  des.i1[1] = src.i1[0];
36 
37  return des.i2;
38  } else {
39  return i;
40  }
41 }
42 
44  if (otfcc_check_endian()) {
45  union {
46  uint8_t i1[4];
47  uint32_t i4;
48  } src, des;
49 
50  src.i4 = i;
51 
52  des.i1[0] = src.i1[3];
53  des.i1[1] = src.i1[2];
54  des.i1[2] = src.i1[1];
55  des.i1[3] = src.i1[0];
56 
57  return des.i4;
58  } else {
59  return i;
60  }
61 }
62 
64  if (otfcc_check_endian()) {
65  union {
66  uint8_t i1[8];
67  uint64_t i8;
68  } src, des;
69 
70  src.i8 = i;
71 
72  des.i1[0] = src.i1[7];
73  des.i1[1] = src.i1[6];
74  des.i1[2] = src.i1[5];
75  des.i1[3] = src.i1[4];
76  des.i1[4] = src.i1[3];
77  des.i1[5] = src.i1[2];
78  des.i1[6] = src.i1[1];
79  des.i1[7] = src.i1[0];
80 
81  return des.i8;
82  } else {
83  return i;
84  }
85 }
86 
88  uint16_t tmp;
89  size_t sizeRead = fread(&tmp, 2, 1, file);
90  if (!sizeRead) {
91  fprintf(stderr, "File corruption of terminated unexpectedly.\n");
93  }
94  return otfcc_endian_convert16(tmp);
95 }
96 
98  uint32_t tmp;
99  size_t sizeRead = fread(&tmp, 4, 1, file);
100  if (!sizeRead) {
101  fprintf(stderr, "File corruption of terminated unexpectedly.\n");
103  }
104  return otfcc_endian_convert32(tmp);
105 }
106 
108  uint64_t tmp;
109  size_t sizeRead = fread(&tmp, 8, 1, file);
110  if (!sizeRead) {
111  fprintf(stderr, "File corruption of terminated unexpectedly.\n");
113  }
114  return otfcc_endian_convert64(tmp);
115 }
116 
117 // data reader
118 static INLINE uint8_t read_8u(const uint8_t *src) {
119  return src[0];
120 }
122  uint16_t b0 = ((uint16_t)src[0]) << 8;
123  uint16_t b1 = ((uint16_t)src[1]);
124  return (b0 | b1);
125 }
127  uint32_t b0 = ((uint32_t)src[0]) << 16;
128  uint32_t b1 = ((uint32_t)src[1]) << 8;
129  uint32_t b2 = ((uint32_t)src[2]);
130  return (b0 | b1 | b2);
131 }
133  uint32_t b0 = ((uint32_t)src[0]) << 24;
134  uint32_t b1 = ((uint32_t)src[1]) << 16;
135  uint32_t b2 = ((uint32_t)src[2]) << 8;
136  uint32_t b3 = ((uint32_t)src[3]);
137  return (b0 | b1 | b2 | b3);
138 }
140  uint64_t b0 = ((uint64_t)src[0]) << 56;
141  uint64_t b1 = ((uint64_t)src[1]) << 48;
142  uint64_t b2 = ((uint64_t)src[2]) << 40;
143  uint64_t b3 = ((uint64_t)src[3]) << 32;
144  uint64_t b4 = ((uint64_t)src[4]) << 24;
145  uint64_t b5 = ((uint64_t)src[5]) << 16;
146  uint64_t b6 = ((uint64_t)src[6]) << 8;
147  uint64_t b7 = ((uint64_t)src[7]);
148  return (b0 | b1 | b2 | b3 | b4 | b5 | b6 | b7);
149 }
150 static INLINE int8_t read_8s(const uint8_t *src) {
151  return (int8_t)read_8u(src);
152 }
154  return (int16_t)read_16u(src);
155 }
157  return (int32_t)read_32u(src);
158 }
160  return (int64_t)read_64u(src);
161 }
162 
164  return ((x & 0xff) << 8) | ((x & 0xFF00) >> 8);
165 }
167  return ((x & 0x000000ff) << 24) | ((x & 0x0000FF00) << 8) | ((x & 0x00FF0000) >> 8) |
168  ((x & 0xFF000000) >> 24);
169 }
170 
171 #endif
static uint32_t otfcc_get32u(FILE *file)
Definition: bin-io.h:97
static uint8_t read_8u(const uint8_t *src)
Definition: bin-io.h:118
static uint32_t read_32u(const uint8_t *src)
Definition: bin-io.h:132
#define INLINE
Definition: bin-io.h:12
static uint16_t read_16u(const uint8_t *src)
Definition: bin-io.h:121
static uint64_t otfcc_get64u(FILE *file)
Definition: bin-io.h:107
static int16_t read_16s(const uint8_t *src)
Definition: bin-io.h:153
static uint16_t be16(uint16_t x)
Definition: bin-io.h:163
static int64_t read_64s(const uint8_t *src)
Definition: bin-io.h:159
static bool otfcc_check_endian(void)
Definition: bin-io.h:16
static uint16_t otfcc_get16u(FILE *file)
Definition: bin-io.h:87
static int8_t read_8s(const uint8_t *src)
Definition: bin-io.h:150
static uint32_t read_24u(const uint8_t *src)
Definition: bin-io.h:126
static uint32_t be32(uint32_t x)
Definition: bin-io.h:166
static uint16_t otfcc_endian_convert16(uint16_t i)
Definition: bin-io.h:25
static uint32_t otfcc_endian_convert32(uint32_t i)
Definition: bin-io.h:43
static uint64_t read_64u(const uint8_t *src)
Definition: bin-io.h:139
static uint64_t otfcc_endian_convert64(uint64_t i)
Definition: bin-io.h:63
static int32_t read_32s(const uint8_t *src)
Definition: bin-io.h:156
#define fread
Definition: xxstdio.h:25
#define EXIT_FAILURE
Definition: cdjpeg.h:169
small capitals from c petite p scientific i
Definition: afcover.h:80
void exit()
signed short int16_t
Definition: stdint.h:76
unsigned short uint16_t
Definition: stdint.h:79
signed __int64 int64_t
Definition: stdint.h:89
unsigned int uint32_t
Definition: stdint.h:80
signed int int32_t
Definition: stdint.h:77
unsigned char uint8_t
Definition: stdint.h:78
unsigned __int64 uint64_t
Definition: stdint.h:90
signed char int8_t
Definition: stdint.h:75
#define fprintf
Definition: mendex.h:64
#define b0
Definition: texmfmem.h:168
#define b1
Definition: texmfmem.h:169
#define b3
Definition: texmfmem.h:171
#define b2
Definition: texmfmem.h:170
float x
Definition: cordic.py:15
#define uint32_t
Definition: stdint.in.h:168
#define uint64_t
Definition: stdint.in.h:215
#define uint16_t
Definition: stdint.in.h:161
Definition: filedef.h:30
#define FILE
Definition: t1stdio.h:34