Blame src/funopen.c

Packit 3c2767
/* funopen.c - Replacement for funopen.
Packit 3c2767
 * Copyright (C) 2003, 2005 Free Software Foundation, Inc.
Packit 3c2767
 *
Packit 3c2767
 * This file is part of Assuan.
Packit 3c2767
 *
Packit 3c2767
 * Assuan is free software; you can redistribute it and/or modify it
Packit 3c2767
 * under the terms of the GNU Lesser General Public License as
Packit 3c2767
 * published by the Free Software Foundation; either version 2.1 of
Packit 3c2767
 * the License, or (at your option) any later version.
Packit 3c2767
 *
Packit 3c2767
 * Assuan is distributed in the hope that it will be useful, but
Packit 3c2767
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 3c2767
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 3c2767
 * Lesser General Public License for more details.
Packit 3c2767
 *
Packit 3c2767
 * You should have received a copy of the GNU Lesser General Public
Packit 3c2767
 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
Packit 3c2767
 * SPDX-License-Identifier: LGPL-2.1+
Packit 3c2767
 */
Packit 3c2767
Packit 3c2767
#ifdef HAVE_CONFIG_H
Packit 3c2767
#include <config.h>
Packit 3c2767
#endif
Packit 3c2767
Packit 3c2767
#include <stdio.h>
Packit 3c2767
Packit 3c2767
Packit 3c2767
/* Replacement for the *BSD function:
Packit 3c2767
Packit 3c2767
  FILE *funopen (void *cookie,
Packit 3c2767
                 int (*readfn)(void *, char *, int),
Packit 3c2767
                 int (*writefn)(void *, const char *, int),
Packit 3c2767
                 fpos_t (*seekfn)(void *, fpos_t, int),
Packit 3c2767
                 int (*closefn)(void *));
Packit 3c2767
Packit 3c2767
  The functions to provide my either be NULL if not required or
Packit 3c2767
  similar to the unistd function with the exception of using the
Packit 3c2767
  cookie instead of the file descriptor.
Packit 3c2767
*/
Packit 3c2767
Packit 3c2767
Packit 3c2767
#ifdef HAVE_FOPENCOOKIE
Packit 3c2767
FILE *
Packit 3c2767
_assuan_funopen(void *cookie,
Packit 3c2767
                cookie_read_function_t *readfn,
Packit 3c2767
                cookie_write_function_t *writefn,
Packit 3c2767
                cookie_seek_function_t *seekfn,
Packit 3c2767
                cookie_close_function_t *closefn)
Packit 3c2767
{
Packit 3c2767
  cookie_io_functions_t io;
Packit 3c2767
Packit 3c2767
  io.read = readfn;
Packit 3c2767
  io.write = writefn;
Packit 3c2767
  io.seek = seekfn;
Packit 3c2767
  io.close = closefn;
Packit 3c2767
Packit 3c2767
  return fopencookie (cookie,
Packit 3c2767
		      readfn ? ( writefn ? "rw" : "r" )
Packit 3c2767
		      : ( writefn ? "w" : ""), io);
Packit 3c2767
}
Packit 3c2767
#else
Packit 3c2767
#error No known way to implement funopen.
Packit 3c2767
#endif