Last active
December 16, 2015 06:48
-
-
Save ecto/5393759 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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