Initial Steps
Create a directory libsrc/fcntl/machine_id
Required Functions
The following functions are required to be
implemented for full file I/O support.
int open(far char *name, int flags, mode_t mode);
int creat(far char *name, mode_t mode);
int close(int fd);
size_t read(int fd, void *ptr, size_t len);
size_t write(int fd, void *ptr, size_t len);
long lseek(int fd,long posn, int whence);
The purpose of these functions should be obvious, if your target
doesn't support far pointers then they can be cast to near pointers
inside the open/creat functions.
int open_z88(far char *name, int flags, mode_t
mode, char *explicit, size_t len);
This is a non-standard routine and on most machines will probably just
call open() however this provides the facility to return the explicit
file name (which is placed in explicit, up to a maximum length len)
extern int __FASTCALL__ readbyte(int fd);
This function reads a byte from filehandle fd (which is supplied in the
register pair hl), if an error occurred it should return EOF (-1) and
return with carry set. Otherwise it should return with carry reset and
hl holding the byte just read.
extern int writebyte(int fd, int c);
This function writes byte c to filehandle fd, once more if an error
occurs it should return EOF and carry set, otherwise hl holds the byte
just written and carry is reset.
void fabandon(FILE *fp);
Abandon file with the handle fd - this is called by the system on
program exit should it not be able to close a file. This function is a
dummy function on the many platforms but for example on the Spectrum +3
this function would be of use. NB. A dummy function is located in
z88dk/libsrc/stdio, but if it is implemented on your machine then it
should be placed in fcntl.
Once you have supplied the above functions the
entire z88dk stdio library is available to you (including printf etc)
in addition to all the ctype, string, assert, setjmp, near malloc, some
stdlib and the generic math
routines - just a little work yields over 100 usable functions!
|