chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-hackers] negative file-position seek


From: Peter Bex
Subject: Re: [Chicken-hackers] negative file-position seek
Date: Fri, 2 May 2014 13:07:27 +0200
User-agent: Mutt/1.4.2.3i

On Thu, Apr 24, 2014 at 09:30:32AM -0700, Seth Alves wrote:
>   (set-file-position! p -1 seek/cur))
> Error: (set-file-position!) invalid negative port position
> -1

Hi Seth,

Thanks for your bug report and patch.  I started wondering why
CHICKEN is trying to catch this case in the first place, because
the POSIX function will return an error and errno.  Even if you
use SEEK_CUR/SEEK_WHENCE (which you forgot), it's possible to get
to a negative position (lseek(f, -4, SEEK_WHENCE) in a file of
size 3 would result in position -1, which is invalid and cannot
be statically detected by CHICKEN, but POSIX _will_ signal an
error.

So I decided it's much simpler and safer to not attempt to do this
at all.  I also noticed that the definition for set-file-position!,
file-position and the seek positions are duplicated in posixwin.scm
and posixunix.scm, and you'd have to remember this and patch both.
Instead, it's better to move these to posix-common.scm.

The attached patch takes care of both these things.  It also removes
the definitions for character-device?, block-device?, fifo? and socket?
from posixwin, because the ones in posix-common are sufficient.

I've tested this on Debian and Windows 7 (only mingw-msys).

Cheers,
Peter
-- 
http://www.more-magic.net

Attachment: 0001-Allow-negative-arguments-to-set-file-position-for-se.patch
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]