~vcs-imports/clamav/main-old

« back to all changes in this revision

Viewing changes to libclamav/zziplib/zzip-stat.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
 
 *      Tomi Ollila <Tomi.Ollila@iki.fi>
5
 
 *
6
 
 *      Copyright (c) 1999,2000,2001,2002 Guido Draheim
7
 
 *          All rights reserved,
8
 
 *          use under the restrictions of the
9
 
 *          Lesser GNU General Public License
10
 
 *          note the additional license information 
11
 
 *          that can be found in COPYING.ZZIP
12
 
 *
13
 
 * Description:
14
 
 *      although this file is defining a function called zzip_stat it
15
 
 *      will not need a real stat(2) exported by the Operating System.
16
 
 *      It will just try to fill the fields of the ZZIP_STAT structure
17
 
 *      of 
18
 
 */
19
 
 
20
 
#if HAVE_CONFIG_H
21
 
#include "clamav-config.h"
22
 
#endif
23
 
 
24
 
#include <zzip.h>                                   /* exported...*/
25
 
#include <string.h>
26
 
 
27
 
#include "strc.h"
28
 
 
29
 
/**
30
 
 * obtain information about a filename in an opened zip-archive without 
31
 
 * opening that file first. Mostly used to obtain the uncompressed 
32
 
 * size of a file inside a zip-archive. see => zzip_dir_open.
33
 
 */
34
 
int 
35
 
zzip_dir_stat(ZZIP_DIR * dir, zzip_char_t* name, ZZIP_STAT * zs, int flags)
36
 
{
37
 
    struct zzip_dir_hdr * hdr = dir->hdr0;
38
 
    int (*cmp)(zzip_char_t*, zzip_char_t*);
39
 
 
40
 
    cmp = (flags & ZZIP_CASEINSENSITIVE) ? strcasecmp : strcmp;
41
 
 
42
 
    if (flags & ZZIP_IGNOREPATH)
43
 
    {
44
 
        char* n = strrchr(name, '/');
45
 
        if (n)  name = n + 1;
46
 
    }
47
 
 
48
 
    if (hdr)
49
 
    while (1)
50
 
    {
51
 
        register char* hdr_name = hdr->d_name;
52
 
        if (flags & ZZIP_IGNOREPATH)
53
 
        {
54
 
            register char* n = strrchr(hdr_name, '/');
55
 
            if (n)  hdr_name = n + 1;
56
 
        }
57
 
 
58
 
        if (! cmp(hdr_name, name))
59
 
            break;
60
 
 
61
 
        if (! hdr->d_reclen)
62
 
        {
63
 
            dir->errcode = ZZIP_ENOENT;
64
 
            return -1;
65
 
        }
66
 
 
67
 
        hdr = (struct zzip_dir_hdr *) ((char *)hdr + hdr->d_reclen);
68
 
    }
69
 
 
70
 
    zs->d_compr = hdr->d_compr;
71
 
    zs->d_csize = hdr->d_csize;
72
 
    zs->st_size = hdr->d_usize;
73
 
    zs->d_name  = hdr->d_name;
74
 
 
75
 
    return 0;
76
 
}
77
 
 
78
 
/* 
79
 
 * Local variables:
80
 
 * c-file-style: "stroustrup"
81
 
 * End:
82
 
 */