OSDN Git Service

(split) LDP: Update releases based on LDP 3.52 release
[linuxjm/LDP_man-pages.git] / release / 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 .TH GETLINE 3 2013\-04\-19 GNU "Linux Programmer's Manual"
32 .SH 名前
33 getline, getdelim \- 区切り文字までの文字列入力を読み込む
34 .SH 書式
35 .nf
36 \fB#include <stdio.h>\fP
37 .sp
38 \fBssize_t getline(char **\fP\fIlineptr\fP\fB, size_t *\fP\fIn\fP\fB, FILE *\fP\fIstream\fP\fB);\fP
39
40 \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
41 .fi
42 .sp
43 .in -4n
44 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
45 .in
46 .sp
47 .ad l
48 \fBgetline\fP(), \fBgetdelim\fP():
49 .PD 0
50 .RS 4
51 .TP  4
52 glibc 2.10 以降:
53 _POSIX_C_SOURCE\ >=\ 200809L || _XOPEN_SOURCE\ >=\ 700
54 .TP 
55 glibc 2.10 より前:
56 _GNU_SOURCE
57 .RE
58 .PD
59 .ad
60 .SH 説明
61 \fBgetline\fP()  は \fIstream\fP から 1 行全てを読み込み、テキストが含まれているバッファのアドレスを \fI*lineptr\fP
62 に格納する。 バッファはヌル文字 (\e0) で終端される。 改行文字が見つかった場合は、改行文字もバッファに格納される。
63
64 \fI*lineptr\fP が NULL の場合、 \fBgetline\fP()  は行の内容を格納するためのバッファを確保する。
65 このバッファはユーザーのプログラムで解放すべきである (この場合、 \fI*n\fP の値は無視される)。
66
67 別の方法として、 \fBgetline\fP()  を呼び出す際に、 \fI*lineptr\fP に \fBmalloc\fP(3)  で確保した大きさ \fI*n\fP
68 バイトのバッファへのポインタを入れて渡すこともできる。 読み込んだ行を保持するのに十分なバッファがない場合、 \fBgetline\fP()  は
69 \fBrealloc\fP(3)  を使ってバッファのサイズを変更し、必要に応じて \fI*lineptr\fP と \fI*n\fP を更新する。
70
71 どちらの場合でも、呼び出しに成功したときには、 \fI*lineptr\fP と \fI*n\fP がバッファのアドレスと割り当てたサイズを反映した値に更新される。
72
73 \fBgetdelim\fP()  は \fBgetline\fP()  と同じように動作するが、改行文字以外の区切り文字を引き数 \fIdelim\fP
74 に指定することができる。 \fBgetline\fP()  と同様に、ファイル終端に達するまでに入力行に区切り文字が見付からない場合は、
75 区切り文字をバッファに追加しない。
76 .SH 返り値
77 On success, \fBgetline\fP()  and \fBgetdelim\fP()  return the number of characters
78 read, including the delimiter character, but not including the terminating
79 null byte (\(aq\e0\(aq).  This value can be used to handle embedded null
80 bytes in the line read.
81
82 Both functions return \-1 on failure to read a line (including end\-of\-file
83 condition).  In the event of an error, \fIerrno\fP is set to indicate the
84 cause.
85 .SH エラー
86 .TP 
87 \fBEINVAL\fP
88 引き数が不正である (\fIn\fP または \fIlineptr\fP が NULL である。 もしくは \fIstream\fP が有効でない)。
89 .SH バージョン
90 これらの関数は libc 4.6.27 以降で利用可能である。
91 .SH 準拠
92 \fBgetline\fP()  と \fBgetdelim\fP()  は、どちらも元は GNU による拡張であったが、 POSIX.1\-2008
93 で標準化された。
94 .SH 例
95 .nf
96 #define _GNU_SOURCE
97 #include <stdio.h>
98 #include <stdlib.h>
99
100 int
101 main(void)
102 {
103     FILE *fp;
104     char *line = NULL;
105     size_t len = 0;
106     ssize_t read;
107
108     fp = fopen("/etc/motd", "r");
109     if (fp == NULL)
110         exit(EXIT_FAILURE);
111
112     while ((read = getline(&line, &len, fp)) != \-1) {
113         printf("Retrieved line of length %zu :\en", read);
114         printf("%s", line);
115     }
116
117     free(line);
118     exit(EXIT_SUCCESS);
119 }
120 .fi
121 .SH 関連項目
122 \fBread\fP(2), \fBfgets\fP(3), \fBfopen\fP(3), \fBfread\fP(3), \fBgets\fP(3), \fBscanf\fP(3)
123 .SH この文書について
124 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.52 の一部
125 である。プロジェクトの説明とバグ報告に関する情報は
126 http://www.kernel.org/doc/man\-pages/ に書かれている。