delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/01/18/06:51:01

From: Martin Str|mberg <ams AT ludd DOT luth DOT se>
Message-Id: <200301181149.h0IBnhY20842@brother.ludd.luth.se>
Subject: Re: lseek() calling llseek()
To: djgpp-workers AT delorie DOT com
Date: Sat, 18 Jan 2003 12:49:43 +0100 (MET)
In-Reply-To: <200301181041.h0IAfYc20680@brother.ludd.luth.se> from "Martin Str|mberg" at Jan 18, 2003 11:41:34 AM
X-Mailer: ELM [version 2.5 PL2]
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

According to Martin Str|mberg:
> Comments are welcome. In particular on my documentation changes and the 
> last return statement in lseek() (which could be made safer with some more 
> lines of code).
...
> +  return llseek_offset&0xffffffff; /* Magically works right now with
> +                                     GCC (no guarantee). The problem
> +                                     is when INT_MAX (2^31-1) <
> +                                     llseek_offset, which invokes
> +                                     implementation defined
> +                                     behaviour. */

Something like this:
  llseek_offset = llseek(handle, offset, whence);
  if( offset == -1 )
  {
    return -1; /* llseek sets errno. */
  }

  /* Here we rely on that llseek()'s return range is [-1, 2^32-2]. */
  if( llseek_offset&0x80000000 )
  {
    return (llseek_offset&0x7fffffff)|0x80000000;
  }
  else
  {
    return llseek_offset&0x7fffffff;
  }


Right,

						MartinS

- Raw text -


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