perl-5.38.0
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 real filehandle wanted; an undefined scalar will be suitably autovivified. This function calls the underlying operating system's open(2) function with the parameters FILENAME, MODE, and PERMS.

FILENAME で与えられたファイル名のファイルをオープンし、 FILEHANDLE と結び付けます。 FILEHANDLE が式の場合、その値は実際の求めているファイルハンドルの名前として 扱われます; 未定義のスカラは適切に自動有効化されます。 この関数呼び出しはシステムの open(2) 関数を FILENAME, MODE, PERMS の 引数で呼び出すことを基礎としています。

Returns true on success and undef otherwise.

成功時は真を、さもなければ undef を返します。

PerlIO layers will be applied to the handle the same way they would in an open call that does not specify layers. That is, the current value of ${^OPEN} as set by the open pragma in a lexical scope, or the -C commandline option or PERL_UNICODE environment variable in the main program scope, falling back to the platform defaults as described in "Defaults and how to override them" in PerlIO. If you want to remove any layers that may transform the byte stream, use binmode after opening it.

PerlIO 層は、層を指定しない open 呼び出しでするのと同じ方法でハンドルに適用されます。 これは、レキシカルスコープの open プラグマで設定された ${^OPEN} の現在の値、 またはメインプログラムスコープの -C コマンドラインオプションまたは PERL_UNICODE 環境変数、"Defaults and how to override them" in PerlIO で 記述されているようにプラットフォームのデフォルトに フォールバックしたものです。 バイトストリームを変換する全ての層を除去したい場合は、 それを開いた後に binmode を使ってください。

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 open(2) syscall to see which values and flag bits are available. You may combine several flags using the |-operator.

MODE パラメータに指定できるフラグビットと値はシステム依存です; これは標準モジュール Fcntl 経由で利用可能です。 どのようなフラグビットと値が利用可能であるかについては、 OS の open(2) システムコールに関する文書を参照してください。 | 演算子を使って複数のフラグを結合することができます。

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.

もっともよく使われる値は、ファイルを読み込み専用で開く O_RDONLY、 ファイルを書き込み専用で開く O_WRONLY、 ファイルを読み書き両用で開く O_RDWR です。

For historical reasons, some values work on almost every system supported by Perl: 0 means read-only, 1 means write-only, and 2 means read/write. We know that these values do not work under OS/390; you probably don't want to use them in new code.

歴史的な理由により、Perl が対応しているほとんどのシステムで使える値が あります:0 は読み込み専用、1 は書き込み専用、2 は読み書き両用を意味します。 OS/390 では動作 しない ことが分かっています; 新しく書くコードではこれらは使わないほうがよいでしょう。

If the file named by FILENAME does not exist and the open 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 sysopen, Perl uses the octal value 0666. These permission values need to be in octal, and are modified by your process's current umask.

FILENAME という名前のファイルが存在せず、(典型的には MODE が O_CREAT フラグを含んでいたために) open 呼び出しがそれを作った場合、 PERMS の値は新しく作られたファイルの権限を指定します。 sysopen の PERMS 引数を省略した場合、 Perl は 8 進数 0666 を使います。 これらの権限は 8 進数である必要があり、プロセスの現在の umask で修正されます。

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.

多くのシステムではファイルを排他モードで開くために O_EXCL が 利用可能です。 これはロック ではありません: 排他性というのは既にファイルが 存在していた場合、sysopen が 失敗することを意味します。 O_EXCL はネットワークファイルシステムでは動作せず、 またO_CREAT フラグも有効でない限りは効果がありません。 O_CREAT|O_EXCL をセットすると、これがシンボリックリンクだった場合は ファイルを開くことを妨げます。 これはファイルパス中のシンボリックリンクは守りません。

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.

既に存在しているファイルを切り詰めたい場合もあるかもしれません。 これは O_TRUNC フラグを使うことで行えます。 O_RDONLYO_TRUNC を同時に指定したときの振る舞いは未定義です。

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

めったなことでは sysopen の引数に 0644 を指定するべきではないでしょう: ユーザーがより寛大な umask を指定する選択肢を奪うからです。 省略した方がいいです。 これに関するさらなる情報については umask を 参照してください。

This function has no direct relation to the usage of sysread, syswrite, or sysseek. A handle opened with this function can be used with buffered IO just as one opened with open can be used with unbuffered IO.

この関数は、 sysread, syswrite, sysseek の使用法と 直接の関係はありません。 この関数で開かれたハンドルがバッファリングされた IO で使えるのと同様、 open で開かれたものは バッファリングされない IO で使えます。

Note that under Perls older than 5.8.0, sysopen depends on the fdopen(3) C library function. On many Unix systems, fdopen(3) is known to fail when file descriptors exceed a certain value, typically 255. If you need more file descriptors than that, consider using the POSIX::open function. For Perls 5.8.0 and later, PerlIO is (most often) the default.

5.8.0 より古い Perl では、 sysopen は C の fdopen(3) ライブラリ関数に依存していることに注意してください。 多くの Unix システムでは、fdopen(3) はファイル記述子がある値(例えば 255)を 超えると失敗することが知られています。 これより多くのファイル記述子が必要な場合は、 POSIX::open 関数を使うことを検討してください。 5.8.0 以降の Perl では、(ほぼ確実に) PerlIO がデフォルトです。

See perlopentut for a kinder, gentler explanation of opening files.

ファイルを開くことに関するより親切な説明については perlopentut を 参照してください。

Portability issues: "sysopen" in perlport.

移植性の問題: "sysopen" in perlport