Mac Developer Library Developer


This manual page is part of Xcode Tools version 5.0

To obtain these tools:

If you are running a version of Xcode Tools other than 5.0, view the documentation locally:

  • In Xcode

  • In Terminal, using the man(1) command

Reading manual pages

Manual pages are intended as a quick reference for people who already understand a technology.

  • To learn how the manual is organized or to learn about command syntax, read the manual page for manpages(5).

  • For more information about this technology, look for other documentation in the Apple Developer Library.

  • For general information about writing shell scripts, read Shell Scripting Primer.

FUNOPEN(3)               BSD Library Functions Manual               FUNOPEN(3)

     funopen, fropen, fwopen -- open a stream

     Standard C Library (libc, -lc)

     #include <stdio.h>

     FILE *
     funopen(const void *cookie, int (*readfn)(void *, char *, int),
         int (*writefn)(void *, const char *, int), fpos_t (*seekfn)(void *, fpos_t, int),
         int (*closefn)(void *));

     FILE *
     fropen(void *cookie, int (*readfn)(void *, char *, int));

     FILE *
     fwopen(void *cookie, int (*writefn)(void *, const char *, int));

     The funopen() function associates a stream with up to four ``I/O functions''.  Either readfn or writefn
     must be specified; the others can be given as an appropriately-typed NULL pointer.  These I/O functions
     will be used to read, write, seek and close the new stream.

     In general, omitting a function means that any attempt to perform the associated operation on the
     resulting stream will fail.  If the close function is omitted, closing the stream will flush any
     buffered output and then succeed.

     The calling conventions of readfn, writefn, seekfn and closefn must match those, respectively, of
     read(2), write(2), lseek(2), and close(2) with the single exception that they are passed the cookie
     argument specified to funopen() in place of the traditional file descriptor argument.

     Read and write I/O functions are allowed to change the underlying buffer on fully buffered or line
     buffered streams by calling setvbuf(3).  They are also not required to completely fill or empty the
     buffer.  They are not, however, allowed to change streams from unbuffered to buffered or to change the
     state of the line buffering flag.  They must also be prepared to have read or write calls occur on
     buffers other than the one most recently specified.

     All user I/O functions can report an error by returning -1.  Additionally, all of the functions should
     set the external variable errno appropriately if an error occurs.

     An error on closefn() does not keep the stream open.

     As a convenience, the include file <stdio.h> defines the macros fropen() and fwopen() as calls to
     funopen() with only a read or write function specified.

     Upon successful completion, funopen() returns a FILE pointer.  Otherwise, NULL is returned and the
     global variable errno is set to indicate the error.

     [EINVAL]           The funopen() function was called without either a read or write function.  The
                        funopen() function may also fail and set errno for any of the errors specified for
                        the routine malloc(3).

     fcntl(2), open(2), fclose(3), fopen(3), fseek(3), setbuf(3)

     The funopen() functions first appeared in 4.4BSD.

     The funopen() function may not be portable to systems other than BSD.

     The funopen() interface erroneously assumes that fpos_t is an integral type; see fseek(3) for a discus-sion discussion
     sion of this issue.

BSD                             March 19, 2004                             BSD

Reporting Problems

The way to report a problem with this manual page depends on the type of problem:

Content errors
Report errors in the content of this documentation with the feedback links below.
Bug reports
Report bugs in the functionality of the described tool or API through Bug Reporter.
Formatting problems
Report formatting mistakes in the online version of these pages with the feedback links below.