3 * - portability routines
6 * This file is part of secnet.
7 * See README for full list of copyright holders.
9 * secnet is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * secnet is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * version 3 along with secnet; if not, see
21 * https://www.gnu.org/licenses/gpl.html.
32 struct fmemopen_state {
37 static int fmemopen_readfn(void *sst, char *out, int sz)
39 struct fmemopen_state *st=sst;
41 int now=MIN((size_t)sz,st->remain);
42 memcpy(out,st->bufp,now);
46 static int fmemopen_close(void *sst) { free(sst); return 0; }
48 FILE *fmemopen(void *buf, size_t size, const char *mode)
50 /* this is just a fake plastic imitation */
51 assert(!strcmp(mode,"r"));
52 struct fmemopen_state *st;
56 FILE *f=funopen(st,fmemopen_readfn,0,0,fmemopen_close);
61 # else /* HAVE_FUNOPEN */
62 # error no fmemopen, no funopen, cannot proceed
65 #endif /* HAVE_FMEMOPEN */