Debian Codegraph @

matio-1.5.30/src/matio_private.h

raw symbols SCIP
1 /*
2 * Copyright (c) 2015-2026, The matio contributors
3 * Copyright (c) 2008-2014, Christopher C. Hulbert
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifndef MATIO_PRIVATE_H
29 #define MATIO_PRIVATE_H
30
31 #if defined(__MINGW32__) && !defined(__USE_MINGW_ANSI_STDIO)
32 #define __USE_MINGW_ANSI_STDIO 1
33 #endif
34
35 #include "matioConfig.h"
36 #include "matio.h"
37
38 #include <stdio.h>
39 #if defined(HAVE_UNISTD_H)
40 #include <unistd.h>
41 #endif
42
43 #if defined(__BORLANDC__) || defined(__MINGW32__) || defined(_MSC_VER)
44 #if defined(_MSC_VER) && defined(HAVE__FSEEKI64) && defined(HAVE__FTELLI64)
45 #define MATIO_LFS
46 #define mat_off_t __int64
47 #define fseeko _fseeki64
48 #define ftello _ftelli64
49 #elif defined(__BORLANDC__) && defined(HAVE__FSEEKI64) && defined(HAVE__FTELLI64)
50 #define MATIO_LFS
51 #define mat_off_t __int64
52 #define fseeko _fseeki64
53 #define ftello _ftelli64
54 #elif defined(HAVE_FSEEKO64) && defined(HAVE_FTELLO64)
55 #define MATIO_LFS
56 #define mat_off_t __int64
57 #define fseeko fseeko64
58 #define ftello ftello64
59 #endif
60 #elif defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && defined(HAVE_FSEEKO) && \
61 defined(HAVE_FTELLO)
62 #define MATIO_LFS
63 #define mat_off_t off_t
64 #endif
65
66 #if !defined(MATIO_LFS)
67 #define mat_off_t long
68 #define ftello ftell
69 #define fseeko fseek
70 #endif
71
72 #if HAVE_ZLIB
73 #include <zlib.h>
74 #endif
75 #if defined(MAT73) && MAT73
76 #include <hdf5.h>
77 #endif
78
79 #ifndef EXTERN
80 #ifdef __cplusplus
81 #define EXTERN extern "C"
82 #else
83 #define EXTERN extern
84 #endif
85 #endif
86
87 #if HAVE_ZLIB
88 #define ZLIB_BYTE_PTR(a) ((Bytef *)(a))
89 #endif
90
91 #if !defined(READ_BLOCK_SIZE)
92 #define READ_BLOCK_SIZE (8192)
93 #endif
94
95 #define CAT_(X, Y) X##Y
96 #define CAT(X, Y) CAT_(X, Y)
97
98 #if defined(__GLIBC__)
99 #if ( __BYTE_ORDER == __BIG_ENDIAN )
100 #define MATIO_BE
101 #elif (__BYTE_ORDER == __LITTLE_ENDIAN)
102 #define MATIO_LE
103 #endif
104 #elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
105 #define MATIO_BE
106 #elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
107 #define MATIO_LE
108 #elif defined(__sparc) || defined(__sparc__) || defined(_POWER) || defined(__powerpc__) || \
109 defined(__ppc__) || defined(__hpux) || defined(_MIPSEB) || defined(_POWER) || \
110 defined(__s390__)
111 #define MATIO_BE
112 #elif defined(__i386__) || defined(__alpha__) || defined(__ia64) || defined(__ia64__) || \
113 defined(_M_IX86) || defined(_M_IA64) || defined(_M_ALPHA) || defined(__amd64) || \
114 defined(__amd64__) || defined(_M_AMD64) || defined(__x86_64) || defined(__x86_64__) || \
115 defined(_M_X64) || defined(__bfin__) || defined(__loongarch64) || defined(__aarch64__)
116 #define MATIO_LE
117 #endif
118
119 /** @if mat_devman
120 * @brief Matlab MAT File information
121 *
122 * Contains information about a Matlab MAT file
123 * @ingroup mat_internal
124 * @endif
125 */
126 struct _mat_t
127 {
128 void *fp; /**< File pointer for the MAT file */
129 char *header; /**< MAT file header string */
130 char *subsys_offset; /**< Offset */
131 char *filename; /**< Filename of the MAT file */
132 int version; /**< MAT file version */
133 int byteswap; /**< 1 if byte swapping is required, 0 otherwise */
134 int mode; /**< Access mode */
135 mat_off_t bof; /**< Beginning of file not including any header */
136 size_t next_index; /**< Index/File position of next variable to read */
137 size_t num_datasets; /**< Number of datasets in the file */
138 #if defined(MAT73) && MAT73
139 hid_t refs_id; /**< Id of the /#refs# group in HDF5 */
140 #endif
141 char **dir; /**< Names of the datasets in the file */
142 };
143
144 /** @if mat_devman
145 * @brief internal structure for MAT variables
146 * @ingroup mat_internal
147 * @endif
148 */
149 struct matvar_internal
150 {
151 #if defined(MAT73) && MAT73
152 hobj_ref_t hdf5_ref; /**< Reference */
153 hid_t id; /**< Id */
154 #endif
155 mat_off_t datapos; /**< Offset from the beginning of the MAT file to the data */
156 unsigned num_fields; /**< Number of fields */
157 char **fieldnames; /**< Pointer to fieldnames */
158 #if HAVE_ZLIB
159 z_streamp z; /**< zlib compression state */
160 void *data; /**< Inflated data array */
161 #endif
162 };
163
164 /* snprintf.c */
165 #if !HAVE_VSNPRINTF
166 int rpl_vsnprintf(char *, size_t, const char *, va_list);
167 #define mat_vsnprintf rpl_vsnprintf
168 #else
169 #define mat_vsnprintf vsnprintf
170 #endif /* !HAVE_VSNPRINTF */
171 #if !HAVE_SNPRINTF
172 int rpl_snprintf(char *, size_t, const char *, ...);
173 #define mat_snprintf rpl_snprintf
174 #else
175 #define mat_snprintf snprintf
176 #endif /* !HAVE_SNPRINTF */
177 #if !HAVE_VASPRINTF
178 int rpl_vasprintf(char **, const char *, va_list);
179 #define mat_vasprintf rpl_vasprintf
180 #else
181 #define mat_vasprintf vasprintf
182 #endif /* !HAVE_VASPRINTF */
183 #if !HAVE_ASPRINTF
184 int rpl_asprintf(char **, const char *, ...);
185 #define mat_asprintf rpl_asprintf
186 #else
187 #define mat_asprintf asprintf
188 #endif /* !HAVE_ASPRINTF */
189
190 /* endian.c */
191 EXTERN double Mat_doubleSwap(double *a);
192 EXTERN float Mat_floatSwap(float *a);
193 #ifdef HAVE_MAT_INT64_T
194 EXTERN mat_int64_t Mat_int64Swap(mat_int64_t *a);
195 #endif /* HAVE_MAT_INT64_T */
196 #ifdef HAVE_MAT_UINT64_T
197 EXTERN mat_uint64_t Mat_uint64Swap(mat_uint64_t *a);
198 #endif /* HAVE_MAT_UINT64_T */
199 EXTERN mat_int32_t Mat_int32Swap(mat_int32_t *a);
200 EXTERN mat_uint32_t Mat_uint32Swap(mat_uint32_t *a);
201 EXTERN mat_int16_t Mat_int16Swap(mat_int16_t *a);
202 EXTERN mat_uint16_t Mat_uint16Swap(mat_uint16_t *a);
203
204 /* read_data.c */
205 EXTERN int ReadDoubleData(mat_t *mat, double *data, enum matio_types data_type, size_t len);
206 EXTERN int ReadSingleData(mat_t *mat, float *data, enum matio_types data_type, size_t len);
207 #ifdef HAVE_MAT_INT64_T
208 EXTERN int ReadInt64Data(mat_t *mat, mat_int64_t *data, enum matio_types data_type, size_t len);
209 #endif /* HAVE_MAT_INT64_T */
210 #ifdef HAVE_MAT_UINT64_T
211 EXTERN int ReadUInt64Data(mat_t *mat, mat_uint64_t *data, enum matio_types data_type, size_t len);
212 #endif /* HAVE_MAT_UINT64_T */
213 EXTERN int ReadInt32Data(mat_t *mat, mat_int32_t *data, enum matio_types data_type, size_t len);
214 EXTERN int ReadUInt32Data(mat_t *mat, mat_uint32_t *data, enum matio_types data_type, size_t len);
215 EXTERN int ReadInt16Data(mat_t *mat, mat_int16_t *data, enum matio_types data_type, size_t len);
216 EXTERN int ReadUInt16Data(mat_t *mat, mat_uint16_t *data, enum matio_types data_type, size_t len);
217 EXTERN int ReadInt8Data(mat_t *mat, mat_int8_t *data, enum matio_types data_type, size_t len);
218 EXTERN int ReadUInt8Data(mat_t *mat, mat_uint8_t *data, enum matio_types data_type, size_t len);
219 EXTERN int ReadCharData(mat_t *mat, void *_data, enum matio_types data_type, size_t len);
220 EXTERN int ReadDataSlab1(mat_t *mat, void *data, enum matio_classes class_type,
221 enum matio_types data_type, int start, int stride, int edge);
222 EXTERN int ReadDataSlab2(mat_t *mat, void *data, enum matio_classes class_type,
223 enum matio_types data_type, const size_t *dims, const int *start,
224 const int *stride, const int *edge);
225 EXTERN int ReadDataSlabN(mat_t *mat, void *data, enum matio_classes class_type,
226 enum matio_types data_type, int rank, const size_t *dims, const int *start,
227 const int *stride, const int *edge);
228 #if HAVE_ZLIB
229 EXTERN int ReadCompressedDoubleData(mat_t *mat, z_streamp z, double *data,
230 enum matio_types data_type, int len);
231 EXTERN int ReadCompressedSingleData(mat_t *mat, z_streamp z, float *data,
232 enum matio_types data_type, int len);
233 #ifdef HAVE_MAT_INT64_T
234 EXTERN int ReadCompressedInt64Data(mat_t *mat, z_streamp z, mat_int64_t *data,
235 enum matio_types data_type, int len);
236 #endif /* HAVE_MAT_INT64_T */
237 #ifdef HAVE_MAT_UINT64_T
238 EXTERN int ReadCompressedUInt64Data(mat_t *mat, z_streamp z, mat_uint64_t *data,
239 enum matio_types data_type, int len);
240 #endif /* HAVE_MAT_UINT64_T */
241 EXTERN int ReadCompressedInt32Data(mat_t *mat, z_streamp z, mat_int32_t *data,
242 enum matio_types data_type, int len);
243 EXTERN int ReadCompressedUInt32Data(mat_t *mat, z_streamp z, mat_uint32_t *data,
244 enum matio_types data_type, int len);
245 EXTERN int ReadCompressedInt16Data(mat_t *mat, z_streamp z, mat_int16_t *data,
246 enum matio_types data_type, int len);
247 EXTERN int ReadCompressedUInt16Data(mat_t *mat, z_streamp z, mat_uint16_t *data,
248 enum matio_types data_type, int len);
249 EXTERN int ReadCompressedInt8Data(mat_t *mat, z_streamp z, mat_int8_t *data,
250 enum matio_types data_type, int len);
251 EXTERN int ReadCompressedUInt8Data(mat_t *mat, z_streamp z, mat_uint8_t *data,
252 enum matio_types data_type, int len);
253 EXTERN int ReadCompressedCharData(mat_t *mat, z_streamp z, void *data, enum matio_types data_type,
254 size_t len);
255 EXTERN int ReadCompressedDataSlab1(mat_t *mat, z_streamp z, void *data,
256 enum matio_classes class_type, enum matio_types data_type,
257 int start, int stride, int edge);
258 EXTERN int ReadCompressedDataSlab2(mat_t *mat, z_streamp z, void *data,
259 enum matio_classes class_type, enum matio_types data_type,
260 const size_t *dims, const int *start, const int *stride,
261 const int *edge);
262 EXTERN int ReadCompressedDataSlabN(mat_t *mat, z_streamp z, void *data,
263 enum matio_classes class_type, enum matio_types data_type,
264 int rank, const size_t *dims, const int *start,
265 const int *stride, const int *edge);
266
267 /* inflate.c */
268 EXTERN int InflateSkip(mat_t *mat, z_streamp z, int nBytes, size_t *bytesread);
269 EXTERN int InflateSkipData(mat_t *mat, z_streamp z, enum matio_types data_type, int len);
270 EXTERN int InflateRankDims(mat_t *mat, z_streamp z, void *buf, size_t nBytes, mat_uint32_t **dims,
271 size_t *bytesread);
272 EXTERN int Inflate(mat_t *mat, z_streamp z, void *buf, unsigned int nBytes, size_t *bytesread);
273 EXTERN int InflateData(mat_t *mat, z_streamp z, void *buf, unsigned int nBytes);
274 #endif
275
276 /* mat.c */
277 EXTERN mat_complex_split_t *ComplexMalloc(size_t nbytes);
278 EXTERN void ComplexFree(mat_complex_split_t *complex_data);
279 EXTERN enum matio_types ClassType2DataType(enum matio_classes class_type);
280 EXTERN int Add(size_t *res, size_t a, size_t b);
281 EXTERN int Mul(size_t *res, size_t a, size_t b);
282 EXTERN int Mat_MulDims(const matvar_t *matvar, size_t *nelems);
283 EXTERN int Read(void *buf, size_t size, size_t count, FILE *fp, size_t *bytesread);
284 EXTERN int IsEndOfFile(FILE *fp, mat_off_t *fpos);
285 EXTERN int CheckSeekFile(FILE *fp, mat_off_t offset);
286
287 /* io.c */
288 #if defined(_WIN32)
289 EXTERN wchar_t *utf82u(const char *src);
290 #endif
291
292 #endif