koren@hpfelg.HP.COM (Steve Koren) (03/01/90)
Any of you AmigaDos i/o gurus out there know how to force a flush if I have an AmigaDos file handle? For example, with a normal file pointer, I can do: fflush(fp); (where fp is FILE *fp); However, there doesn't seem to be a Flush(fh) call for AmigaDos i/o; at least, not that I can find documented. What do I do? - steve
koren@hpfelg.HP.COM (Steve Koren) (03/02/90)
One more for the AmigaDos I/O gurus: How can I tell whether I have reached eof without actually reading anything from the file? That is, I am aware that if Read() returns <= 0 when you asked for a positive number of byte, you either hit the end of the file or had an error. But what if (for a reason that is not important here - you'll have to trust me that it's necessary) I have a file pointer but don't want to call Read() to check eof status? I can't seem to find an Feof() call for AmigaDos I/O. thanks for any help.... - steve PS - the motivation for my recent AmigaDos I/O questions is this: I was very unsatisfied with both the size and performance of the SKsh external commands. I have already changed them to AmigaDos I/O (from Lattice), and they are now much smaller and from 5 to 10 times faster. That part was easy, since the external commands (even the new 1.4 ones such as grep) are quite simple. However, I am planning to implement *real* pipes in SKsh 1.4 using the 'cmd | cmd' syntax and the AmigaDos pipe device. To do this, I need to convert at least some of SKsh to AmigaDos I/O (from ansi). I've found a few capabilities that I need but can't find, such as this and the Fflush() call. Any help would be greatly appriciated! PPS- I am still hoping to finish SKsh 1.4 by late march or early april, although it depends on 1) how much time I can devote to it, and 2) how long I get stuck on stuff like this. PPPS - So far, empirical results seem to suggest that the AmigaDos Read() call is from 5 to 10 times faster than the Lattice read() call. A file which used to take 17 seconds to 'wc -c' now takes 2 seconds with the SKsh 1.4 wc command. I wonder how the Lattice call is implemented?
Jim.Locker@afitamy.fidonet.org (Jim Locker) (03/07/90)
You might try Close(), then Open(). The Close will flush for you. Clumsy? sure. But it works. Jim Locker -- ---------------------------------------------------------------------------- AFIT Amiga Users BBS/UFGateway |Jim Locker - via FidoNet node 1:110/300 1:110/300 Dayton, Ohio |UUCP: afitamy!Jim.Locker (513)-252-7681 |ARPA: Jim.Locker@afitamy.fidonet.org ----------------------------------------------------------------------------
deven@rpi.edu (Deven T. Corzine) (03/10/90)
On 2 Mar 90 14:50:49 GMT, koren@hpfelg.HP.COM (Steve Koren) said:
Steve> One more for the AmigaDos I/O gurus:
Steve> How can I tell whether I have reached eof without actually
Steve> reading anything from the file? That is, I am aware that if
Steve> Read() returns <= 0 when you asked for a positive number of
Steve> byte, you either hit the end of the file or had an error. But
Steve> what if (for a reason that is not important here - you'll have
Steve> to trust me that it's necessary) I have a file pointer but
Steve> don't want to call Read() to check eof status? I can't seem to
Steve> find an Feof() call for AmigaDos I/O.
Hmm. I'll give this a shot.
Eof(fh)
BPTR fh;
{
ULONG pos;
pos = Seek(fh, 0L, OFFSET_END);
return(pos==Seek(fh, pos, OFFSET_BEGINNING));
}
While this should work reliably on _regular_ files, I suggest you
don't try it on a pipe or interactive input. Furthermore, this may be
quite slow, depending on what the actual implementation of Seek() is
like. If you call this function frequently, you're inviting disk
thrashing. There's probably a better way to do this, but maybe not
with the DOS calls available. The only other option to try with Seek
might be to change that first Seek to Seek(fh,1L,OFFSET_CURRENT) and
check for an error representing seeking beyond the end of the file.
Steve> [ ... switching to AmigaDOS I/O for speed ...]
Steve> I've found a few capabilities that I need but can't find, such
Steve> as this and the Fflush() call. Any help would be greatly
Steve> appreciated!
As I've said, forget about FFlush(); Write() will block until done. I
don't see what you need an feof() type of function for. Maybe if you
could explain in more detail what you're attempting, I could offer an
alternative approach to try which wouldn't need an feof()...
Steve> PPPS - So far, empirical results seem to suggest that the
Steve> AmigaDos Read() call is from 5 to 10 times faster than the
Steve> Lattice read() call. A file which used to take 17 seconds to
Steve> 'wc -c' now takes 2 seconds with the SKsh 1.4 wc command. I
Steve> wonder how the Lattice call is implemented?
It's an interesting question. I don't see that they NEED to do
anything beyond a table lookup on fd for a filehandle, and then simply
call the AmigaDOS Read() routine. But I haven't looked at their
implementationaybe there's something I've missed.
Deven
--
Deven T. Corzine Internet: deven@rpi.edu, shadow@pawl.rpi.edu
Snail: 2151 12th St. Apt. 4, Troy, NY 12180 Phone: (518) 274-0327
Bitnet: deven@rpitsmts, userfxb6@rpitsmts UUCP: uunet!rpi!deven
Simple things should be simple and complex things should be possible.