~vcs-imports/clamav/main-old

« back to all changes in this revision

Viewing changes to libclamav/zziplib/zzip-info.c

  • Committer: nervoso
  • Date: 2006-05-21 15:16:39 UTC
  • Revision ID: Arch-1:clamav@arch.ubuntu.com%clamav--MAIN--0--patch-1959
repository moved to cvs.clamav.net

Show diffs side-by-side

added added

removed removed

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