Chinaunix首页 | 论坛 | 博客
  • 博客访问: 485179
  • 博文数量: 279
  • 博客积分: 4467
  • 博客等级: 上校
  • 技术积分: 2830
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-03 14:43
文章分类

全部博文(279)

文章存档

2013年(1)

2012年(39)

2011年(35)

2009年(29)

2008年(131)

2007年(44)

分类:

2008-04-18 10:19:42

sysopen
| |
  • sysopen FILEHANDLE,FILENAME,MODE
  • sysopen FILEHANDLE,FILENAME,MODE,PERMS

    Opens the file whose filename is given by FILENAME, and associates it with FILEHANDLE. If FILEHANDLE is an expression, its value is used as the name of the real filehandle wanted. This function calls the underlying operating system's function with the parameters FILENAME, MODE, PERMS.

    The possible values and flag bits of the MODE parameter are system-dependent; they are available via the standard module Fcntl . See the documentation of your operating system's to see which values and flag bits are available. You may combine several flags using the |-operator.

    Some of the most common values are O_RDONLY for opening the file in read-only mode, O_WRONLY for opening the file in write-only mode, and O_RDWR for opening the file in read-write mode.

    For historical reasons, some values work on almost every system supported by perl: zero means read-only, one means write-only, and two means read/write. We know that these values do not work under OS/390 & VM/ESA Unix and on the Macintosh; you probably don't want to use them in new code.

    If the file named by FILENAME does not exist and the call creates it (typically because MODE includes the O_CREAT flag), then the value of PERMS specifies the permissions of the newly created file. If you omit the PERMS argument to , Perl uses the octal value 0666 . These permission values need to be in octal, and are modified by your process's current .

    In many systems the O_EXCL flag is available for opening files in exclusive mode. This is not locking: exclusiveness means here that if the file already exists, sysopen() fails. O_EXCL may not work on network filesystems, and has no effect unless the O_CREAT flag is set as well. Setting O_CREAT|O_EXCL prevents the file from being opened if it is a symbolic link. It does not protect against symbolic links in the file's path.

    Sometimes you may want to truncate an already-existing file. This can be done using the O_TRUNC flag. The behavior of O_TRUNC with O_RDONLY is undefined.

    You should seldom if ever use 0644 as argument to , because that takes away the user's option to have a more permissive umask. Better to omit it. See the perlfunc(1) entry on for more on this.

    Note that depends on the fdopen() C library function. On many UNIX systems, fdopen() is known to fail when file descriptors exceed a certain value, typically 255. If you need more file descriptors than that, consider rebuilding Perl to use the sfio library, or perhaps using the POSIX::open() function.

    See for a kinder, gentler explanation of opening files.

阅读(615) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~