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 /* include optional check for HAVE_FDOPEN here, from deleted config.h:
51 
52  uncomment the following line if fdopen() exists for your compiler and
53  compiler options
54 */
55 /* #define HAVE_FDOPEN */
56 
57 
58 #ifdef HAVE_ZLIB
59 #if defined(ITKZLIB) && !defined(ITK_USE_SYSTEM_ZLIB)
60 #include "itk_zlib.h"
61 #else
62 #include "zlib.h"
63 #endif
64 #endif
65 
66 struct znzptr {
67  int withz;
68  FILE* nzfptr;
69 #ifdef HAVE_ZLIB
70  gzFile zfptr;
71 #endif
72 } ;
73 
74 /* the type for all file pointers */
75 typedef struct znzptr * znzFile;
76 
77 
78 /* int znz_isnull(znzFile f); */
79 /* int znzclose(znzFile f); */
80 #define znz_isnull(f) ((f) == NULL)
81 #define znzclose(f) Xznzclose(&(f))
82 
83 /* Note extra argument (use_compression) where
84  use_compression==0 is no compression
85  use_compression!=0 uses zlib (gzip) compression
86 */
87 
88 znzFile znzopen(const char *path, const char *mode, int use_compression);
89 
90 znzFile znzdopen(int fd, const char *mode, int use_compression);
91 
92 int Xznzclose(znzFile * file);
93 
94 size_t znzread(void* buf, size_t size, size_t nmemb, znzFile file);
95 
96 size_t znzwrite(const void* buf, size_t size, size_t nmemb, znzFile file);
97 
98 long znzseek(znzFile file, long offset, int whence);
99 
100 int znzrewind(znzFile stream);
101 
102 long znztell(znzFile file);
103 
104 int znzputs(const char *str, znzFile file);
105 
106 char * znzgets(char* str, int size, znzFile file);
107 
108 int znzputc(int c, znzFile file);
109 
110 int znzgetc(znzFile file);
111 
112 #if !defined(WIN32)
113 int znzprintf(znzFile stream, const char *format, ...);
114 #endif
115 
116 /*=================*/
117 #ifdef __cplusplus
118 }
119 #endif
120 /*=================*/
121 
122 #endif
Definition: znzlib.h:66