cgul_get_line.h File Reference

get an arbitrarily large line of text from a file More...

#include "cgul_common.h"
#include "cgul_exception.h"
#include "cgul_string.h"
Include dependency graph for cgul_get_line.h:
This graph shows which files directly or indirectly include this file:

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)
 

Detailed Description

Get an arbitrarily large line of text from a file.

Author
Paul Serice
See also
cgul_crlf__get_line()
cgul_crlf_file__get_line()

Function Documentation

§ cgul_get_line()

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.

Parameters
[in,out]cexc-style exception
[in]finput file
[in]swhere to store the text
Returns
whether EOF was not reached

§ cgul_get_line_relaxed()

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.

Parameters
[in,out]cexc-style exception
[in]finput file
[in]swhere to store the line of text
Returns
whether EOF was not reached