Skip to content

Instantly share code, notes, and snippets.

@ecto
Last active December 16, 2015 06:48
Show Gist options
  • Select an option

  • Save ecto/5393759 to your computer and use it in GitHub Desktop.

Select an option

Save ecto/5393759 to your computer and use it in GitHub Desktop.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) {
char line[80];
FILE *fr;
NSString *path = @"/path/to/long/file";
struct stat info;
stat([path UTF8String], &info);
off_t lastSize = info.st_size;
fr = fopen([path UTF8String], "rt");
fseek(fr, 0, SEEK_END);
while (1) {
stat([path UTF8String], &info);
off_t nowSize = status.st_size;
if (nowSize > lastSize) {
lastSize = nowSize;
while (ftell(fr) < nowSize) {
memset(&line[0], 0, sizeof(line));
fgets(line, 80, fr);
NSData *data = [NSData dataWithBytes:line length:sizeof(line)];
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@", string);
}
}
}
fclose(fr);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment