From 6a970984017e44324691a449cac38ecd00b249d7 Mon Sep 17 00:00:00 2001 From: millert Date: Wed, 5 Jan 2022 20:57:27 +0000 Subject: [PATCH] funopen(): change seekfn argument to use off_t, not fpos_t On BSD, fpos_t is typedef'd to off_t but some systems use a struct. This means fpos_t is not a portable function argument or return value. Both FreeBSD and the Linux libbsd funopen() have switched to off_t for this--we should too. From Joe Nelson. OK deraadt@ --- bin/csh/csh.c | 8 ++++---- include/stdio.h | 4 ++-- lib/libc/stdio/funopen.3 | 13 ++++--------- lib/libc/stdio/funopen.c | 4 ++-- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/bin/csh/csh.c b/bin/csh/csh.c index 6ed362ab604..654361c0a76 100644 --- a/bin/csh/csh.c +++ b/bin/csh/csh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: csh.c,v 1.47 2020/08/30 22:23:47 mortimer Exp $ */ +/* $OpenBSD: csh.c,v 1.48 2022/01/05 20:57:27 millert Exp $ */ /* $NetBSD: csh.c,v 1.14 1995/04/29 23:21:28 mycroft Exp $ */ /*- @@ -153,7 +153,7 @@ bool tellwhat = 0; extern char **environ; static int readf(void *, char *, int); -static fpos_t seekf(void *, fpos_t, int); +static off_t seekf(void *, off_t, int); static int writef(void *, const char *, int); static int closef(void *); static int srccat(Char *, Char *); @@ -1271,8 +1271,8 @@ writef(void *oreo, const char *buf, int siz) return write(DESC(oreo), buf, siz); } -static fpos_t -seekf(void *oreo, fpos_t off, int whence) +static off_t +seekf(void *oreo, off_t off, int whence) { return lseek(DESC(oreo), off, whence); } diff --git a/include/stdio.h b/include/stdio.h index ffb49fbd1b9..0db964f3409 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -1,4 +1,4 @@ -/* $OpenBSD: stdio.h,v 1.54 2020/09/11 17:56:41 naddy Exp $ */ +/* $OpenBSD: stdio.h,v 1.55 2022/01/05 20:57:27 millert Exp $ */ /* $NetBSD: stdio.h,v 1.18 1996/04/25 18:29:21 jtc Exp $ */ /*- @@ -368,7 +368,7 @@ __BEGIN_DECLS FILE *funopen(const void *, int (*)(void *, char *, int), int (*)(void *, const char *, int), - fpos_t (*)(void *, fpos_t, int), + off_t (*)(void *, off_t, int), int (*)(void *)); __END_DECLS #define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) diff --git a/lib/libc/stdio/funopen.3 b/lib/libc/stdio/funopen.3 index 5138bf1160b..0348e49304d 100644 --- a/lib/libc/stdio/funopen.3 +++ b/lib/libc/stdio/funopen.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: funopen.3,v 1.18 2015/11/04 21:30:13 tedu Exp $ +.\" $OpenBSD: funopen.3,v 1.19 2022/01/05 20:57:27 millert Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: November 4 2015 $ +.Dd $Mdocdate: January 5 2022 $ .Dt FUNOPEN 3 .Os .Sh NAME @@ -42,7 +42,7 @@ .Ft FILE * .Fn funopen "const void *cookie" "int (*readfn)(void *, char *, int)" \ "int (*writefn)(void *, const char *, int)" \ - "fpos_t (*seekfn)(void *, fpos_t, int)" \ + "off_t (*seekfn)(void *, off_t, int)" \ "int (*closefn)(void *)" .Ft FILE * .Fn fropen "const void *cookie" "int (*readfn)(void *, char *, int)" @@ -84,12 +84,7 @@ with the exceptions that they are passed the .Fa cookie argument specified to .Fn funopen -in place of the traditional file descriptor argument and that -the seek function takes an -.Li fpos_t -argument and not an -.Li off_t -argument. +in place of the traditional file descriptor argument. .Pp Read and write I/O functions are allowed to change the underlying buffer on fully buffered or line buffered streams by calling diff --git a/lib/libc/stdio/funopen.c b/lib/libc/stdio/funopen.c index b6fc464b4aa..8c0aafbf204 100644 --- a/lib/libc/stdio/funopen.c +++ b/lib/libc/stdio/funopen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: funopen.c,v 1.9 2015/08/31 02:53:57 guenther Exp $ */ +/* $OpenBSD: funopen.c,v 1.10 2022/01/05 20:57:27 millert Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -38,7 +38,7 @@ 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 *)) + off_t (*seekfn)(void *, off_t, int), int (*closefn)(void *)) { FILE *fp; int flags; -- 2.20.1