.\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de) .\" .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" License. .\" Modified Wed Jul 28 11:12:07 1993 by Rik Faith (faith@cs.unc.edu) .\" Modified Fri Sep 8 15:48:13 1995 by Andries Brouwer (aeb@cwi.nl) .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH GETS 3 2012\-01\-18 GNU "Linux Programmer's Manual" .SH 名前 fgetc, fgets, getc, getchar, gets, ungetc \- 文字と文字列の入力 .SH 書式 .nf \fB#include \fP .sp \fBint fgetc(FILE *\fP\fIstream\fP\fB);\fP \fBchar *fgets(char *\fP\fIs\fP\fB, int \fP\fIsize\fP\fB, FILE *\fP\fIstream\fP\fB);\fP \fBint getc(FILE *\fP\fIstream\fP\fB);\fP \fBint getchar(void);\fP \fBchar *gets(char *\fP\fIs\fP\fB);\fP \fBint ungetc(int \fP\fIc\fP\fB, FILE *\fP\fIstream\fP\fB);\fP .fi .SH 説明 \fBfgetc\fP() は、 \fIstream\fP から次の文字を \fIunsigned char\fP として読み、 \fIint\fP にキャストして返す。ファイルの終わりやエラーとなった場合は \fBEOF\fP を返す。 .PP \fBgetc\fP() は \fBfgetc\fP() と同様だが、 \fIstream\fP を複数回評価するマクロとして実装されているかもしれない。 .PP \fBgetchar\fP() は \fBgetc(\fP\fIstdin\fP\fB)\fP と同じである。 .PP \fBgets\fP() は、改行文字か \fBEOF\fP までの 1行を \fIstdin\fP から読み込み \fIs\fP が指すバッファに格納する (末尾の改行文字や \fBEOF\fP は NULL バイト (\(aq\e0\(aq) に置き換えられる)。 バッファオーバーランのチェックは行われない (下記の「バグ」を参照)。 .PP \fBfgets\fP() は \fIstream\fP から最大で \fIsize\fP \- 1 個の文字を読み込み、 \fIs\fP が指すバッファに格納する。読み込みは \fBEOF\fP または改行文字を読み込んだ後で停止する。 読み込まれた改行文字はバッファに格納される。 終端の NULL バイト (\(aq\e0\(aq) が一つバッファの中の最後の文字の後に書き込まれる。 .PP \fBungetc\fP() は、後の read 操作で読めるように、 \fIc\fP を \fIunsigned char\fP にキャストして \fIstream\fP に書き戻す。 書き戻された文字は逆順に戻される; 書き戻しとして保証されているのは、一文字だけである。 .PP ここで述べた関数や \fIstdio\fP ライブラリの入力関数を同じ入力ストリームに対して互いに混ぜて使うことができる。 .PP これらの処理を停止せずに行いたいときは、 \fBunlocked_stdio\fP(3) を参照のこと。 .SH 返り値 \fBfgetc\fP(), \fBgetc\fP(), \fBgetchar\fP() は、文字を \fIunsigned char\fP として読んで \fIint\fP にキャストして返す。ファイルの終わりやエラーの場合は \fBEOF\fP を返す。 .PP \fBgets\fP() と \fBfgets\fP() は、成功すると \fIs\fP を返し、エラーや 1 文字も読み込んでいないのにファイルの終わりになった 場合に NULL を返す。 .PP \fBungetc\fP() は成功すると \fIc\fP を返し、エラーの場合は \fBEOF\fP を返す。 .SH 準拠 C89, C99, POSIX.1\-2001. LSB は \fBgets\fP() を非推奨としている。 POSIX.1\-2008 では \fBgets\fP() に廃止予定の印が付けられている。 ISO C11 では \fBgets\fP)() の規定が C 言語から削除されている。 glibc バージョン 2.16 以降では、機能検査マシン \fB_ISOC11_SOURCE\fP が定義された 場合、glibc ヘッダファイルでは \fBgets\fP)() の宣言が公開されない。 .SH バグ \fBgets\fP() は絶対に使用してはならない。 前もってデータを知ることなしに \fBgets\fP() が何文字読むかを知ることはできず、 \fBgets\fP() がバッファの終わりを越えて書き込み続けるため、 \fBgets\fP() を使うのは極めて危険である。 これを利用してコンピュータのセキュリティが破られてきた。 代わりに \fBfgets\fP() を使うこと。 .PP 入力ストリームのファイルディスクリプタに対して、 \fIstdio\fP ライブラリの入力関数と、低レベル呼び出しの \fBread\fP(2) を混ぜて呼び出す事は勧められない。 結果がどうなるかは分からず、おそらくあなたの 望んでいる結果にはならないだろう。 .SH 関連項目 \fBread\fP(2), \fBwrite\fP(2), \fBferror\fP(3), \fBfgetwc\fP(3), \fBfgetws\fP(3), \fBfopen\fP(3), \fBfread\fP(3), \fBfseek\fP(3), \fBgetline\fP(3), \fBgetwchar\fP(3), \fBputs\fP(3), \fBscanf\fP(3), \fBungetwc\fP(3), \fBunlocked_stdio\fP(3), \fBfeature_test_macros\fP(7) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.41 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。