get an arbitrarily large line of text from a file More...
Functions | |
CGUL_BEGIN_C CGUL_EXPORT int | cgul_get_line (cgul_exception_t *cex, FILE *f, cgul_string_t s) |
CGUL_EXPORT int | cgul_get_line_relaxed (cgul_exception_t *cex, FILE *f, cgul_string_t s) |
Get an arbitrarily large line of text from a file.
CGUL_BEGIN_C CGUL_EXPORT int cgul_get_line | ( | cgul_exception_t * | cex, |
FILE * | f, | ||
cgul_string_t | s | ||
) |
Read an arbitrarily long line of text from f
and append it to s
. A line of text is terminated by '\n' only. Supporting just what the platform strictly considers to be an EOL
allows this method to be much faster than cgul_get_line_relaxed()
. On success, 1 is returned. On EOF, 0 is returned. If an error occurs, 0 is returned and an exception is thrown.
If you are reading directly from a block device, e.g., a traditional file, you can use cgul_crlf_file
which is even faster than this function and, unlike this function, is capable of reading text files in DOS, Mac, and Unix formats; however, it does require that you can read your file in large blocks.
[in,out] | cex | c-style exception |
[in] | f | input file |
[in] | s | where to store the text |
CGUL_EXPORT int cgul_get_line_relaxed | ( | cgul_exception_t * | cex, |
FILE * | f, | ||
cgul_string_t | s | ||
) |
Read an arbitrarily long line of text from f
and append it to s
. It is more relaxed in what it allows as the EOL
sequence. A line of text is terminated by "\n", "\r", or "\r\n". Support for the three main EOL
conventions allows you to read in text files generated by most common operating systems. On success, 1 is returned. On EOF, 0 is returned. If an error occurs, 0 is returned and an exception is thrown.
If you are reading directly from a block device, e.g., a regular file, you can use cgul_crlf_file
which is very fast (even faster than cgul_get_line()
above) and also capable of reading text files in DOS, Mac, and Unix formats; however, it does require that you can read your file in large blocks.
[in,out] | cex | c-style exception |
[in] | f | input file |
[in] | s | where to store the line of text |