PageRenderTime 13ms CodeModel.GetById 2ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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