Subject: lib/15265: fsetpos() silently truncates file offsets to "long"
To: None <>
From: None <>
List: netbsd-bugs
Date: 01/16/2002 18:47:53
>Number:         15265
>Category:       lib
>Synopsis:       fsetpos() silently truncates file offsets to "long"
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jan 16 09:49:00 PST 2002
>Originator:     Matthias Drochner
>Release:        NetBSD 1.5
System: NetBSD zelz26 1.5ZA NetBSD 1.5ZA (ZELZ26) #134: Wed Jan 9 19:36:59 MET 2002 drochner@zelz26:/home/drochner/netbsd/sys/arch/i386/compile/ZELZ26 i386
Architecture: i386
Machine: i386
	The c library function fsetpos() gets passed an fpos_t as file
offset (which is defined as off_t), ie 64 bit.
It is implemented as a call to fseek(), passing a "long" as file offset
which means that it gets truncated on 32-bit platforms.
The following test code fails on NetBSD-1.5/i386 but succeeds on -current:
#include <stdio.h>
#include <err.h>

        FILE *a;
        fpos_t b;
        int res;

        a = fopen("mist", "w");
        if (!a)
                err(1, "open");

        b = 0x80000001;

        res = fsetpos(a, &b);
        if (res)
                err(1, "fsetpos");

        return (0);
	In -current, fsetpos() uses fseeko(), which is identical to fseek()
except the "long" replaced by "off_t".