repair arguments (add const)
[unix-history] / usr / src / lib / libc / stdio / funopen.c
CommitLineData
c9be6cfe
KB
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * %sccs.include.redist.c%
9 */
10
11#if defined(LIBC_SCCS) && !defined(lint)
d25ccb19 12static char sccsid[] = "@(#)funopen.c 5.2 (Berkeley) %G%";
c9be6cfe
KB
13#endif /* LIBC_SCCS and not lint */
14
15#include <stdio.h>
16#include <errno.h>
17#include "local.h"
18
19FILE *
20funopen(cookie, readfn, writefn, seekfn, closefn)
d25ccb19 21 const void *cookie;
c9be6cfe
KB
22 int (*readfn)(), (*writefn)();
23#if __STDC__
d25ccb19 24 fpos_t (*seekfn)(void *cookie, fpos_t off, int whence);
c9be6cfe
KB
25#else
26 fpos_t (*seekfn)();
27#endif
28 int (*closefn)();
29{
30 register FILE *fp;
31 int flags;
32
33 if (readfn == NULL) {
34 if (writefn == NULL) { /* illegal */
35 errno = EINVAL;
36 return (NULL);
37 } else
38 flags = __SWR; /* write only */
39 } else {
40 if (writefn == NULL)
41 flags = __SRD; /* read only */
42 else
43 flags = __SRW; /* read-write */
44 }
45 if ((fp = __sfp()) == NULL)
46 return (NULL);
47 fp->_flags = flags;
48 fp->_file = -1;
d25ccb19 49 fp->_cookie = (void *)cookie;
c9be6cfe
KB
50 fp->_read = readfn;
51 fp->_write = writefn;
52 fp->_seek = seekfn;
53 fp->_close = closefn;
54 return (fp);
55}