OSDN Git Service

Address unmatch newlines in special ja.po
[linuxjm/LDP_man-pages.git] / draft / man3 / getline.3
1 .\" Copyright (c) 2001 John Levon <moz@compsoc.man.ac.uk>
2 .\" Based in part on GNU libc documentation
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\"*******************************************************************
27 .\"
28 .\" This file was generated with po4a. Translate the source file.
29 .\"
30 .\"*******************************************************************
31 .\"
32 .\" Japanese Version Copyright (c) 2001 Yuichi SATO
33 .\"         all rights reserved.
34 .\" Translated 2001-11-09, Yuichi SATO <ysato@h4.dion.ne.jp>
35 .\" Updated 2006-07-20, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.34
36 .\" Updated 2010-04-18, Akihiro MOTOKI, LDP v3.24
37 .\" Updated 2013-07-22, Akihiro MOTOKI <amotoki@gmail.com>
38 .\"
39 .TH GETLINE 3 2015\-01\-22 GNU "Linux Programmer's Manual"
40 .SH 名前
41 getline, getdelim \- 区切り文字までの文字列入力を読み込む
42 .SH 書式
43 .nf
44 \fB#include <stdio.h>\fP
45 .sp
46 \fBssize_t getline(char **\fP\fIlineptr\fP\fB, size_t *\fP\fIn\fP\fB, FILE *\fP\fIstream\fP\fB);\fP
47
48 \fBssize_t getdelim(char **\fP\fIlineptr\fP\fB, size_t *\fP\fIn\fP\fB, int \fP\fIdelim\fP\fB, FILE *\fP\fIstream\fP\fB);\fP
49 .fi
50 .sp
51 .in -4n
52 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
53 .in
54 .sp
55 .ad l
56 \fBgetline\fP(), \fBgetdelim\fP():
57 .PD 0
58 .RS 4
59 .TP  4
60 glibc 2.10 以降:
61 _POSIX_C_SOURCE\ >=\ 200809L || _XOPEN_SOURCE\ >=\ 700
62 .TP 
63 glibc 2.10 より前:
64 _GNU_SOURCE
65 .RE
66 .PD
67 .ad
68 .SH 説明
69 \fBgetline\fP()  は \fIstream\fP から 1 行全てを読み込み、テキストが含まれているバッファーのアドレスを \fI*lineptr\fP
70 に格納する。 バッファーはヌル文字 (\e0) で終端される。 改行文字が見つかった場合は、改行文字もバッファーに格納される。
71
72 \fI*lineptr\fP が NULL にセットされ、 \fI*n\fP が呼び出し前に 0 にセットされた場合、 \fBgetline\fP()
73 は行の内容を格納するためのバッファーを確保する。 このバッファーは、 \fBgetline\fP()
74 が失敗した場合であっても、ユーザーのプログラムで解放すべきである。
75
76 別の方法として、 \fBgetline\fP()  を呼び出す際に、 \fI*lineptr\fP に \fBmalloc\fP(3)  で確保した大きさ \fI*n\fP
77 バイトのバッファーへのポインターを入れて渡すこともできる。 読み込んだ行を保持するのに十分なバッファーがない場合、 \fBgetline\fP()  は
78 \fBrealloc\fP(3)  を使ってバッファーのサイズを変更し、必要に応じて \fI*lineptr\fP と \fI*n\fP を更新する。
79
80 どちらの場合でも、呼び出しに成功したときには、 \fI*lineptr\fP と \fI*n\fP
81 がバッファーのアドレスと割り当てたサイズを反映した値に更新される。
82
83 \fBgetdelim\fP()  は \fBgetline\fP()  と同じように動作するが、改行文字以外の区切り文字を引き数 \fIdelim\fP
84 に指定することができる。 \fBgetline\fP()  と同様に、ファイル終端に達するまでに入力行に区切り文字が見付からない場合は、
85 区切り文字をバッファーに追加しない。
86 .SH 返り値
87 成功した場合、 \fBgetline\fP()  と \fBgetdelim\fP()  は読み込んだ文字数を返す。
88 文字数には区切り文字は含まれるが、終端に使うヌルバイト (\(aq\e0\(aq) は含まれない。
89 この値によって、読み込んだ行に含まれるヌルバイトを操作することができる。
90
91 どちらの関数も、行の読み込みに失敗した場合には \-1 を返す (ファイルの終端に達した場合にも \-1 を返す)。 エラーが発生した場合には、
92 \fIerrno\fP にエラーの原因を示す値が設定される。
93 .SH エラー
94 .TP 
95 \fBEINVAL\fP
96 引き数が不正である (\fIn\fP または \fIlineptr\fP が NULL である。 もしくは \fIstream\fP が有効でない)。
97 .SH 準拠
98 \fBgetline\fP()  と \fBgetdelim\fP()  は、どちらも元は GNU による拡張であったが、 POSIX.1\-2008
99 で標準化された。
100 .SH 例
101 .nf
102 #define _GNU_SOURCE
103 #include <stdio.h>
104 #include <stdlib.h>
105
106 int
107 main(void)
108 {
109     FILE *stream;
110     char *line = NULL;
111     size_t len = 0;
112     ssize_t read;
113
114     stream = fopen("/etc/motd", "r");
115     if (stream == NULL)
116         exit(EXIT_FAILURE);
117
118     while ((read = getline(&line, &len, stream)) != \-1) {
119         printf("Retrieved line of length %zu :\en", read);
120         printf("%s", line);
121     }
122
123     free(line);
124     fclose(stream);
125     exit(EXIT_SUCCESS);
126 }
127 .fi
128 .SH 関連項目
129 \fBread\fP(2), \fBfgets\fP(3), \fBfopen\fP(3), \fBfread\fP(3), \fBscanf\fP(3)
130 .SH この文書について
131 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.78 の一部
132 である。プロジェクトの説明とバグ報告に関する情報は
133 http://www.kernel.org/doc/man\-pages/ に書かれている。