Programming Guide



sm_fio_open

Opens the specified file and returns a handle to the JPL caller

int sm_fio_open(char *path, char *mode);

path
Path name of file to open.

mode
Describes the file type—binary or text—and type of access required, one of the following constants described in Table 5-6 in Description.

Returns

Description

sm_fio_open opens a file in the specified mode and returns an integer handle to a file stream that is accessible to other Panther library file I/O functions. Supply this handle to these functions for all subsequent I/O operations on the file stream.

Note: The file stream that is opened by sm_fio_open is not accessible to standard C library functions.

You can open a file in one of the modes shown in Table 5-6:

Table 5-6 File access modes

Mode identifier Access description

r

Open read-only text file.

rb

Open read-only binary file.

w

Create write-only text file.

wb

Create write-only binary file.

a

Open text file for append.

ab

Open binary file for append.

r+b

Open binary file for update.

w+b

Create binary file for update.

a+b

Open binary file for append or update.

If a server executes this command, it must have the necessary permissions for the requested operation to the specified path. For example, when a Web client issues sm_fio_open to create or open a file, the Web application server's user ID must have write permission to that file's directory.

Example

// this validation routine is attached to a 
// push button on a dialog screen that gets the
// user-entered name of a file and opens it

vars fileStream = SMFIO_INVALID_HANDLE
vars operation
receive BUNDLE mode DATA operation

if (operation == "w")
{
fileStream = getFileHandle(file, "w")
}
if (operation == "r")
{
fileStream = getFileHandle(file, "r")
}

// All-purpose routine for supplying file handles
proc getFileHandle(fileName, mode)
vars fileHandle
fileHandle = sm_fio_open(fileName, mode)
if fileHandle < 0
{
msg emsg "I/O error :fileHandle - reenter file name
sm_n_gofield("fileName")
}

if fileHandle >= 0
{
send BUNDLE f_handle DATA fileHandle
}
return