Jump to content

Perl Programming/Keywords/sysopen

From Wikibooks, open books for an open world
Previous: syscall Keywords Next: sysread

The sysopen keyword

[edit | edit source]

The sysopen command opens the file whose filename is given by FILEHANDLE, and associates it with the FILEHANDLE, which may be an expression where its value is the real filehandle. The function calls the open(2) function of the underlying operating system and depends on the fdopen() C library function.

Values of the MODE parametre are system-dependent and are available over the standard module Fcntl. These values are O_RDONLY (=0), O_WRONLY (=1), O_RDWR (=2) for opening the file read-only, write-only, and read-write, respectively. The values do not work on some operating systems, such as OS/390 and Macintosh.

Many systems support also the O_EXCL flag that opens the file in the exclusive mode, which does not mean a lock, but that if the file already exists, sysopen() fails. O_EXCL may not work on network filesystems, or if the O_CREAT flag is not set. The O_TRUNC can be used to truncate a file.

Syntax

[edit | edit source]
  sysopen FILEHANDLE, FILENAME, MODE
  sysopen FILEHANDLE, FILENAME, MODE, PERMISSIONS
syscall sysopen sysread sysseek system syswrite
Previous: syscall Keywords Next: sysread