#stdio in Lattice C
6 messages in this thread
I am trying to figure oyt programming on the Amiga. I'm using Lattice C
4.01, and I'm havin a bit of a problem. I've gotten up to chapter four in
Berry's "Inside the Amiga". In his examples 4-5 and 4-6, he seems to be
using stdin, etc. in ways that just don't work. In a rather round-about way,
he attemps to use stdin as a File Handle for an AmigaDOS Read(). As I
understand the Lattice manual, stdin is a Lattice level 2 File Pointer.
FILE *stdin;
not struct FileHandle *stdin;
I've found a function, fdopen(), that will take a level 1 File Handle and
return a level 2 File Pointer. I can't figure out how to do it the other way
around. I've looked through stdio.h, and the FILE is a typedef for a pointer
to a struct _iobuf. _iobuf contains info on the buffers, and an int file
descriptor, which doesn't seem to be what I want. Anybody out there using
Lattice C 4.0+ have any ideas?
Jeff,
Sounds like you're real close. There are basically two types of file io
that you can do, using the standard input and output. (Actually, this is a
simplification, but let's leave it at that for now). You can use the Lattice
functions to access the input and output streams but using the Lattice
level-2 file functions (getc, fgetc, gets, fgets, putc, puts, etc), which the
Lattice library routines will process and pass to the AmigaDos FileHandles.
Your other option is to use the AmigaDos FileHandles yourself, which you can
obtain via the Input() and Output() AmigaDOS function calls, and then read
from and write to them as appropriate, using the AmigaDOS file io functions
Read() and Write() <— (notice the capitalization). These are basically two
equivalent approaches, but using the Lattice libraries is more "standard"
across machine environments, while using the AmigaDOS functions directly is
more "Amiga".
Hope this clarifies more than it confuses…Bob
Thanks for the response. I was trying to rewrite the program, and I couldn't
find a way to get the File Handles for stdin and stdout. I found the Input()
and Output() functions in the chapter on disk files. Now to get it to work.
Sounds like he was using the original lattice compiler, with the startup code
written by Amiga, where stdin and stdout where (were, sorry) defined as LONGS
and set by calls to Open() urr, Output() Input(). Only thing I can suggest
is to see if the old startup code is still supplied on the lattice disk, and
then link *only* with amiga.lib. Otherwise, you will have to rewrite the
program, you can probably yank the 'true' filehandle out of the iobuff
pointer.
That help? sdb
I found that I could get the file handles to stdin and stdout using Input()
and Outpt(). I still wonder whether there's a way to get a file handle from
a level 2 file pointer. I couldn't find it in the listing of iobuf in the
sdtio.h, but I'm still new at this.
You can convert from any level file handle down. From Level2 to level1, just
use fileno(fp). To go from level1 to level0, use: chkufb(fn)->ufbfh This
also corresponds to the AmigaDos file handle. Note that this will work with
3.10 or 4.0 even though all the underlying I/O is different. Have fun.