dlgTextEntry_Keyboard: rename to TouchTextEntry
[xcsoar.git] / src / zzip / stat.c
blob4b55dea6b7b1be90b58adebe760ab77dfdfb5123
2 /*
3 * Author:
4 * Guido Draheim <guidod@gmx.de>
5 * Tomi Ollila <Tomi.Ollila@iki.fi>
7 * Copyright (c) 1999,2000,2001,2002 Guido Draheim
8 * All rights reserved,
9 * use under the restrictions of the
10 * Lesser GNU General Public License
11 * or alternatively the restrictions
12 * of the Mozilla Public License 1.1
14 * Description:
15 * although this file is defining a function called zzip_stat it
16 * will not need a real stat(2) exported by the Operating System.
17 * It will just try to fill the fields of the ZZIP_STAT structure
18 * of
21 #include <zzip/lib.h> /* exported... */
22 #include <zzip/file.h>
23 #include <string.h>
24 #if defined(_AIX)
25 #include <strings.h> /* for strcasecmp */
26 #endif
27 #include <sys/stat.h>
29 #define ZZIP_USE_INTERNAL
30 #include <zzip/info.h>
32 /**
33 * obtain information about a filename in an opened zip-archive without
34 * opening that file first. Mostly used to obtain the uncompressed
35 * size of a file inside a zip-archive. see => zzip_dir_open.
37 int
38 zzip_dir_stat(ZZIP_DIR * dir, zzip_char_t * name, ZZIP_STAT * zs, int flags)
40 struct zzip_dir_hdr *hdr = dir->hdr0;
41 int (*cmp) (zzip_char_t *, zzip_char_t *);
43 if (flags & ZZIP_CASEINSENSITIVE) flags |= ZZIP_CASELESS;
44 cmp = (flags & ZZIP_CASELESS) ? strcasecmp : strcmp;
46 if (! hdr)
48 #ifdef ZZIP_DISABLED
49 dir->errcode = ZZIP_ENOENT;
50 #endif /* ZZIP_DISABLED */
51 return -1;
54 if (flags & ZZIP_IGNOREPATH)
56 char *n = strrchr((const char *)name, '/');
57 if (n)
58 name = n + 1;
61 while (1)
63 register char *hdr_name = hdr->d_name;
64 if (flags & ZZIP_IGNOREPATH)
66 register char *n = strrchr(hdr_name, '/');
67 if (n)
68 hdr_name = n + 1;
71 if (! cmp(hdr_name, name))
72 break;
74 if (! hdr->d_reclen)
76 #ifdef ZZIP_DISABLED
77 dir->errcode = ZZIP_ENOENT;
78 #endif /* ZZIP_DISABLED */
79 return -1;
82 hdr = (struct zzip_dir_hdr *) ((char *) hdr + hdr->d_reclen);
85 zs->d_compr = hdr->d_compr;
86 zs->d_csize = hdr->d_csize;
87 zs->st_size = hdr->d_usize;
88 zs->d_name = hdr->d_name;
90 return 0;
93 /** => zzip_dir_stat
94 * This function will obtain information about a opened file _within_ a
95 * zip-archive. The file is supposed to be open (otherwise -1 is returned).
96 * The st_size stat-member contains the uncompressed size. The optional
97 * d_name is never set here.
99 int
100 zzip_file_stat(ZZIP_FILE * file, ZZIP_STAT * zs)
102 if (! file)
103 return -1;
104 zs->d_compr = file->method;
105 zs->d_csize = file->csize;
106 zs->st_size = file->usize;
107 zs->d_name = 0;
108 return 0;
111 /** => zzip_dir_stat
112 * This function will obtain information about a opened file which may be
113 * either real/zipped. The file is supposed to be open (otherwise -1 is
114 * returned). The st_size stat-member contains the uncompressed size.
115 * The optional d_name is never set here. For a real file, we do set the
116 * d_csize := st_size and d_compr := 0 for meaningful defaults.
119 zzip_fstat(ZZIP_FILE * file, ZZIP_STAT * zs)
121 if (ZZIP_file_real(file))
123 struct stat st;
124 if (fstat(file->fd, &st) < 0)
125 return -1;
126 zs->st_size = st.st_size;
127 zs->d_csize = st.st_size;
128 zs->d_compr = 0;
129 return 0;
130 } else
132 return zzip_file_stat(file, zs);
137 * Local variables:
138 * c-file-style: "stroustrup"
139 * End: