]> granicus.if.org Git - zziplib/blob - zzip/info.c
remove msvc6 warnings about difference of signedness of pointer target types
[zziplib] / zzip / info.c
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
13 #include <zzip/lib.h>                                   /* exported... */
14 #include <zzip/file.h>
15 #include <zzip/format.h>
16
17 #ifdef ZZIP_HAVE_SYS_STAT_H
18 #include <sys/stat.h>
19 #else
20 #include <stdlib.h>
21 #include <stdio.h>
22 #endif
23
24 /** 
25  *  just returns dir->errcode of the ZZIP_DIR handle 
26  *  see: => zzip_dir_open, => zzip_diropen, => zzip_readdir, => zzip_dir_read
27  */
28 int 
29 zzip_error(ZZIP_DIR * dir)   
30 {   
31     return dir->errcode; 
32 }
33
34 /** => zzip_error
35  *  This function just does dir->errcode = errcode 
36  */
37 void 
38 zzip_seterror(ZZIP_DIR * dir, int errcode)   
39 { 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  */
47 ZZIP_DIR * 
48 zzip_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  */
60 int 
61 zzip_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  */
70 zzip_char_t*
71 zzip_compr_str(int compr)
72 {
73     switch(compr)
74     {
75     case ZZIP_IS_STORED:                return "stored";
76     case ZZIP_IS_SHRUNK:                return "shrunk";
77     case ZZIP_IS_REDUCEDx1:
78     case ZZIP_IS_REDUCEDx2:
79     case ZZIP_IS_REDUCEDx3:
80     case ZZIP_IS_REDUCEDx4:             return "reduced";
81     case ZZIP_IS_IMPLODED:              return "imploded";
82     case ZZIP_IS_TOKENIZED:             return "tokenized";
83     case ZZIP_IS_DEFLATED:              return "deflated";
84     case ZZIP_IS_DEFLATED_BETTER:       return "deflatedX";
85     case ZZIP_IS_IMPLODED_BETTER:       return "implodedX";
86     default:
87         if (0 < compr && compr < 256)   return "zipped"; 
88         else
89         {
90 #       ifdef S_ISDIR
91             if (S_ISDIR(compr))         return "directory";
92 #       endif
93 #       ifdef S_ISCHR
94             if (S_ISCHR(compr))         return "is/chr";
95 #       endif
96 #       ifdef S_ISBLK
97             if (S_ISBLK(compr))         return "is/blk";
98 #       endif
99 #       ifdef S_ISFIFO
100             if (S_ISFIFO(compr))        return "is/fifo";
101 #       endif
102 #       ifdef S_ISSOCK
103             if (S_ISSOCK(compr))        return "is/sock";
104 #       endif
105 #       ifdef S_ISLNK
106             if (S_ISLNK(compr))         return "is/lnk";
107 #       endif
108             return "special";
109         }
110     }/*switch*/
111 }
112
113 /** => zzip_file_real
114  * This function checks if the ZZIP_DIR-handle is wrapping 
115  * a real directory or a zip-archive. 
116  * Returns 1 for a stat'able directory, and 0 for a handle to zip-archive.
117  */ 
118 int
119 zzip_dir_real(ZZIP_DIR* dir)
120 {
121     return dir->realdir != 0;
122 }
123
124 /**
125  * This function checks if the ZZIP_FILE-handle is wrapping 
126  * a real file or a zip-contained file. 
127  * Returns 1 for a stat'able file, and 0 for a file inside a zip-archive.
128  */
129 int
130 zzip_file_real(ZZIP_FILE* fp)
131 {
132     return fp->dir == 0; /* ie. not dependent on a zip-arch-dir  */
133 }
134
135 /** => zzip_file_real
136  * This function returns the posix DIR* handle (if one exists).
137  * Check before with => zzip_dir_real if the
138  * the ZZIP_DIR points to a real directory.
139  */
140 void*
141 zzip_realdir(ZZIP_DIR* dir)
142 {
143     return dir->realdir;
144 }
145
146 /** => zzip_file_real
147  * This function returns the posix file descriptor (if one exists).
148  * Check before with => zzip_file_real if the
149  * the ZZIP_FILE points to a real file.
150  */
151 int
152 zzip_realfd(ZZIP_FILE* fp)
153 {
154     return fp->fd;
155 }
156
157 /* 
158  * Local variables:
159  * c-file-style: "stroustrup"
160  * End:
161  */