Perl sysopen 函数

  • 描述

    sysopen 函数等效于基础C和操作系统调用open()。打开由FILENAME指定的文件,并将其与FILEHANDLE关联。MODE参数指定应如何打开文件。MODE的值取决于系统,但是某些值是历史设置的。值0、1和2分别表示只读,只写和读/写。支持的值在Fcntl模块中可用,并在下表中进行了汇总。
    请注意,FILENAME严格来说是一个文件名;不对内容进行任何解释(与open不同),并且MODE参数定义了open的模式。
    如果必须创建文件,并且已在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。