Goto: 4C Home | 4C Docs | System PCLs List sys.open_file()

sys.open_file()

Purpose:
sys.open_file() allows you to open a file before it is needed for file access.
Usage:
sys.open_file(<asfile>,<flags>);
Arguments:

asfile <asfile> - The asfile name of the file to open.

integer <flags> - Open flags. These can be or'd together with '|'. Possible values for the flags are:
Returns:
0 - File opened OK.
-1 - Some Error
Where Used:
sys.open_file() can be called from anywhere. It most likely will be used when you want to create a file if it does not yet exist, or to determine existence of a file before you try to do something to it.
Example:
The bootstrap program sys.ph.maint uses the following code in the edittext() pcl. It assumes that if the text file does not exist it should create it.

if (sys.open_file(sys.pcl_text,F_DEFAULT|F_NOMSG) < 0)
    sys.open_file(sys.pcl_text,F_CREATE);
Description:
sys.open_file() allows you to open files before they are automatically opened at file access time. If the asfile is already opened, possibly under a different ext name, it will be closed first. If the F_TEMP flag is specified, a temporary file is created. You do not need to specify both F_TEMP and F_CREATE. If the F_CREATE flag is specified without F_TEMP, then the file is created in the first directory of the data path. If neither F_CREATE nor F_TEMP are specified, then F_DEFAULT is assumed. This just opens the file. The F_SAVEBUF flag is used to specify that 4C saves the original field values after each read. You may want to do this if you will be calling sys.rcd_changed() or if you will be calling sys.upd_file() on many rcds that may not have changed. When F_SAVEBUF is used, sys.upd_file() will not actually rewrite any rcds that did not change. Error messages can be suppressed by using the F_NOMSG flag. The F_TRANS and F_NOTRANS flags can be used to override the default transaction logging for files that support this.

If there is an error opening the file, sys.errno will be set to one of:
Bugs/Features/Comments:
sys.open_file() does not set sys.errno for external database files.
See Also:
sys.close_file()
sys.create_file()
sys.create_tfile()
sys.read_file()


Back to Top