delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/01/14/13:52:09

Sender: rich AT phekda DOT freeserve DOT co DOT uk
Message-ID: <3A61E9A6.EB7E45B@phekda.freeserve.co.uk>
Date: Sun, 14 Jan 2001 18:02:14 +0000
From: Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
X-Mailer: Mozilla 4.51 [en] (X11; I; Linux 2.2.17 i586)
X-Accept-Language: de,fr
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com
Subject: Re: FSEXTs and llseek()
References: <200101132117 DOT WAA26339 AT father DOT ludd DOT luth DOT se>
Reply-To: djgpp-workers AT delorie DOT com

Hello.

Martin Str|mberg wrote:
> Of course you can't cast "int *" to "long long *" and expect anything
> to work. But you can cast "int" to "long long" (not necessarily the
> return value).

OK, I wasn't quite sure what you meant, but it's clear now.

> > The problem is returning a good (int-sized) offset to the FSEXT caller
> > for __FSEXT_llseek. If you can't return a good offset, then it's
> > broken.
> 
> There is a good (well, sufficiently non-broken at least) int-sized
> return value: the range [-1, 2^32-2] which will be represented as the
> range [-2^31, 2^31-1].

Perhaps with a conversion like (untested):

  int return_offset_as_int (offset_t offset, int *rv)
  {
    offset_t t = offset;

    if (t > INT_MAX) {
      t -= INT_MAX;

      /* Handle offset > 2^32 - 2 */
      if (t > INT_MAX)
        return(-1);

      *rv = -1 - (int) offset;
    } else if (t >= 0) {
      *rv = (int) offset;
    } else {
      /* Do not handle negative offset */
      return(-1);
    }

    return(0);
  }

and then back conversion like:

  offset_t return_int_as_offset (int rv)
  {
    if (rv < -1)
      return((offset_t) - (rv + 1));
    else
      return((offset_t) rv);
  }

I guess these conversion functions would be FSEXT convenience functions.

So we get one bit extra for llseek()'s offsets over normal lseek() for
FSEXTs.

Another possible solution is to have llseek() return an error if too big
an offset is used (greater than INT_MAX), otherwise call the __FSEXT_lseek
handler. Then __FSEXT_llseek could be fixed later to support the full long
long offsets.

Bye, Rich =]

-- 
Richard Dawe
[ mailto:richdawe AT bigfoot DOT com | http://www.bigfoot.com/~richdawe/ ]

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019