Author: cem
Date: Wed May 11 14:38:27 2016
New Revision: 299456
URL: https://svnweb.freebsd.org/changeset/base/299456
Log:
libc: Add fopencookie(3) wrapper around funopen(3)
Reviewed by: jhb, oshogbo
Sponsored by: EMC / Isilon Storage Division
Differential Revision:https://reviews.freebsd.org/D6282
Added:
head/lib/libc/stdio/fopencookie.3 (contents, props changed)
head/lib/libc/stdio/fopencookie.c (contents, props changed)
Modified:
head/include/stdio.h
head/lib/libc/stdio/Makefile.inc
head/lib/libc/stdio/funopen.3
Modified: head/include/stdio.h
==
--- head/include/stdio.hWed May 11 14:37:33 2016(r299455)
+++ head/include/stdio.hWed May 11 14:38:27 2016(r299456)
@@ -58,6 +58,11 @@ typedef __ssize_t ssize_t;
#endif
#endif
+#ifndef _OFF64_T_DECLARED
+#define_OFF64_T_DECLARED
+typedef__off_t off64_t;
+#endif
+
#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE
#ifndef _VA_LIST_DECLARED
typedef__va_list va_list;
@@ -427,6 +432,18 @@ FILE *funopen(const void *,
#definefropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
#definefwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
+typedef ssize_t (cookie_read_function_t)(void *, char *, size_t);
+typedef ssize_t (cookie_write_function_t)(void *, const char *, size_t);
+typedef int (cookie_seek_function_t)(void *, off64_t *, int);
+typedef int (cookie_close_function_t)(void *);
+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;
+FILE *fopencookie(void *, const char *, cookie_io_functions_t);
+
/*
* Portability hacks. See .
*/
Modified: head/lib/libc/stdio/Makefile.inc
==
--- head/lib/libc/stdio/Makefile.incWed May 11 14:37:33 2016
(r299455)
+++ head/lib/libc/stdio/Makefile.incWed May 11 14:38:27 2016
(r299456)
@@ -8,7 +8,8 @@ SRCS+= _flock_stub.c asprintf.c clrerr.c
fclose.c fcloseall.c fdopen.c \
feof.c ferror.c fflush.c fgetc.c fgetln.c fgetpos.c fgets.c fgetwc.c \
fgetwln.c fgetws.c \
- fileno.c findfp.c flags.c fmemopen.c fopen.c fprintf.c fpurge.c \
+ fileno.c findfp.c flags.c fmemopen.c fopen.c \
+ fopencookie.c fprintf.c fpurge.c \
fputc.c fputs.c \
fputwc.c fputws.c fread.c freopen.c fscanf.c fseek.c fsetpos.c \
ftell.c funopen.c fvwrite.c fwalk.c fwide.c fwprintf.c fwscanf.c \
@@ -35,7 +36,7 @@ SYM_MAPS+=${LIBC_SRCTOP}/stdio/Symbol.m
MAN+= fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 fgetwln.3 fgetws.3 \
flockfile.3 \
- fopen.3 fputs.3 \
+ fopen.3 fopencookie.3 fputs.3 \
fputws.3 fread.3 fseek.3 funopen.3 fwide.3 getc.3 \
getline.3 getwc.3 mktemp.3 open_memstream.3 \
printf.3 printf_l.3 putc.3 putwc.3 remove.3 scanf.3 scanf_l.3 setbuf.3 \
Added: head/lib/libc/stdio/fopencookie.3
==
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/lib/libc/stdio/fopencookie.3 Wed May 11 14:38:27 2016
(r299456)
@@ -0,0 +1,156 @@
+.\" Copyright (c) 2016, EMC / Isilon Storage Division
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"notice, this list of conditions and the following disclaimer in the
+.\"documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
+.\" IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+.\" THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+.\" CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd May 9, 2016
+.Dt FOPENCOOKIE 3
+.Os
+.Sh NAME
+.Nm fopencookie
+.Nd open a stream
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS