annotate src/ggets.h @ 62:301805d68a97 default tip

Clean up better.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 06 Jan 2015 04:33:07 +0200
parents 785057719d9b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /* File ggets.h - goodgets is a safe alternative to gets */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 /* By C.B. Falconer. Public domain 2002-06-22 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 /* attribution appreciated. */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 /* Revised 2002-06-26 New prototype.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 2002-06-27 Incomplete final lines
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 /* fggets and ggets [which is fggets(ln, stdin)] set *ln to
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 a buffer filled with the next complete line from the text
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 stream f. The storage has been allocated within fggets,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 and is normally reduced to be an exact fit. The trailing
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 \n has been removed, so the resultant line is ready for
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 dumping with puts. The buffer will be as large as is
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 required to hold the complete line.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 Note: this means a final file line without a \n terminator
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 has an effective \n appended, as EOF occurs within the read.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 If no error occurs fggets returns 0. If an EOF occurs on
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 the input file, EOF is returned. For memory allocation
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 errors some positive value is returned. In this case *ln
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 may point to a partial line. For other errors memory is
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 freed and *ln is set to NULL.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 Freeing of assigned storage is the callers responsibility
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 #ifndef ggets_h_
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 # define ggets_h_
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 # ifdef __cplusplus
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 extern "C" {
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 # endif
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 int fggets(char* *ln, FILE *f);
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 #define ggets(ln) fggets(ln, stdin)
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 # ifdef __cplusplus
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 }
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 # endif
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 #endif
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 /* END ggets.h */