~vcs-imports/clamav/main-old

« back to all changes in this revision

Viewing changes to libclamav/zziplib/zzip-io.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
 
 *      Mike Nordell <tamlin@algonet.se>
5
 
 *
6
 
 *      Copyright (c) 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
 
 
14
 
#if HAVE_CONFIG_H
15
 
#include "clamav-config.h"
16
 
#endif
17
 
 
18
 
#include <zzip.h>
19
 
#include <zzip-io.h>
20
 
 
21
 
#include <string.h>
22
 
#include <sys/types.h>  /* njh@bandsman.co.uk: for icc7.0 */
23
 
#include <sys/stat.h>
24
 
#include <errno.h>
25
 
#include <stdlib.h>
26
 
#ifdef DEBUG
27
 
#include <stdio.h>
28
 
#endif
29
 
 
30
 
#include <zzip-file.h>
31
 
#include <zzipformat.h>
32
 
 
33
 
zzip_off_t
34
 
zzip_filesize(int fd)
35
 
{
36
 
  struct stat st;
37
 
 
38
 
  if (fstat(fd, &st) < 0)
39
 
    return -1;
40
 
 
41
 
# ifdef DEBUG 
42
 
  if (! st.st_size && st.st_blocks > 1) /* seen on some darwin 10.1 machines */
43
 
      fprintf(stderr, "broken fstat(2) ?? st_size=%ld st_blocks=%ld\n", 
44
 
              (long) st.st_size, (long) st.st_blocks);
45
 
# endif
46
 
 
47
 
  return st.st_size;
48
 
}
49
 
 
50
 
#if defined ZZIP_WRAPWRAP
51
 
int             zzip_wrap_read(int fd, void* p, unsigned int len)
52
 
                                { return _zzip_read (fd, p, len); }
53
 
zzip_off_t      zzip_wrap_lseek(int fd, zzip_off_t offset, int whence)
54
 
                                { return _zzip_lseek (fd, offset, whence); }
55
 
#else
56
 
#define zzip_wrap_read  _zzip_read
57
 
#define zzip_wrap_lseek _zzip_lseek
58
 
#endif
59
 
 
60
 
static const struct zzip_plugin_io default_io =
61
 
{
62
 
    &open,
63
 
    &close,
64
 
    (int (*)(int, void*, unsigned)) &zzip_wrap_read,
65
 
    (zzip_off_t (*)(int, zzip_off_t, int)) &zzip_wrap_lseek,
66
 
    (zzip_off_t (*)(int)) &zzip_filesize,
67
 
    1
68
 
};
69
 
 
70
 
/** => zzip_init_io
71
 
 * This function returns a zzip_plugin_io_t handle to static defaults
72
 
 * wrapping the posix io file functions for actual file access.
73
 
 */
74
 
zzip_plugin_io_t
75
 
zzip_get_default_io()
76
 
{
77
 
    return &default_io;
78
 
}
79
 
 
80
 
/**
81
 
 * This function initializes the users handler struct to default values 
82
 
 * being the posix io functions in default configured environments.
83
 
 */
84
 
int zzip_init_io(struct zzip_plugin_io* io, int flags)
85
 
{
86
 
    if (!io) {
87
 
        return ZZIP_ERROR;
88
 
    }
89
 
    memcpy(io, &default_io, sizeof(default_io));
90
 
    io->use_mmap = flags;
91
 
    return 0;
92
 
}
93
 
 
94
 
/* 
95
 
 * Local variables:
96
 
 * c-file-style: "stroustrup"
97
 
 * End:
98
 
 */