Functions HI-TECH C OPEN
OPEN
SYNOPSIS
#include <unixio.h> int open(char * name, int mode)
DESCRIPTION
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:
[uid:][drive:]name.type
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:
fred.dat file.c 0:xyz.com 0:a:file1.p a:file2.
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:
lst: | Accesses the list device - write only |
pun: | Accesses the punch device - write only |
rdr: | Accesses the reader device - read only |
con: | 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.
fred.nrk A:\HITECH\STDIO.H
The special device names (e.g. CON, LST) are also
recognized. These do not require (and should not have)
a trailing colon.
SEE ALSO
close, fopen, fclose, read, write, creat