fseek(3) is implemented by just calling fseeko(3), the POSIX addition 
version that takes an off_t instead of a long:

int
fseek(FILE *fp, long offset, int whence)
{
        return (fseeko(fp, offset, whence));
}

...so there's no reason for libc to be using fseek() internally, as that 
just loses range on ILP32 platforms and adds that (tail)call overhead.

Diff below converts the last three such uses** and then updates the symbol 
naming for fseek to block attempts to reference it in the future so uses 
don't accidentally crawl back in.

ok?


Philip

** theoretically fixing the handling of xdr_setpos() to a position
beyond 2GB on an xdrstdio, I guess



Index: gen/getcap.c
===================================================================
RCS file: /data/src/openbsd/src/lib/libc/gen/getcap.c,v
retrieving revision 1.35
diff -u -p -r1.35 getcap.c
--- gen/getcap.c        3 Jul 2019 03:24:04 -0000       1.35
+++ gen/getcap.c        23 Dec 2019 23:21:11 -0000
@@ -244,7 +244,7 @@ getent(char **cap, u_int *len, char **db
                 * Open database if not already open.
                 */
                if (fp != NULL) {
-                       (void)fseek(fp, 0L, SEEK_SET);
+                       fseeko(fp, 0, SEEK_SET);
                        myfd = 0;
                        opened++;
                } else {
Index: rpc/xdr_stdio.c
===================================================================
RCS file: /data/src/openbsd/src/lib/libc/rpc/xdr_stdio.c,v
retrieving revision 1.16
diff -u -p -r1.16 xdr_stdio.c
--- rpc/xdr_stdio.c     14 Feb 2022 03:38:59 -0000      1.16
+++ rpc/xdr_stdio.c     14 May 2022 01:40:56 -0000
@@ -144,7 +144,7 @@ static bool_t
 xdrstdio_setpos(XDR *xdrs, u_int pos)
 { 
 
-       return ((fseek((FILE *)xdrs->x_private, (long)pos, SEEK_SET) == -1) ?
+       return ((fseeko((FILE *)xdrs->x_private, pos, SEEK_SET) == -1) ?
                FALSE : TRUE);
 }
 
Index: stdio/rewind.c
===================================================================
RCS file: /data/src/openbsd/src/lib/libc/stdio/rewind.c,v
retrieving revision 1.6
diff -u -p -r1.6 rewind.c
--- stdio/rewind.c      31 Aug 2015 02:53:57 -0000      1.6
+++ stdio/rewind.c      23 Dec 2019 23:30:22 -0000
@@ -37,7 +37,7 @@
 void
 rewind(FILE *fp)
 {
-       (void) fseek(fp, 0L, SEEK_SET);
+       fseeko(fp, 0, SEEK_SET);
        clearerr(fp);
        errno = 0;      /* not required, but seems reasonable */
 }
Index: hidden/stdio.h
===================================================================
RCS file: /data/src/openbsd/src/lib/libc/hidden/stdio.h,v
retrieving revision 1.7
diff -u -p -r1.7 stdio.h
--- hidden/stdio.h      6 Sep 2016 19:56:36 -0000       1.7
+++ hidden/stdio.h      14 May 2022 02:01:51 -0000
@@ -65,7 +65,7 @@ PROTO_NORMAL(fputs);
 PROTO_NORMAL(fread);
 PROTO_NORMAL(freopen);
 PROTO_NORMAL(fscanf);
-PROTO_NORMAL(fseek);
+PROTO_STD_DEPRECATED(fseek);
 PROTO_NORMAL(fseeko);
 PROTO_NORMAL(fsetpos);
 PROTO_NORMAL(ftell);
Index: stdio/fseek.c
===================================================================
RCS file: /data/src/openbsd/src/lib/libc/stdio/fseek.c,v
retrieving revision 1.13
diff -u -p -r1.13 fseek.c
--- stdio/fseek.c       28 Jun 2019 13:32:42 -0000      1.13
+++ stdio/fseek.c       14 May 2022 02:00:03 -0000
@@ -250,4 +250,3 @@ fseek(FILE *fp, long offset, int whence)
 {
        return (fseeko(fp, offset, whence));
 }
-DEF_STRONG(fseek);

Reply via email to