delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/27/04:17:32

From: Vik Heyndrickx <Vik DOT Heyndrickx AT rug DOT ac DOT be>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Problem with read()
Date: Mon, 27 Apr 1998 10:12:16 +0200
Organization: University of Ghent, Belgium
Lines: 28
Message-ID: <35443DE0.6FE3@rug.ac.be>
References: <35443AEB DOT 7115C264 AT sis DOT co DOT at>
NNTP-Posting-Host: eduserv1.rug.ac.be
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Gerhard W. Gruber wrote:
> 
> I'm not sure if this is an error in the standard library or if the
> behaviour in this case is not exactly defined.
> 
> I'm trying to read a file into memory. My buffer to read in is 4096 bytes
> long and the file is 10 bytes long.
> 
> I seek to position 5 of the file and call read with read(hdl, buffer,
> 4096). The result of read should be the number of bytes actually read or -1
> if an error occured. In this case it should return 5 bytes, because the
> remainder of the file is 5 bytes, but I get -1.
> 
> Is this an error or is this behaviour correct? 

It is not correct to return -1 unless there is an error situation.
Reading beyond EOF is not considered an error situation. So it seems
that this behaviour is incorrect.
However, are you SURE that nothing else fails.

e.g. can't it be that the open call fails? Do you open the file for
reading? Does the lseek call succeed? 
Please post a short program that still shows this erratic behaviour.

-- 
 \ Vik /-_-_-_-_-_-_/
  \___/ Heyndrickx /
   \ /-_-_-_-_-_-_/  Knight in the Order of the Unsigned Types

- Raw text -


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