znzlib.h 3.4 KB

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