nifti1_io
|
00001 #ifndef _ZNZLIB_H_ 00002 #define _ZNZLIB_H_ 00003 00004 /* 00005 znzlib.h (zipped or non-zipped library) 00006 00007 ***** This code is released to the public domain. ***** 00008 00009 ***** Author: Mark Jenkinson, FMRIB Centre, University of Oxford ***** 00010 ***** Date: September 2004 ***** 00011 00012 ***** Neither the FMRIB Centre, the University of Oxford, nor any of ***** 00013 ***** its employees imply any warranty of usefulness of this software ***** 00014 ***** for any purpose, and do not assume any liability for damages, ***** 00015 ***** incidental or otherwise, caused by any use of this document. ***** 00016 00017 */ 00018 00019 /* 00020 00021 This library provides an interface to both compressed (gzip/zlib) and 00022 uncompressed (normal) file IO. The functions are written to have the 00023 same interface as the standard file IO functions. 00024 00025 To use this library instead of normal file IO, the following changes 00026 are required: 00027 - replace all instances of FILE* with znzFile 00028 - change the name of all function calls, replacing the initial character 00029 f with the znz (e.g. fseek becomes znzseek) 00030 - add a third parameter to all calls to znzopen (previously fopen) 00031 that specifies whether to use compression (1) or not (0) 00032 - use znz_isnull rather than any (pointer == NULL) comparisons in the code 00033 00034 NB: seeks for writable files with compression are quite restricted 00035 00036 */ 00037 00038 00039 /*=================*/ 00040 #ifdef __cplusplus 00041 extern "C" { 00042 #endif 00043 /*=================*/ 00044 00045 #include <stdio.h> 00046 #include <stdlib.h> 00047 #include <string.h> 00048 #include <stdarg.h> 00049 00050 /* include optional check for HAVE_FDOPEN here, from deleted config.h: 00051 00052 uncomment the following line if fdopen() exists for your compiler and 00053 compiler options 00054 */ 00055 /* #define HAVE_FDOPEN */ 00056 00057 00058 #ifdef HAVE_ZLIB 00059 #if defined(ITKZLIB) && !defined(ITK_USE_SYSTEM_ZLIB) 00060 #include "itk_zlib.h" 00061 #else 00062 #include "zlib.h" 00063 #endif 00064 #endif 00065 00066 struct znzptr { 00067 int withz; 00068 FILE* nzfptr; 00069 #ifdef HAVE_ZLIB 00070 gzFile zfptr; 00071 #endif 00072 } ; 00073 00074 /* the type for all file pointers */ 00075 typedef struct znzptr * znzFile; 00076 00077 00078 /* int znz_isnull(znzFile f); */ 00079 /* int znzclose(znzFile f); */ 00080 #define znz_isnull(f) ((f) == NULL) 00081 #define znzclose(f) Xznzclose(&(f)) 00082 00083 /* Note extra argument (use_compression) where 00084 use_compression==0 is no compression 00085 use_compression!=0 uses zlib (gzip) compression 00086 */ 00087 00088 znzFile znzopen(const char *path, const char *mode, int use_compression); 00089 00090 znzFile znzdopen(int fd, const char *mode, int use_compression); 00091 00092 int Xznzclose(znzFile * file); 00093 00094 size_t znzread(void* buf, size_t size, size_t nmemb, znzFile file); 00095 00096 size_t znzwrite(const void* buf, size_t size, size_t nmemb, znzFile file); 00097 00098 long znzseek(znzFile file, long offset, int whence); 00099 00100 int znzrewind(znzFile stream); 00101 00102 long znztell(znzFile file); 00103 00104 int znzputs(const char *str, znzFile file); 00105 00106 char * znzgets(char* str, int size, znzFile file); 00107 00108 int znzputc(int c, znzFile file); 00109 00110 int znzgetc(znzFile file); 00111 00112 #if !defined(WIN32) 00113 int znzprintf(znzFile stream, const char *format, ...); 00114 #endif 00115 00116 /*=================*/ 00117 #ifdef __cplusplus 00118 } 00119 #endif 00120 /*=================*/ 00121 00122 #endif