Previous Topic

Next Topic

CloseCtFile

Close index or data file.

Short Name

CLSFIL()

Type

Low level file function

Declaration

COUNT CloseCtFile(COUNT filno, COUNT filmod)

Description

CloseCtFile() closes file number filno.

The filmod parameter is no longer used. It has been left in this definition solely for the sake of compatibility with older versions. If you have programs that were developed with older versions of c-tree Plus, you don’t have to change your CloseCtFile() function calls. For newer programs, you can leave it out, unless you are using function prototyping and receive a warning about having too few parameters. In this case either use a second parameter, which will be ignored, or change the function prototype definition in ctdecl.h.

If filno references an index file with additional index members, CloseCtFile() closes the primary index and its members.

CloseCtFile() ensures a file is properly closed so updates will be properly saved to disk. In low-level mode, data files are updated by NewData(), ReleaseData(), and WriteData(), and index files are updated by AddKey(), DeleteKey(), and DeleteKeyBlind().

Return

Value

Symbolic Constant

Explanation

0

NO_ERROR

Successful file close.

22

FNUM_ERR

File number out of range.

24

FCLS_ERR

Could not close file number isam_fil.

26

FACS_ERR

File number is not assigned to a file in use.

See c-tree Plus Error Codes for a complete listing of valid c-tree Plus error values.

Example

COUNT     filno = 0, retval;
TEXT      filnam[15] = "sample.dat";

if (retval = InitCtree(6,7,4))
    printf("\nCould not initialize. Error %d.", retval);
else {
    if (OpenCtFile(filno, filnam, (ctSHARED | ctVIRTUAL | ctFIXED)))
        printf("\nCould not open file.");
    else if (CloseCtFile(filno, 0))
        printf("\nCould not close file.");

    if (CloseISAM())
        printf("\nCould not close ISAM.");
}

See also

NewData(), ReleaseData(), WriteData(), AddKey(), DeleteKey(), DeleteKeyBlind(), OpenCtFile(), CreateDataFile(), CreateIndexFile()