Functions HI-TECH C OPEN

From HI-TECH C for CP/M Fan WIKI(EN)
Jump to: navigation, search



#include  <unixio.h>

int open(char * name, int mode)


Open() is the fundamental means of opening files for reading and writing. The file specified by name is sought, and if found is opened for reading, writing or both. Mode is encoded as follows:

Mode Meaning
0 Open for reading only
1 Open for writing only
2 Open for both reading and writing

The file must already exist - if it does not, creat() should be used to create it. On a successful open, a file descriptor is returned. This is a non-negative integer which may be used to refer to the open file subsequently. If the open fails, -1 is returned. The syntax of a CP/M filename is:


where uid is a decimal number 0 to 15, drive is a letter A to P or a to p, name is 1 to 8 characters and type is 0 to 3 characters. Though there are few inherent restrictions on the characters in the name and type, it is recommended that they be restricted to the alphanumerics and standard printing characters. Use of strange characters may cause problems in accessing and/or deleting the file.

One or both of uid: and drive: may be omitted; if both are supplied, the uid: must come first. Note that the [ and ] are meta-symbols only. Some examples are:


If the uid: is omitted, the file will be sought with uid equal to the current user number, as returned by getuid(). If drive: is omitted, the file will be sought on the currently selected drive. The following special file names are recognized:

Accesses the list device - write only
Accesses the punch device - write only
Accesses the reader device - read only
Accesses the system console - read/write

File names may be in any case - they are converted to upper case during processing of the name.

MS-DOS filenames may be any valid MS-DOS 2.xx filename, e.g.


The special device names (e.g. CON, LST) are also recognized. These do not require (and should not have) a trailing colon.


close, fopen, fclose, read, write, creat