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