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