/src/zziplib/zzip/info.c

https://bitbucket.org/cabalistic/ogredeps/ · C · 163 lines · 88 code · 13 blank · 62 comment · 11 complexity · af55a440dc17627596532818a0105ad6 MD5 · raw file

  1. /*
  2. * Author:
  3. * Guido Draheim <guidod@gmx.de>
  4. *
  5. * Copyright (c) 2000,2001,2002,2003 Guido Draheim
  6. * All rights reserved,
  7. * use under the restrictions of the
  8. * Lesser GNU General Public License
  9. * or alternatively the restrictions
  10. * of the Mozilla Public License 1.1
  11. */
  12. #include <zzip/lib.h> /* exported... */
  13. #include <zzip/file.h>
  14. #include <zzip/format.h>
  15. #ifdef ZZIP_HAVE_SYS_STAT_H
  16. #include <sys/stat.h>
  17. #else
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #endif
  21. /**
  22. * just returns dir->errcode of the ZZIP_DIR handle
  23. * see: => zzip_dir_open, => zzip_dir_open, => zzip_readdir, => zzip_dir_read
  24. */
  25. int
  26. zzip_error(ZZIP_DIR * dir)
  27. {
  28. return dir->errcode;
  29. }
  30. /** => zzip_error
  31. * This function just does dir->errcode = errcode
  32. */
  33. void
  34. zzip_seterror(ZZIP_DIR * dir, int errcode) { dir->errcode = errcode; }
  35. /**
  36. * This function will just return fp->dir
  37. *
  38. * If a ZZIP_FILE is contained within a zip-file that one will be a valid
  39. * pointer, otherwise a NULL is returned and the ZZIP_FILE wraps a real file.
  40. */
  41. ZZIP_DIR *
  42. zzip_dirhandle(ZZIP_FILE * fp)
  43. {
  44. return fp->dir;
  45. }
  46. /** => zzip_dirhandle
  47. * This function will just return dir->fd
  48. *
  49. * If a ZZIP_DIR does point to a zipfile then the file-descriptor of that
  50. * zipfile is returned, otherwise a NULL is returned and the ZZIP_DIR wraps
  51. * a real directory DIR (if you have dirent on your system).
  52. */
  53. int
  54. zzip_dirfd(ZZIP_DIR * dir)
  55. {
  56. return dir->fd;
  57. }
  58. /**
  59. * return static const string of the known compression methods,
  60. * otherwise just "zipped" is returned
  61. */
  62. zzip_char_t *
  63. zzip_compr_str(int compr)
  64. {
  65. switch (compr)
  66. {
  67. /* *INDENT-OFF* */
  68. case ZZIP_IS_STORED: return "stored";
  69. case ZZIP_IS_SHRUNK: return "shrunk";
  70. case ZZIP_IS_REDUCEDx1:
  71. case ZZIP_IS_REDUCEDx2:
  72. case ZZIP_IS_REDUCEDx3:
  73. case ZZIP_IS_REDUCEDx4: return "reduced";
  74. case ZZIP_IS_IMPLODED: return "imploded";
  75. case ZZIP_IS_TOKENIZED: return "tokenized";
  76. case ZZIP_IS_DEFLATED: return "deflated";
  77. case ZZIP_IS_DEFLATED_BETTER: return "deflatedX";
  78. case ZZIP_IS_IMPLODED_BETTER: return "implodedX";
  79. default:
  80. if (0 < compr && compr < 256) return "zipped";
  81. else
  82. {
  83. # ifdef S_ISDIR
  84. if (S_ISDIR(compr)) return "directory";
  85. # endif
  86. # ifdef S_ISCHR
  87. if (S_ISCHR(compr)) return "is/chr";
  88. # endif
  89. # ifdef S_ISBLK
  90. if (S_ISBLK(compr)) return "is/blk";
  91. # endif
  92. # ifdef S_ISFIFO
  93. if (S_ISFIFO(compr)) return "is/fifo";
  94. # endif
  95. # ifdef S_ISSOCK
  96. if (S_ISSOCK(compr)) return "is/sock";
  97. # endif
  98. # ifdef S_ISLNK
  99. if (S_ISLNK(compr)) return "is/lnk";
  100. # endif
  101. return "special";
  102. }
  103. /* *INDENT-ON* */
  104. } /*switch */
  105. }
  106. /** => zzip_file_real
  107. * This function checks if the ZZIP_DIR-handle is wrapping
  108. * a real directory or a zip-archive.
  109. * Returns 1 for a stat'able directory, and 0 for a handle to zip-archive.
  110. */
  111. int
  112. zzip_dir_real(ZZIP_DIR * dir)
  113. {
  114. return dir->realdir != 0;
  115. }
  116. /**
  117. * This function checks if the ZZIP_FILE-handle is wrapping
  118. * a real file or a zip-contained file.
  119. * Returns 1 for a stat'able file, and 0 for a file inside a zip-archive.
  120. */
  121. int
  122. zzip_file_real(ZZIP_FILE * fp)
  123. {
  124. return fp->dir == 0; /* ie. not dependent on a zip-arch-dir */
  125. }
  126. /** => zzip_file_real
  127. * This function returns the posix DIR* handle (if one exists).
  128. * Check before with => zzip_dir_real if the
  129. * the ZZIP_DIR points to a real directory.
  130. */
  131. void *
  132. zzip_realdir(ZZIP_DIR * dir)
  133. {
  134. return dir->realdir;
  135. }
  136. /** => zzip_file_real
  137. * This function returns the posix file descriptor (if one exists).
  138. * Check before with => zzip_file_real if the
  139. * the ZZIP_FILE points to a real file.
  140. */
  141. int
  142. zzip_realfd(ZZIP_FILE * fp)
  143. {
  144. return fp->fd;
  145. }
  146. /*
  147. * Local variables:
  148. * c-file-style: "stroustrup"
  149. * End:
  150. */