, readDataToEndOfFile , tail , tail -f (stdout). C I/O, FileTailer, . - , , . FileTailer.h, FileTailer.m .
. , ( ) ; EOF , ( refresh), .
- (void)readIndefinitely:(void (^)(int ch))action
{
long pos = 0L;
int ch = 0;
while (1) {
fseek(in, pos, SEEK_SET);
int ch = fgetc(in);
pos = ftell(in);
if (ch != EOF) {
action(ch);
} else {
[NSThread sleepForTimeInterval:refresh];
}
}
}
, :
FileTailer *tail = [[[FileTailer alloc] initWithStream:stdin refreshPeriod:3.0] autorelease];
[tail readIndefinitely:^ void (int ch) { printf("%c", ch); }];
(: FileTailer , , , , , à la tail -f.)