Cleanup and simplify get_reason() and related functions
Rename randreason() to fread_random() to better reflect its function, and change it to a one-pass algorithm. Have it write into a caller-provided buffer instead of a static buffer. Fixes a file leak when an empty file is given to this function. Change freadln() so that it never returns an empty line - it only returns 0 at end-of-file now. This simplifies its callers. Factor out some common code from the several get_reason()-type functions, which greatly simplifies them.
This commit is contained in:
@@ -4012,10 +4012,10 @@ FILE *f;
|
||||
{
|
||||
char *hst = NULL;
|
||||
buffer = alloca(sb.st_size+1);
|
||||
freadln(f, buffer);
|
||||
freadln(f, buffer, sb.st_size + 1);
|
||||
while(!feof(f))
|
||||
{
|
||||
if ((freadln(f, buffer)))
|
||||
if ((freadln(f, buffer, sb.st_size + 1)))
|
||||
{
|
||||
if (*buffer == '#')
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user