stdioのヘルプ・マニュアル
日本語 英語
stdio --help
man stdio
STDIO(3) Linux Programmer’s Manual STDIO(3)
名前
stdio - 標準入出力ライブラリ関数
書式
#include
FILE *stdin;
FILE *stdout;
FILE *stderr;
説明
標 準入出力ライブラリは、簡単かつ効果のよい、バッファリングされたストリ
ーム入出力インターフェースを提供する。入力と出力は論理データストリー ム
に 割り付けられ、入出力の物理的な特徴は隠蔽される。このライブラリに属す
る関数とマクロを以下に挙げる。より詳しい情報は個々の man ページから得る
ことができる。
ファイルを オープン (open) することによって、ストリームは外部ファイル (
通常は物理デバイス) に連結される。この操作には新しくファイルを作成す る
こ とも含まれる。既存のファイルと同じ名前のファイルを新たに作ると、もと
のファイルの中身が捨てられてしまう。ファイルが位置指定リクエストをサ ポ
ー トしている (ディスクファイルなどが相当する。逆の例としては端末が挙げ
られる) 場合、そのストリームに連結された ファイル位置指示子 (file posi-
tion indicator) は、追加モードで開かれない限りファイルの先頭 (0 バイト
目) に位置する。追加モードを使用した場合、位置指示子をファイルの先頭 に
置 かれるか末尾に置かれるかは規定されていない。位置指示子は、以降の読み
書きや位置指定リクエストによって変更される。すべての入力は 、 fgetc(3)
関 数を次々に呼び出して文字を読み込んだかのように行われる。一方すべての
出力は、 fputc(3) 関数を次々に呼び出して文字を書き込んだかのように行 わ
れる。
フ ァイルを クローズ (close) することによって、そのファイルはストリーム
から切り離される。出力ストリームは、そのストリームがファイルから切り 離
さ れる前にフラッシュされる (書き込まれていないすべてのバッファの内容が
ホスト環境に転送される)。 FILE オブジェクトへのポインタの値は、ファイル
を閉じた後では不確定になる (ゴミになってしまう)。
フ ァイルはその後 (同じまたは別のプログラムによって) 再びオープンされる
こともあり、その内容が修正されたり変更されたりする (そのファイルで先 頭
へ の 位置移動が可能であれば)。 main 関数がもとの呼び出し側に返ったり、
exit(3) 関数が呼ばれた場合、プログラムの終了の前に現在開いているすべ て
の ファイルは閉じられる (その結果、すべての出力ストリームはフラッシュさ
れる)。プログラムの停止に abort(3) のような他の方法を用いた場合には、フ
ァイルが正しく閉じられる保証はない。
プログラムの起動時に 3 個のテキストストリームが予め定義されており、それ
らは明示的に開く必要がない。 — 標準入力 (standard input) (通常の入力 を
読み取るのに使う)、— 標準出力 (standard output) (通常の出力を書き込むの
に使う)、 標準エラー出力 (standard error) (診断出力を書き込むのに使 う)
である。これらのストリームは stdin, stdout, stderr と短縮して表現される
。オープンされたときには、標準エラーストリームは完全にはバッファリン グ
さ れていない。標準入力ストリームと標準出力ストリームは、ストリームがイ
ンタラクティブなデバイスを参照していなければ、完全にバッファリングさ れ
ている。
端 末デバイスを参照する出力ストリームは、デフォルトでは常に行単位でバッ
ファリングされている。ただしそのようなストリームにおけるバッファ内の 出
力 は、端末デバイスを参照している入力ストリームからの読み込みがあるたび
に、自動的に書き込まれる。出力端末に行の一部を書き込んだ後で大量の計 算
を 行う場合、出力が表示されるように、計算に取りかかる前に標準出力に対し
て fflush(3) を実行する必要がある。
stdio ライブラリは libc ライブラリの一部であり、ルーチンはコンパイラ ー
cc(1) と pc(1) によって必要な時に自動的に読み込まれる。後述する man ペ
ージ中の「書式」の節には、どのインクルードファイルを使用しなければな ら
な いか、その関数のコンパイラー宣言はどのようなものか、どのような外部変
数が関係するのかが示されている。
BUFSIZ, EOF, FILENAME_MAX, FOPEN_MAX, L_cuserid, L_ctermid, L_tmpnam,
NULL, SEEK_END, SEEK_SET, SEEK_CUR, TMP_MAX, clearerr, feof, ferror,
fileno, getc, getchar, putc, putchar, stderr, stdin, stdout はマクロ と
し て定義されている。これらの名前は、現在の定義を #undef で削除しない限
り、再利用することはできない。マクロ関数の関数版として、 feof, ferror,
clearerr, fileno, getc, getchar, putc, putchar がある。マクロの定義が明
示的に消去されている場合には、これらを使用することになるだろう。
関数のリスト
関数 説明
-------------------------------------------------------------------
clearerr ストリームの状態の確認とリセット
fclose ストリームをクローズする
fdopen ストリームをオープンする
feof ストリームの状態の確認とリセット
ferror ストリームの状態の確認とリセット
fflush ストリームをフラッシュする
fgetc 次の文字または語を入力ストリームから獲得する
fgetpos ストリームの位置を取得する
fgets ストリームから行を取得する
fileno 引き数であるストリームの整数値のディスクリプタを返す
fopen ストリームをオープンする
fprintf 書式付き出力変換
fpurge ストリームをフラッシュする
fputc 文字または語をストリームに出力する
fputs 行をストリームに出力する
fread バイナリーストリーム入出力
freopen ストリームをオープンする
fscanf 書式付き入力変換
fseek ストリームの位置指示子を移動する
fsetpos ストリームの位置指示子を移動する
ftell ストリームの位置を取得する
fwrite バイナリーストリーム入出力
getc 次の文字または語を入力ストリームから取得する
getchar 次の文字または語を入力ストリームから取得する
gets 行を入力ストリームから取得する
getw 次の文字または語を入力ストリームから取得する
mktemp 他と重ならないテンポラリファイル名を作る
perror システムエラーメッセージ
printf 書式付き出力変換
putc 文字または語をストリームに出力する
putchar 文字または語をストリームに出力する
puts 行をストリームに出力する
putw 文字または語をストリームに出力する
remove ディレクトリエントリを削除する
rewind ストリームの位置指示子を移動する
scanf 書式付き入力変換
setbuf ストリームのバッファリングの操作
setbuffer ストリームのバッファリングの操作
setlinebuf ストリームのバッファリングの操作
setvbuf ストリームのバッファリングの操作
sprintf 書式付き出力変換
sscanf 書式付き入力変換
strerror システムエラーメッセージ
sys_errlist システムエラーメッセージ
sys_nerr システムエラーメッセージ
tempnam テンポラリファイルの操作
tmpfile テンポラリファイルの操作
tmpnam テンポラリファイルの操作
ungetc 入力ストリームへ 1 文字戻す。
vfprintf 書式付き出力変換
vfscanf 書式付き入力変換
vprintf 書式付き出力変換
vscanf 書式付き入力変換
vsprintf 書式付き出力変換
vsscanf 書式付き入力変換
準拠
stdio ライブラリは C89 に準拠している。
関連項目
close(2), open(2), read(2), write(2), stdout(3), unlocked_stdio(3)
2001-12-26 STDIO(3)
STDIO(3) Linux Programmer’s Manual STDIO(3)
NAME
stdio - standard input/output library functions
SYNOPSIS
#include
FILE *stdin;
FILE *stdout;
FILE *stderr;
DESCRIPTION
The standard I/O library provides a simple and efficient buffered
stream I/O interface. Input and output is mapped into logical data
streams and the physical I/O characteristics are concealed. The func-
tions and macros are listed below; more information is available from
the individual man pages.
A stream is associated with an external file (which may be a physical
device) by opening a file, which may involve creating a new file. Cre-
ating an existing file causes its former contents to be discarded. If
a file can support positioning requests (such as a disk file, as
opposed to a terminal) then a file position indicator associated with
the stream is positioned at the start of the file (byte zero), unless
the file is opened with append mode. If append mode is used, it is
unspecified whether the position indicator will be placed at the start
or the end of the file. The position indicator is maintained by subse-
quent reads, writes and positioning requests. All input occurs as if
the characters were read by successive calls to the fgetc(3) function;
all output takes place as if all characters were written by successive
calls to the fputc(3) function.
A file is disassociated from a stream by closing the file. Output
streams are flushed (any unwritten buffer contents are transferred to
the host environment) before the stream is disassociated from the file.
The value of a pointer to a FILE object is indeterminate after a file
is closed (garbage).
A file may be subsequently reopened, by the same or another program
execution, and its contents reclaimed or modified (if it can be reposi-
tioned at the start). If the main function returns to its original
caller, or the exit(3) function is called, all open files are closed
(hence all output streams are flushed) before program termination.
Other methods of program termination, such as abort(3) do not bother
about closing files properly.
At program startup, three text streams are predefined and need not be
opened explicitly — standard input (for reading conventional input), —
standard output (for writing conventional input), and standard error
(for writing diagnostic output). These streams are abbreviated
stdin,stdout and stderr. When opened, the standard error stream is not
fully buffered; the standard input and output streams are fully
buffered if and only if the streams do not to refer to an interactive
device.
Output streams that refer to terminal devices are always line buffered
by default; pending output to such streams is written automatically
whenever an input stream that refers to a terminal device is read. In
cases where a large amount of computation is done after printing part
of a line on an output terminal, it is necessary to fflush(3) the stan-
dard output before going off and computing so that the output will
appear.
The stdio library is a part of the library libc and routines are auto-
matically loaded as needed by the compilers cc(1) and pc(1). The SYN-
OPSIS sections of the following manual pages indicate which include
files are to be used, what the compiler declaration for the function
looks like and which external variables are of interest.
The following are defined as macros; these names may not be re-used
without first removing their current definitions with #undef: BUFSIZ,
EOF, FILENAME_MAX, FOPEN_MAX, L_cuserid, L_ctermid, L_tmpnam, NULL,
SEEK_END, SEEK_SET, SEEK_CUR, TMP_MAX, clearerr, feof, ferror, fileno,
getc, getchar, putc, putchar, stderr, stdin, stdout. Function versions
of the macro functions feof, ferror, clearerr, fileno, getc, getchar,
putc, and putchar exist and will be used if the macros definitions are
explicitly removed.
List of Functions
Function Description
-------------------------------------------------------------------
clearerr check and reset stream status
fclose close a stream
fdopen stream open functions
feof check and reset stream status
ferror check and reset stream status
fflush flush a stream
fgetc get next character or word from input stream
fgetpos reposition a stream
fgets get a line from a stream
fileno return the integer descriptor of the argument stream
fopen stream open functions
fprintf formatted output conversion
fpurge flush a stream
fputc output a character or word to a stream
fputs output a line to a stream
fread binary stream input/output
freopen stream open functions
fscanf input format conversion
fseek reposition a stream
fsetpos reposition a stream
ftell reposition a stream
fwrite binary stream input/output
getc get next character or word from input stream
getchar get next character or word from input stream
gets get a line from a stream
getw get next character or word from input stream
mktemp make temporary filename (unique)
perror system error messages
printf formatted output conversion
putc output a character or word to a stream
putchar output a character or word to a stream
puts output a line to a stream
putw output a character or word to a stream
remove remove directory entry
rewind reposition a stream
scanf input format conversion
setbuf stream buffering operations
setbuffer stream buffering operations
setlinebuf stream buffering operations
setvbuf stream buffering operations
sprintf formatted output conversion
sscanf input format conversion
strerror system error messages
sys_errlist system error messages
sys_nerr system error messages
tempnam temporary file routines
tmpfile temporary file routines
tmpnam temporary file routines
ungetc un-get character from input stream
vfprintf formatted output conversion
vfscanf input format conversion
vprintf formatted output conversion
vscanf input format conversion
vsprintf formatted output conversion
vsscanf input format conversion
CONFORMING TO
The stdio library conforms to C89.
SEE ALSO
close(2), open(2), read(2), write(2), stdout(3), unlocked_stdio(3)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
2001-12-26 STDIO(3)