fopen()

含义:Open a PSL channel to a file(打开一个PSL的管道指向某个文件)

Format

fopen(filename,mode,[shr=upd])

Parameters

Parameter

Definition

filename

name of the file to which the PSL channel should be opened.

mode

file access mode


Valid Values
r:open for read
w:truncate to zero length for write or create file for write
a:open for append to end of file or create for write
rb:open binary file for read
wb:truncate binary file to zero length for write or create binary file for write
ab:open binary file for append at end of file or create binary file for write
r+:open for read and write (update)
w+:truncate to zero length for read and write or create for read and write
a+:open for read and write at end of file or create file for read and write
r+b:open binary file for read and write (update)
w+b:truncate binary file to zero length for read and write or create binary file for read and write
a+b:open binary file for read and write at end of file or create binary file for read and write

shr=upd

literal switch used only with PATROL Agent for OpenVMS


Use this switch to open a file so that another process can write to it. For more information, see the documentation for OpenVMS.


Note: When creating a new file on OpenVMS, the default behavior is in effect; a file is created with a new version number.

Description

The fopen() function opens a channel to filename that provides the access to filename from within a PSL process. The read(), readln(), write(), get_chan_info(),share(), fseek(), ftell(), and close() functions apply to channels that have been opened to files. When supported by the underlying operating system, the fopen() function performs security checks to determine whether the user name of the calling process has permission for the request. The valid range of mode is the same as for the ANSI C fopen() function.If the fopen() function is successful, it returns the PSL channel number to filename.A failure to open filename, such as an operating system problem or invalid mode, sets the PSL errno value and causes the fopen() function to return the NULL string without attempting to open the file. The fopen() function behaves much like the ANSI C fopen() function.

Example

Code:

readchan = fopen("/etc/passwd","r");
print("readchan number is: ",readchan,"\n");

Output:

BMC PSL function(24)-fopen()_fopen()