2.5 File Handling

The file-handling routines let you create, manipulate, and delete files. They also set and check file-access permissions.

File-handling routines work on a file designated by a path name or by a “file handle,” an integer assigned by the operating system that identifies an open file. These routines modify or give information about the designated file. Most of them are declared in the include file IO.H, with the exceptions being the _fstat and _stat functions (declared in SYS\STAT.H), the _fullpath routine (declared in DIRECT.H), and the remove and rename functions (also declared in STDIO.H).

Routine Use

_access Checks file-permission setting
_chmod Changes file-permission setting
_chsize Changes file size
_filelength Gets file length
_fstat Gets file-status information on handle
_fullpath Makes an absolute path name from a relative path name
_isatty Checks for character device
_locking Locks areas of file (available with DOS versions 3.0 and later)
_makepath Merges path-name components into a single, full path name
_mktemp Creates unique filename
remove Deletes file
rename Renames file
_setmode Sets file-translation mode
_splitpath Splits a path name into component pieces
_stat Gets file-status information on named file
_umask Sets default-permission mask
_unlink Deletes file

The _access, _chmod, _fullpath, _makepath, remove, rename, _splitpath, _stat, and _unlink routines operate on files specified by a path name or filename.

The _chsize, _filelength, _fstat, _isatty, _locking, and _setmode routines work with files designated by a file handle.

The _mktemp and _umask routines have functions that are slightly different from the other routines. The _mktemp routine creates a unique filename; you can use _mktemp to create unique filenames that do not conflict with the names of existing files. The _umask routine sets the default permission mask for any new files created in a program. The mask can override the permission setting given in the _open or _creat call for the new file.