home *** CD-ROM | disk | FTP | other *** search
- #include <implement.cf>
- #include <language.cf>
- #include <status.cf>
- pragma data(common,_Private_prefix "dosregs");
- /* DON'T TOUCH THIS REGISTER STRUCTURE. It matches that in msdos.cf. */
- typedef union {
- struct {char L,H;} LH; /* Lower & Upper portions of 16-bit register. */
- unsigned R; /* Entire register. */
- } Register;
- Register AX,BX,CX,DX,SI,DI,DS,ES;
- /* The rightmost bit of Flags is the carry bit. MS-DOS usually sets */
- /* carry if an error occurs. */
- /* Thus, if Flags is odd on return, an error occurred; */
- /* ax contains the error number #. */
- unsigned Flags;
- pragma data;
- /*
- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- >> WARNING!!! The run-time library uses this Registers <<
- >> variable. So DO NOT expect it to be preserved across calls to <<
- >> the library that require DOS communication (e.g., Professional Pascal <<
- >> "writeln" or High C "printf"). <<
- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- */
- #if ! _system_defs_included
-
- typedef unsigned int File_handle; /* Small integer file handle. */
- typedef enum{From_beginning,From_current,From_end} Seek_method;
- typedef enum{Compatibility,Deny_read_write,Deny_write,Deny_read,Deny_none}
- Sharing_mode_type;
- /* Use data pragma to share with Pascal system.pf package: */
- pragma data(common,"?" _Private_prefix "system");
- Sharing_mode_type Sharing_mode; /* Initialized to Compatibility. */
- pragma data;
- typedef enum{For_reading, For_writing, For_updating} Open_method;
- /* File attributes: */
- #define Attr_read_only 1 /* File may not be modified. */
- #define Attr_hidden 2 /* File is hidden. */
- #define Attr_system 4 /* File is a "system" file. */
- #define Attr_volume_id 8 /* File is the volume id. */
- #define Attr_directory 16 /* File is a directory. */
- #define Attr_archive 32 /* File has not been archived. */
- #ifdef CDOS
- #define Attr_security 64 /* File has security enabled. */
- #endif
- typedef unsigned char File_mode; /* A set of the above bits. */
-
- extern int errno;
- pragma Calling_convention(PASCAL);
- extern void _mwc_dos_name(char *Name, unsigned char I);
- extern void _mwdos(unsigned char I);
- extern void _mwload_ds_dx(void *A);
- pragma Calling_convention(_DEFAULT_CALLING_CONVENTION);
-
- /*
- NOTE: Following every call, the imported variable errno contains the
- status of the call. If zero, then the call was successful, otherwise
- it will contain one of the error codes specified after each
- routine declaration below.
- */
-
- /* Close file whose handle is "F". */
- int close(File_handle F) {
- int save = errno; errno = 0;
- BX.R = F; _mwdos(62);
- int error_occurred = errno != 0 ? -1 : 0;
- if (errno == 0) errno = save;
- return error_occurred;
- }
-
- /* Create file "name" and open it for writing. */
- /* NOTE!!! The Mode is NOT For_reading, For_writing, or For_updating, */
- /* but is a combination of attribute bits such as Attr_hidden, Attr_archive, */
- /* etc. Usually you should specify Mode = 0. */
- File_handle creat(char *Name, File_mode Mode) {
- CX.R = Mode; /* was retype (Mode, Byte) */
- int save = errno; errno = 0;
- _mwc_dos_name(Name,60);
- if (errno) return -1;
- else {
- errno = save;
- return AX.R;
- }
- }
-
- /* Reposition the file pointer assoicated with "F" to location "Loc" */
- /* according to the method specified in "Method". */
- /* Return the new position. */
- long lseek(File_handle F, long Loc, Seek_method Method) {
- union Addr {long L; struct{short int Lo, Hi;}Bits;} A;
- A.L=Loc;
- BX.R = F; AX.LH.L = Method;
- CX.R=A.Bits.Hi;
- DX.R=A.Bits.Lo;
- _mwdos(66);
- A.Bits.Hi = DX.R;
- A.Bits.Lo = AX.R;
- return A.L;
- }
-
- /* Open file "Name" for reading, writing, or updating. */
-
- File_handle open(char *Name, Open_method Method) {
- AX.LH.L = (Sharing_mode << 4) | Method;
- int save = errno; errno = 0;
- _mwc_dos_name(Name,61);
- if (errno) return -1;
- else {
- errno = save;
- return AX.R;
- }
- }
-
- /* Read "Cnt" bytes from file "F" into buffer whose address is "Bufp". */
- /* Returns the number of bytes actually read. */
- unsigned read(File_handle F, void *Buf, unsigned Cnt) {
- _mwload_ds_dx(Buf);
- CX.R = Cnt;
- BX.R = F;
- _mwdos(63);
- return(AX.R);
- }
-
- /* Erase file from directory. */
- void unlink(char *Name) {
- _mwc_dos_name(Name,65);
- }
-
- /* Write "Cnt" bytes from buffer whose address is "Bufp" into file "F". */
- /* Note: If disk overflow occurs, Errno will have the value Error_disk_overflow */
- /* and Write will return with the number of bytes actually written. */
-
- unsigned write(File_handle F, void *Buf, unsigned Cnt) {
- _mwload_ds_dx(Buf);
- CX.R = Cnt;
- BX.R = F;
- _mwdos(64);
- if ((AX.R < Cnt) && (errno == No_error_occurred))
- errno = Error_write_failed;
- return(AX.R);
- }
-
- #define _system_defs_included 1
- #endif