PageRenderTime 22ms CodeModel.GetById 12ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/zziplib/zzip/plugin.c

https://bitbucket.org/cabalistic/ogredeps/
C | 90 lines | 49 code | 12 blank | 29 comment | 6 complexity | f9b1678285179b27e7bdb630bae296e5 MD5 | raw file
 1
 2/*
 3 * Author: 
 4 *	Guido Draheim <guidod@gmx.de>
 5 *      Mike Nordell <tamlin-@-algonet-se>
 6 *
 7 * Copyright (c) 2002,2003 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
13 */
14
15#include <zzip/lib.h>
16#include <zzip/plugin.h>
17
18#include <string.h>
19#include <sys/stat.h>
20#include <errno.h>
21#include <stdlib.h>
22#ifdef DEBUG
23#include <stdio.h>
24#endif
25
26#include <zzip/file.h>
27#include <zzip/format.h>
28
29zzip_off_t
30zzip_filesize(int fd)
31{
32    struct stat st;
33
34    if (fstat(fd, &st) < 0)
35        return -1;
36
37# if defined DEBUG && ! defined _WIN32
38    if (! st.st_size && st.st_blocks > 1)        /* seen on some darwin 10.1 machines */
39        fprintf(stderr, "broken fstat(2) ?? st_size=%ld st_blocks=%ld\n",
40                (long) st.st_size, (long) st.st_blocks);
41# endif
42
43    return st.st_size;
44}
45
46static const struct zzip_plugin_io default_io = {
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. The
59 * returned structure is shared by all threads in the system.
60 */
61zzip_plugin_io_t
62zzip_get_default_io(void)
63{
64    return (zzip_plugin_io_t) & default_io;
65}
66
67/**
68 * This function initializes the users handler struct to default values 
69 * being the posix io functions in default configured environments.
70 *
71 * Note that the target io_handlers_t structure should be static or 
72 * atleast it should be kept during the lifetime of zzip operations.
73 */
74int
75zzip_init_io(zzip_plugin_io_handlers_t io, int flags)
76{
77    if (! io)
78    {
79        return ZZIP_ERROR;
80    }
81    memcpy(io, &default_io, sizeof(default_io));
82    io->fd.sys = flags;
83    return 0;
84}
85
86/* 
87 * Local variables:
88 * c-file-style: "stroustrup"
89 * End:
90 */