[Glibc-bsd-commits] r5014 - in trunk/freebsd-glue: debian include src
Robert Millan
rmh at alioth.debian.org
Mon Oct 7 22:30:06 UTC 2013
Author: rmh
Date: 2013-10-07 22:30:06 +0000 (Mon, 07 Oct 2013)
New Revision: 5014
Added:
trunk/freebsd-glue/src/funopen.c
Modified:
trunk/freebsd-glue/debian/changelog
trunk/freebsd-glue/include/stdio.h
trunk/freebsd-glue/src/Makefile
Log:
Implement funopen(), fropen() and fwopen().
Modified: trunk/freebsd-glue/debian/changelog
===================================================================
--- trunk/freebsd-glue/debian/changelog 2013-10-07 22:29:08 UTC (rev 5013)
+++ trunk/freebsd-glue/debian/changelog 2013-10-07 22:30:06 UTC (rev 5014)
@@ -1,6 +1,7 @@
freebsd-glue (0.1.9) UNRELEASED; urgency=low
* Build with full -Werror.
+ * Implement funopen(), fropen() and fwopen().
-- Robert Millan <rmh at debian.org> Tue, 08 Oct 2013 00:28:49 +0200
Modified: trunk/freebsd-glue/include/stdio.h
===================================================================
--- trunk/freebsd-glue/include/stdio.h 2013-10-07 22:29:08 UTC (rev 5013)
+++ trunk/freebsd-glue/include/stdio.h 2013-10-07 22:30:06 UTC (rev 5014)
@@ -10,4 +10,14 @@
here. */
#include <__want_lseek.h>
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+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));
+__END_DECLS
+
#endif
Modified: trunk/freebsd-glue/src/Makefile
===================================================================
--- trunk/freebsd-glue/src/Makefile 2013-10-07 22:29:08 UTC (rev 5013)
+++ trunk/freebsd-glue/src/Makefile 2013-10-07 22:30:06 UTC (rev 5014)
@@ -3,6 +3,7 @@
exec.c \
feature_present.c \
fstab.c \
+ funopen.c \
getosreldate.c \
random.c \
trimdomain.c \
Added: trunk/freebsd-glue/src/funopen.c
===================================================================
--- trunk/freebsd-glue/src/funopen.c (rev 0)
+++ trunk/freebsd-glue/src/funopen.c 2013-10-07 22:30:06 UTC (rev 5014)
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <errno.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 *))
+{
+ auto ssize_t cookie_read (void *cookie, char *buf, size_t size);
+ auto ssize_t cookie_read (void *cookie, char *buf, size_t size)
+ {
+ return readfn (cookie, buf, size);
+ }
+
+ auto ssize_t cookie_write (void *cookie, const char *buf, size_t size);
+ auto ssize_t cookie_write (void *cookie, const char *buf, size_t size)
+ {
+ return writefn (cookie, buf, size);
+ }
+
+ if (seekfn)
+ {
+ errno = ENOSYS;
+ return NULL;
+ }
+
+ cookie_io_functions_t funcs = {
+ .read = cookie_read,
+ .write = cookie_write,
+ .seek = NULL,
+ .close = closefn
+ };
+
+ return fopencookie ((void *) cookie, "r+", funcs);
+}
+
+FILE *
+fropen (void *cookie, int (*readfn)(void *, char *, int))
+{
+ return funopen (cookie, readfn, NULL, NULL, NULL);
+}
+
+FILE *
+fwopen (void *cookie, int (*writefn)(void *, const char *, int))
+{
+ return funopen (cookie, NULL, writefn, NULL, NULL);
+}
More information about the Glibc-bsd-commits
mailing list