.\" the source, must acknowledge the copyright and authors of this work.
.\" %%%LICENSE_END
.\"
-.TH FOPENCOOKIE 3 2015-03-02 "Linux" "Linux Programmer's Manual"
+.TH FOPENCOOKIE 3 2020-04-11 "Linux" "Linux Programmer's Manual"
.SH NAME
fopencookie \- opening a custom stream
.SH SYNOPSIS
argument is a structure that contains four fields pointing to the
programmer-defined hook functions that are used to implement this stream.
The structure is defined as follows
+.PP
.in +4n
-.nf
-
+.EX
typedef struct {
cookie_read_function_t *read;
cookie_write_function_t *write;
cookie_seek_function_t *seek;
cookie_close_function_t *close;
} cookie_io_functions_t;
-
-.fi
+.EE
.in
+.PP
The four fields are as follows:
.TP
.I cookie_read_function_t *read
of the following three values is supplied in
.IR whence :
.RS
-.TP 10
+.TP
.B SEEK_SET
The stream offset should be set
.I *offset
.TE
.SH CONFORMING TO
This function is a nonstandard GNU extension.
-.SH EXAMPLE
+.SH EXAMPLES
The program below implements a custom stream whose functionality
is similar (but not identical) to that available via
.BR fmemopen (3).
and then seeks through the stream reading two out of every
five characters and writing them to standard output.
The following shell session demonstrates the use of the program:
+.PP
.in +4n
-.nf
-
+.EX
.RB "$" " ./a.out \(aqhello world\(aq"
/he/
/ w/
/d/
Reached end of file
-
-.fi
+.EE
.in
+.PP
Note that a more general version of the program below
could be improved to more robustly handle various error situations
(e.g., opening a stream with a cookie that already has an open stream;
exit(EXIT_FAILURE);
}
if (nread == 0) {
- printf("Reached end of file\\n");
+ printf("Reached end of file\en");
break;
}
- printf("/%.*s/\\n", nread, buf);
+ printf("/%.*s/\en", nread, buf);
}
exit(EXIT_SUCCESS);