drain

drain — modifies end-of-file detection.

Syntax

drain (file, drain_p)

		

Arguments

file

An open file.

drain_p

A flag. If non-nil, sets the file to drain.

Returns

The previous state of the drain flag for this file.

Description

This function sets a flag on the file state such that if the drain_p flag is on, the first time that a read on that file finds no characters waiting, the read will return immediately with "Unexpected end of file". This is intended for use in situations where the operating system may never actually generate an end of file indication, but where it is known that no more input will be available once a read would block. This function does not affect dev_read.

For best results, the file should be unbuffered first with unbuffer_file. Otherwise characters will be read in buffer by buffer and held locally in groups of 1024. This could cause a read function to return "Unexpected end of file" even when there are still characters waiting to be read.

Example

Gamma> fp = open("mydrainfile.dat","r",nil);
#<File:"mydrainfile.dat">
Gamma> unbuffer_file(fp);
#<File:"mydrainfile.dat">
Gamma> drain(fp,t);
nil
Gamma> read_line(fp);
"This is my drain file."
Gamma> read_line(fp);
"Unexpected end of file"
Gamma>