1 .\" Copyright (c) 2001 John Levon <moz@compsoc.man.ac.uk>
2 .\" Based in part on GNU libc documentation
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" Japanese Version Copyright (c) 2001 Yuichi SATO
26 .\" all rights reserved.
27 .\" Translated 2001-11-09, Yuichi SATO <ysato@h4.dion.ne.jp>
28 .\" Updated 2006-07-20, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.34
29 .\" Updated 2010-04-18, Akihiro MOTOKI, LDP v3.24
31 .\"WORD: delimiter 区切り文字
33 .TH GETLINE 3 2010-06-12 "GNU" "Linux Programmer's Manual"
36 .\"O getline, getdelim \- delimited string input
37 getline, getdelim \- 区切り文字までの文字列入力を読み込む
43 .BI "ssize_t getline(char **" lineptr ", size_t *" n ", FILE *" stream );
45 .BI "ssize_t getdelim(char **" lineptr ", size_t *" n ", int " delim \
50 .\"O Feature Test Macro Requirements for glibc (see
51 .\"O .BR feature_test_macros (7)):
53 .RB ( feature_test_macros (7)
63 .\"O Since glibc 2.10:
65 _POSIX_C_SOURCE\ >=\ 200809L || _XOPEN_SOURCE\ >=\ 700
67 .\"O Before glibc 2.10:
76 .\"O reads an entire line from \fIstream\fP,
77 .\"O storing the address of the buffer containing the text into
80 は \fIstream\fP から 1 行全てを読み込み、テキストが含まれているバッファのアドレスを
83 .\"O The buffer is null-terminated and includes the newline character, if
85 バッファはヌル文字 (\e0) で終端される。
86 改行文字が見つかった場合は、改行文字もバッファに格納される。
92 .\"O will allocate a buffer for storing the line,
93 .\"O which should be freed by the user program.
94 .\"O (In this case, the value in
100 は行の内容を格納するためのバッファを確保する。
101 このバッファはユーザーのプログラムで解放すべきである
106 .\"O Alternatively, before calling
109 .\"O can contain a pointer to a
110 .\"O .BR malloc (3)\-allocated
122 バイトのバッファへのポインタを入れて渡すこともできる。
123 .\"O If the buffer is not large enough to hold the line,
126 .\"O .BR "realloc(3)" ,
132 読み込んだ行を保持するのに十分なバッファがない場合、
136 を使ってバッファのサイズを変更し、必要に応じて
142 .\"O In either case, on a successful call,
146 .\"O will be updated to reflect the buffer address and allocated size respectively.
147 どちらの場合でも、呼び出しに成功したときには、
151 がバッファのアドレスと割り当てたサイズを反映した値に更新される。
156 .\"O except that a line delimiter other than newline can be specified as the
162 と同じように動作するが、改行文字以外の区切り文字を引き数
167 .\"O a delimiter character is not added if one was not present
168 .\"O in the input before end of file was reached.
170 と同様に、ファイル終端に達するまでに入力行に区切り文字が見付からない場合は、
172 .\"O .SH "RETURN VALUE"
178 .\"O return the number of characters read, including the delimiter character,
179 .\"O but not including the terminating null byte.
180 .\"O This value can be used
181 .\"O to handle embedded null bytes in the line read.
187 文字数には区切り文字は含まれるが、終端に使う NULL バイトは含まれない。
188 この値によって、読み込んだ行に含まれる NULL バイトを操作することができる。
190 .\"O Both functions return \-1 on failure to read a line (including end-of-file
192 どちらの関数も、行の読み込みに失敗した場合には \-1 を返す
193 (ファイルの終端に達した場合にも \-1 を返す)。
215 .\"O These functions are available since libc 4.6.27.
216 これらの関数は libc 4.6.27 以降で利用可能である。
217 .\"O .SH "CONFORMING TO"
223 .\"O were originally GNU extensions.
224 .\"O They were standardized in POSIX.1-2008.
228 は、どちらも元は GNU による拡張であったが、
229 POSIX.1-2008 で標準化された。
245 fp = fopen("/etc/motd", "r");
249 while ((read = getline(&line, &len, fp)) != \-1) {
250 printf("Retrieved line of length %zu :\en", read);