gets
Section: C Library Functions (3)
Updated: 2026-02-08
Index
JM Home Page
roff page
名前
gets - 標準入力からの文字列を取得する (非推奨)
ライブラリ
標準 C ライブラリ (libc,~-lc)
書式
#include <stdio.h>
[[deprecated]] char *gets(char *s);
説明
この関数は使用しないこと。
gets() reads a line from stdin into the buffer pointed to by s
until either a terminating newline or EOF, which it replaces with a null
byte ('\0'). No check for buffer overrun is performed (see BUGS
below).
返り値
gets() は、成功すると s を返し、エラーや 1 文字も読み込んでいないのにファイルの終わりになった 場合に NULL を返す。
しかし、バッファーの行き過ぎのチェックが行われないため、この関数が返るという保証はない。
属性
この節で使用されている用語の説明については、 attributes(7) を参照。
| インターフェース | 属性 | 値
|
|
gets()
| Thread safety | MT-Safe
|
標準規格
POSIX.1-2008.
歴史
C89, POSIX.1-2001.
LSB deprecates gets(). POSIX.1-2008 marks gets() obsolescent. ISO
C11 removes the specification of gets() from the C language, and since
glibc 2.16, glibc header files don't expose the function declaration if the
_ISOC11_SOURCE feature test macro is defined.
バグ
gets() は絶対に使用してはならない。 前もってデータを知ることなしに gets() が何文字読むかを知ることはできず、
gets() がバッファーの終わりを越えて書き込み続けるため、 gets() を使うのは極めて危険である。
これを利用してコンピュータのセキュリティが破られてきた。 代わりに fgets() を使うこと。
詳しい情報については、CWE-242 (別名 "Use of Inherently Dangerous Function"
(「本質的に危険な関数を使う」)) を参照。 http://cwe.mitre.org/data/definitions/242.html
で参照できる。
関連項目
read(2), write(2), ferror(3), fgetc(3), fgets(3),
fgetwc(3), fgetws(3), fopen(3), fread(3), fseek(3),
getline(3), getwchar(3), puts(3), scanf(3), ungetwc(3),
unlocked_stdio(3), feature_test_macros(7)
Index
- 名前
-
- ライブラリ
-
- 書式
-
- 説明
-
- 返り値
-
- 属性
-
- 標準規格
-
- 歴史
-
- バグ
-
- 関連項目
-
This document was created by
man2html,
using the manual pages.