summaryrefslogtreecommitdiff
path: root/Build/source/libs/zziplib/zziplib-src/zzip/info.c
blob: 4b7e941b8e7aba71321ba7e5f220fdddab247e47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151

/*
 * Author:
 *      Guido Draheim <guidod@gmx.de>
 *
 * Copyright (c) Guido Draheim, use under copyleft (LGPL,MPL)
 */

#include <zzip/lib.h>           /* exported... */
#include <zzip/file.h>
#include <zzip/format.h>

#ifdef ZZIP_HAVE_SYS_STAT_H
#include <sys/stat.h>
#else
#include <stdlib.h>
#include <stdio.h>
#endif

/** get errror status.
 *  This function just returns dir->errcode of the ZZIP_DIR handle
 *  see: => zzip_dir_open, => zzip_dir_open, => zzip_readdir, => zzip_dir_read
 */
int
zzip_error(ZZIP_DIR * dir)
{
    return dir->errcode;
}

/** => zzip_error
 *  This function just does dir->errcode = errcode
 */
void
zzip_seterror(ZZIP_DIR * dir, int errcode) { dir->errcode = errcode; }

/** get handle.
 * This function will just return the fp->dir value.
 *
 * If a ZZIP_FILE is contained within a zip-file that one will be a valid
 * pointer, otherwise a NULL is returned and the ZZIP_FILE wraps a real file.
 */
ZZIP_DIR *
zzip_dirhandle(ZZIP_FILE * fp)
{
    return fp->dir;
}

/** => zzip_dirhandle
 *  This function will just return dir->fd
 *
 * If a ZZIP_DIR does point to a zipfile then the file-descriptor of that
 * zipfile is returned, otherwise a NULL is returned and the ZZIP_DIR wraps
 * a real directory DIR (if you have dirent on your system).
 */
int
zzip_dirfd(ZZIP_DIR * dir)
{
    return dir->fd;
}

#define LENGTH(x) (sizeof(x) / sizeof(*x))
static const char* comprlevel[] = {
    "stored",   "shrunk",   "redu:1",   "redu:2",   "redu:3",   "redu:4",
    "impl:N",   "toknze",   "defl:N",   "defl:B",   "impl:B" };

/** compr name.
 * This function returns the static const string of the known compression methods,
 * Unknown id values will return just "zipped" as the string code.
 */
zzip_char_t *
zzip_compr_str(int compr)
{
    if (0 <= compr && (unsigned) compr < LENGTH(comprlevel))
    {
        return comprlevel[compr];
    } else if (0 < compr && compr < 256) 
    {
        return "zipped";
    } else
    {
#	ifdef S_ISDIR
        if (S_ISDIR(compr))		return "directory";
#	endif
#	ifdef S_ISCHR
        if (S_ISCHR(compr))		return "is/chr";
#	endif
#	ifdef S_ISBLK
        if (S_ISBLK(compr))		return "is/blk";
#	endif
#	ifdef S_ISFIFO
        if (S_ISFIFO(compr))	return "is/fifo";
#	endif
#	ifdef S_ISSOCK
        if (S_ISSOCK(compr))	return "is/sock";
#	endif
#	ifdef S_ISLNK
        if (S_ISLNK(compr))		return "is/lnk";
#	endif
        return "special";
    }
}

/** => zzip_file_real
 * This function checks if the ZZIP_DIR-handle is wrapping
 * a real directory or a zip-archive.
 * Returns 1 for a stat'able directory, and 0 for a handle to zip-archive.
 */
int
zzip_dir_real(ZZIP_DIR * dir)
{
    return dir->realdir != 0;
}

/** check real or zipped file.
 * This function checks if the ZZIP_FILE-handle is wrapping
 * a real file or a zip-contained file.
 * Returns 1 for a stat'able file, and 0 for a file inside a zip-archive.
 */
int
zzip_file_real(ZZIP_FILE * fp)
{
    return fp->dir == 0;        /* ie. not dependent on a zip-arch-dir  */
}

/** => zzip_file_real
 * This function returns the posix DIR* handle (if one exists).
 * Check before with => zzip_dir_real if the
 * the ZZIP_DIR points to a real directory.
 */
void *
zzip_realdir(ZZIP_DIR * dir)
{
    return dir->realdir;
}

/** => zzip_file_real
 * This function returns the posix file descriptor (if one exists).
 * Check before with => zzip_file_real if the
 * the ZZIP_FILE points to a real file.
 */
int
zzip_realfd(ZZIP_FILE * fp)
{
    return fp->fd;
}

/*
 * Local variables:
 * c-file-style: "stroustrup"
 * End:
 */