nifti1_io
znzlib.h
1 #ifndef _ZNZLIB_H_
2 #define _ZNZLIB_H_
3 
4 /*
5 znzlib.h (zipped or non-zipped library)
6 
7 ***** This code is released to the public domain. *****
8 
9 ***** Author: Mark Jenkinson, FMRIB Centre, University of Oxford *****
10 ***** Date: September 2004 *****
11 
12 ***** Neither the FMRIB Centre, the University of Oxford, nor any of *****
13 ***** its employees imply any warranty of usefulness of this software *****
14 ***** for any purpose, and do not assume any liability for damages, *****
15 ***** incidental or otherwise, caused by any use of this document. *****
16 
17 */
18 
19 /*
20 
21 This library provides an interface to both compressed (gzip/zlib) and
22 uncompressed (normal) file IO. The functions are written to have the
23 same interface as the standard file IO functions.
24 
25 To use this library instead of normal file IO, the following changes
26 are required:
27  - replace all instances of FILE* with znzFile
28  - change the name of all function calls, replacing the initial character
29  f with the znz (e.g. fseek becomes znzseek)
30  - add a third parameter to all calls to znzopen (previously fopen)
31  that specifies whether to use compression (1) or not (0)
32  - use znz_isnull rather than any (pointer == NULL) comparisons in the code
33 
34 NB: seeks for writable files with compression are quite restricted
35 
36 */
37 
38 
39 /*=================*/
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 /*=================*/
44 
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
48 #include <stdarg.h>
49 
50 
51 /* include optional check for HAVE_FDOPEN here, from deleted config.h:
52 
53  uncomment the following line if fdopen() exists for your compiler and
54  compiler options
55 */
56 /* #define HAVE_FDOPEN */
57 
58 #if defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64) || defined(_MSVC) || defined(_MSC_VER)
59 #include <io.h>
60 #define fseek _fseeki64
61 #define ftell _ftelli64
62 #define znz_off_t long long
63 #elif defined(__APPLE__) || defined(__FreeBSD__)
64 #define znz_off_t off_t
65 #else
66 #include <unistd.h>
67 #include <sys/types.h>
68 #define znz_off_t off_t
69 #endif
70 
71 #ifdef HAVE_ZLIB
72 #if defined(ITKZLIB) && !defined(ITK_USE_SYSTEM_ZLIB)
73 #include "itk_zlib.h"
74 #else
75 #include "zlib.h"
76 #endif
77 #endif
78 
79 struct znzptr {
80  int withz;
81  FILE* nzfptr;
82 #ifdef HAVE_ZLIB
83  gzFile zfptr;
84 #endif
85 } ;
86 
87 /* the type for all file pointers */
88 typedef struct znzptr * znzFile;
89 
90 
91 /* int znz_isnull(znzFile f); */
92 /* int znzclose(znzFile f); */
93 #define znz_isnull(f) ((f) == NULL)
94 #define znzclose(f) Xznzclose(&(f))
95 
96 /* Note extra argument (use_compression) where
97  use_compression==0 is no compression
98  use_compression!=0 uses zlib (gzip) compression
99 */
100 
101 znzFile znzopen(const char *path, const char *mode, int use_compression);
102 
103 #ifdef COMPILE_NIFTIUNUSED_CODE
104 znzFile znzdopen(int fd, const char *mode, int use_compression);
105 #endif
106 
107 int Xznzclose(znzFile * file);
108 
109 size_t znzread(void* buf, size_t size, size_t nmemb, znzFile file);
110 
111 size_t znzwrite(const void* buf, size_t size, size_t nmemb, znzFile file);
112 
113 znz_off_t znzseek(znzFile file, znz_off_t offset, int whence);
114 
115 int znzrewind(znzFile stream);
116 
117 znz_off_t znztell(znzFile file);
118 
119 int znzputs(const char *str, znzFile file);
120 
121 #ifdef COMPILE_NIFTIUNUSED_CODE
122 char * znzgets(char* str, int size, znzFile file);
123 
124 int znzputc(int c, znzFile file);
125 
126 int znzgetc(znzFile file);
127 
128 #if !defined(WIN32)
129 int znzprintf(znzFile stream, const char *format, ...);
130 #endif
131 #endif
132 
133 /*=================*/
134 #ifdef __cplusplus
135 }
136 #endif
137 /*=================*/
138 
139 #endif
znzptr
Definition: znzlib.h:79