Boost logo

Boost :

Subject: Re: [boost] [btree] Large file support
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-10-01 09:25:23


Beman Dawes wrote:
>
> POSIX-like operating systems get around this problem by supply
> functions with names like llseek or lseek64 that traffic in long long
> instead of long.
>
> So there is a line of code:
>
> new_offset = ::lseek(handle(), offset, whence); // offset is a
> variable of type int64_t
>
> That needs to change to something like:
>
> #if defined(SOMEOS)
> new_offset = ::|lseek(handle(), offset, whence);
> #elif defined(ANOTHEROS)
> new_offset = ::whatever(handle(), offset, whence);
> #else
> new_offset = ::lseek(handle(), offset, whence);
> #endif

When code isn't separated by platform, and semantics are the same, I prefer to define a macro like this:

#ifdef SOMEOS
# define LSEEK ::lseek
#else
# define LSEEK ::lseek64
#endif

Then the later invocation is just this:

   new_offset = LSEEK(handle(), offset, whence);

If the macro would be exposed in a header, then a more unique name would be appropriate, of course.

> Up at the front of the source file there may also have to be special
> headers included or symbols defined, depending on the operating
> system.
>
> I'd appreciate some help from folks familiar with particular
> non-Windows operating systems. What is the preferred name for the
> 64-bit seek function and what is the preferred #if defined(symbol)? Do
> special headers have to be included or special symbols defined?

I'm using lseek64() in my 64b code. According to the manpages, the required includes don't differ between lseek() and lseek64(). The latter is only available when _LARGEFILE64_SOURCE is defined.

The manpage goes on to say that lseek64() is an alias for llseek() and has been available since glibc 2.1. However, when I look up llseek(2), it redirects to _llseek(2) and a search of headers in /usr/include doesn't turn up a .h with llseek(). That suggests lseek64() is a safer name.

FYI: lseek() uses a 32b off_t on 32b platforms unless _FILE_OFFSET_BITS is #defined as 64. In that case, lseek() is the same as lseek64().

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk