sysopen FILEHANDLE, FILENAME, MODE, PERMS sysopen FILEHANDLE, FILENAME, MODE |
相当于基础C语言的操作系统调用open()。打开filename指定的文件,关联它到FILEHANDLE。mode参数指定文件应该如何被打开。模式的值是依赖于系统,但也使用过往的某些值。 0,1和2的值的意思分别是只读,只写和读/写。支持的值是在Fcntl模块,并总结如下表所示。请注意,文件名FILENAME 是严格意义上的文件名;任何解释的内容发生(不像打开),和打开的模式是由MODE参数定义。
如果文件被创建,O_CREAT标志被指定在MODE,然后在文件被创建PERMS的权限。在传统的Unix风格的十六进制的值PERMS必须指定。如果没有指定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.
0 - 失败时
1 - 成功时