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"
35 getline, getdelim \- 区切り文字までの文字列入力を読み込む
40 .BI "ssize_t getline(char **" lineptr ", size_t *" n ", FILE *" stream );
42 .BI "ssize_t getdelim(char **" lineptr ", size_t *" n ", int " delim \
48 .RB ( feature_test_macros (7)
59 _POSIX_C_SOURCE\ >=\ 200809L || _XOPEN_SOURCE\ >=\ 700
68 は \fIstream\fP から 1 行全てを読み込み、テキストが含まれているバッファのアドレスを
71 バッファはヌル文字 (\e0) で終端される。
72 改行文字が見つかった場合は、改行文字もバッファに格納される。
77 は行の内容を格納するためのバッファを確保する。
78 このバッファはユーザーのプログラムで解放すべきである
91 バイトのバッファへのポインタを入れて渡すこともできる。
92 読み込んだ行を保持するのに十分なバッファがない場合、
96 を使ってバッファのサイズを変更し、必要に応じて
102 どちらの場合でも、呼び出しに成功したときには、
106 がバッファのアドレスと割り当てたサイズを反映した値に更新される。
111 と同じように動作するが、改行文字以外の区切り文字を引き数
115 と同様に、ファイル終端に達するまでに入力行に区切り文字が見付からない場合は、
123 文字数には区切り文字は含まれるが、終端に使う NULL バイトは含まれない。
124 この値によって、読み込んだ行に含まれる NULL バイトを操作することができる。
126 どちらの関数も、行の読み込みに失敗した場合には \-1 を返す
127 (ファイルの終端に達した場合にも \-1 を返す)。
140 これらの関数は libc 4.6.27 以降で利用可能である。
145 は、どちらも元は GNU による拡張であったが、
146 POSIX.1-2008 で標準化された。
161 fp = fopen("/etc/motd", "r");
165 while ((read = getline(&line, &len, fp)) != \-1) {
166 printf("Retrieved line of length %zu :\en", read);