Line data Source code
1 : /* funopen.c - Replacement for funopen.
2 : Copyright (C) 2004 g10 Code GmbH
3 :
4 : This file is part of GPGME
5 :
6 : GPGME is free software; you can redistribute it and/or modify it
7 : under the terms of the GNU Lesser General Public License as
8 : published by the Free Software Foundation; either version 2.1 of
9 : the License, or (at your option) any later version.
10 :
11 : GPGME is distributed in the hope that it will be useful, but
12 : WITHOUT ANY WARRANTY; without even the implied warranty of
13 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : Lesser General Public License for more details.
15 :
16 : You should have received a copy of the GNU Lesser General Public
17 : License along with this program; if not, write to the Free Software
18 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 : 02111-1307, USA. */
20 :
21 : #ifdef HAVE_CONFIG_H
22 : #include <config.h>
23 : #endif
24 :
25 : #include <stdio.h>
26 :
27 :
28 : /* Replacement for the *BSD function:
29 :
30 : FILE *funopen (void *cookie,
31 : int (*readfn)(void *, char *, int),
32 : int (*writefn)(void *, const char *, int),
33 : fpos_t (*seekfn)(void *, fpos_t, int),
34 : int (*closefn)(void *));
35 :
36 : The functions to provide my either be NULL if not required or
37 : similar to the unistd function with the exception of using the
38 : cookie instead of the file descriptor.
39 : */
40 :
41 :
42 : #ifdef HAVE_FOPENCOOKIE
43 : FILE *
44 0 : _gpgme_funopen(void *cookie,
45 : cookie_read_function_t *readfn,
46 : cookie_write_function_t *writefn,
47 : cookie_seek_function_t *seekfn,
48 : cookie_close_function_t *closefn)
49 : {
50 0 : cookie_io_functions_t io = { NULL };
51 :
52 0 : io.read = readfn;
53 0 : io.write = writefn;
54 0 : io.seek = seekfn;
55 0 : io.close = closefn;
56 :
57 0 : return fopencookie (cookie,
58 : readfn ? ( writefn ? "rw" : "r" )
59 0 : : ( writefn ? "w" : ""), io);
60 : }
61 : #else
62 : #error No known way to implement funopen.
63 : #endif
|