Re: Re: [UnixOS2] libc

Holger Veit <[email protected]> Wed, 18 Jun 2003 12:21:46 +0200
Newsgroups gmane.comp.ide.emx.devel
Message-ID <[email protected]>
On Wed, Jun 18, 2003 at 11:22:51AM +0200, Stefan Neis wrote:
> On Tue, 17 Jun 2003, Andreas Buening wrote:
[...]
> > How do other systems solve this problem? Do they use an internal
> > fseek_64() replacement which is used by default instead of fseek()?
> 
> There typically is fseek() (32-bit version) and fseek_64().
> If -D_FILE_OFFSET_BITS=64 is given on compilation, fseek() is typically
> "somehow" mapped to fseek_64(). And you better avoid mixing the two in
> the same binary. (i.e. either compile _everything_ (including every helper
> library) with that library, or nothing). Similar to the problems
> with single- and multi-threaded libc in EMX. That's why I suggested to
> have only the large file enabled version in a new library. It would
> eliminate all the problems of unintentionally mixing the two variants.

The fseek vs fseek64 is yet another example of broken Unix API design.
Effectively, this revolves around the problem whether off_t has been
designed as 32 bit (as usual) or as 64 bit right from the beginning.

Since most Unixes started broken by concept with the old 'long' offset
type, this had to be "fixed" later when designers "suddenly" detected that
their Unix filesystems were designed for Terabytes of storage and 
disks meanwhile approached the size of 2GB (which is ridiculously small
nowadays). Result was this awkward *_64() patches which required specific
programming and compilation.

We only have to preserve compatibility in that we need some fseek() and
fseek_64() at all, not with binary compatibility with existing code
(this can still access the old EMX DLLs and will be happy).

If we need to touch the header files already then my proposal is to
	typedef longlong off_t;
and prototype
	int fseek(FILE*,off_t,int);
and implement
	int fseek_64(FILE* f,off_t off,int whence) { return fseek(f,off,whence); }

The fseek code will itself fall down to a 64 bit compliant lseek(), and
this will, depending on the presence of Dos*L routines or not (loadable
DLL module) decide whether to accept the call or not if an offset >2GB is
specified.

Holger