]> granicus.if.org Git - zziplib/blob - zzip/plugin.c
using mksite.sh for doc build
[zziplib] / zzip / plugin.c
1 /*
2  * Author: 
3  *      Guido Draheim <guidod@gmx.de>
4  *      Mike Nordell <tamlin@algonet.se>
5  *
6  * Copyright (c) 2002,2003 Guido Draheim
7  *          All rights reserved,
8  *          use under the restrictions of the
9  *          Lesser GNU General Public License
10  *          or alternatively the restrictions 
11  *          of the Mozilla Public License 1.1
12  */
13
14 #include <zzip/lib.h>
15 #include <zzip/plugin.h>
16
17 #include <string.h>
18 #include <sys/stat.h>
19 #include <errno.h>
20 #include <stdlib.h>
21 #ifdef DEBUG
22 #include <stdio.h>
23 #endif
24
25 #include <zzip/file.h>
26 #include <zzip/format.h>
27
28 zzip_off_t
29 zzip_filesize(int fd)
30 {
31   struct stat st;
32
33   if (fstat(fd, &st) < 0)
34     return -1;
35
36 # if defined DEBUG && ! defined _WIN32
37   if (! st.st_size && st.st_blocks > 1) /* seen on some darwin 10.1 machines */
38       fprintf(stderr, "broken fstat(2) ?? st_size=%ld st_blocks=%ld\n", 
39               (long) st.st_size, (long) st.st_blocks);
40 # endif
41
42   return st.st_size;
43 }
44
45 static const struct zzip_plugin_io default_io =
46 {
47     &open,
48     &close,
49     &_zzip_read,
50     &_zzip_lseek,
51     &zzip_filesize,
52     1, 1,
53     &_zzip_write
54 };
55
56 /** => zzip_init_io
57  * This function returns a zzip_plugin_io_t handle to static defaults
58  * wrapping the posix io file functions for actual file access.
59  */
60 zzip_plugin_io_t
61 zzip_get_default_io()
62 {
63     return (zzip_plugin_io_t) &default_io;
64 }
65
66 /**
67  * This function initializes the users handler struct to default values 
68  * being the posix io functions in default configured environments.
69  */
70 int zzip_init_io(zzip_plugin_io_handlers_t io, int flags)
71 {
72     if (!io) {
73         return ZZIP_ERROR;
74     }
75     memcpy(io, &default_io, sizeof(default_io));
76     io->fd.sys = flags;
77     return 0;
78 }
79
80 /* 
81  * Local variables:
82  * c-file-style: "stroustrup"
83  * End:
84  */