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) 00060 #include "itk_zlib.h" 00061 #else 00062 #include "zlib.h" 00063 #endif 00064 #endif 00065 00066 00067 struct znzptr { 00068 int withz; 00069 FILE* nzfptr; 00070 #ifdef HAVE_ZLIB 00071 gzFile zfptr; 00072 #endif 00073 } ; 00074 00075 /* the type for all file pointers */ 00076 typedef struct znzptr * znzFile; 00077 00078 00079 /* int znz_isnull(znzFile f); */ 00080 /* int znzclose(znzFile f); */ 00081 #define znz_isnull(f) ((f) == NULL) 00082 #define znzclose(f) Xznzclose(&(f)) 00083 00084 /* Note extra argument (use_compression) where 00085 use_compression==0 is no compression 00086 use_compression!=0 uses zlib (gzip) compression 00087 */ 00088 00089 znzFile znzopen(const char *path, const char *mode, int use_compression); 00090 00091 znzFile znzdopen(int fd, const char *mode, int use_compression); 00092 00093 int Xznzclose(znzFile * file); 00094 00095 size_t znzread(void* buf, size_t size, size_t nmemb, znzFile file); 00096 00097 size_t znzwrite(const void* buf, size_t size, size_t nmemb, znzFile file); 00098 00099 long znzseek(znzFile file, long offset, int whence); 00100 00101 int znzrewind(znzFile stream); 00102 00103 long znztell(znzFile file); 00104 00105 int znzputs(const char *str, znzFile file); 00106 00107 char * znzgets(char* str, int size, znzFile file); 00108 00109 int znzputc(int c, znzFile file); 00110 00111 int znzgetc(znzFile file); 00112 00113 #if !defined(WIN32) 00114 int znzprintf(znzFile stream, const char *format, ...); 00115 #endif 00116 00117 /*=================*/ 00118 #ifdef __cplusplus 00119 } 00120 #endif 00121 /*=================*/ 00122 00123 #endif