Perl sysopen 函式



描述

此函式等效於底層的 C 和作業系統呼叫 open( )。開啟由 FILENAME 指定的檔案,將其與 FILEHANDLE 關聯。MODE 引數指定應如何開啟檔案。MODE 的值取決於系統,但某些值在歷史上是固定的。0、1 和 2 的值分別表示只讀、只寫和讀寫。受支援的值在 Fcntl 模組中可用,並在下表中進行了總結。

請注意,FILENAME 嚴格來說是一個檔名;不會對內容進行任何解釋(與 open 不同),並且開啟模式由 MODE 引數定義。

如果必須建立檔案,並且在 MODE 中指定了 O_CREAT 標誌,則使用 PERMS 的許可權建立檔案。PERMS 的值必須以傳統的 Unix 風格十六進位制指定。如果未指定 PERMS,則 Perl 使用預設模式 0666(使用者/組/其他具有讀/寫許可權)。

Flag		Description
O_RDONLY 	Read only.
O_WRONLY 	Write only.
O_RDWR 		Read and write.
O_CREAT		Create the file if it doesn.t already exist.
O_EXCL 		Fail if the file already exists.
O_APPEND 	Append to an existing file.
O_TRUNC 	Truncate the file before opening.
O_NONBLOCK 	Non-blocking mode.
O_NDELAY 	Equivalent of O_NONBLOCK.
O_EXLOCK 	Lock using flock and LOCK_EX.
O_SHLOCK 	Lock using flock and LOCK_SH.
O_DIRECTOPRY 	Fail if the file is not a directory.
O_NOFOLLOW 	Fail if the last path component is a symbolic link.
O_BINARY 	Open in binary mode (implies a call to binmode).
O_LARGEFILE 	Open with large (>2GB) file support.
O_SYNC 		Write data physically to the disk, instead of 
		write buffer.
O_NOCTTY 	Don't make the terminal file being opened 
	 	the processescontrolling terminal, even if you 
	 	don.t have one yet.

語法

以下是此函式的簡單語法:

sysopen FILEHANDLE, FILENAME, MODE, PERMS

sysopen FILEHANDLE, FILENAME, MODE

返回值

此函式在失敗時返回 0,成功時返回 1。

perl_function_references.htm
廣告
© . All rights reserved.