File: info.c

package info (click to toggle)
zziplib 0.13.56-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,760 kB
  • ctags: 2,135
  • sloc: sh: 12,147; ansic: 7,392; perl: 2,826; python: 2,190; makefile: 968; sed: 44
file content (163 lines) | stat: -rw-r--r-- 3,934 bytes parent folder | download | duplicates (4)
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
152
153
154
155
156
157
158
159
160
161
162
163

/*
 * Author: 
 *      Guido Draheim <guidod@gmx.de>
 *
 * Copyright (c) 2000,2001,2002,2003 Guido Draheim
 *          All rights reserved,
 *          use under the restrictions of the
 *          Lesser GNU General Public License
 *          or alternatively the restrictions 
 *          of the Mozilla Public License 1.1
 */

#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

/** 
 *  just returns dir->errcode of the ZZIP_DIR handle 
 *  see: => zzip_dir_open, => zzip_diropen, => 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; }

/** 
 * This function will just return fp->dir 
 *
 * 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;
}

/**
 * return static const string of the known compression methods, 
 * otherwise just "zipped" is returned
 */
zzip_char_t *
zzip_compr_str(int compr)
{
    switch (compr)
    {
	/* *INDENT-OFF* */
    case ZZIP_IS_STORED:		return "stored";
    case ZZIP_IS_SHRUNK:		return "shrunk";
    case ZZIP_IS_REDUCEDx1:
    case ZZIP_IS_REDUCEDx2:
    case ZZIP_IS_REDUCEDx3:
    case ZZIP_IS_REDUCEDx4:		return "reduced";
    case ZZIP_IS_IMPLODED:		return "imploded";
    case ZZIP_IS_TOKENIZED:		return "tokenized";
    case ZZIP_IS_DEFLATED:		return "deflated";
    case ZZIP_IS_DEFLATED_BETTER:	return "deflatedX";
    case ZZIP_IS_IMPLODED_BETTER:	return "implodedX";
    default:
        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";
        }
	/* *INDENT-ON* */
    }                           /*switch */
}

/** => 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;
}

/**
 * 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:
 */