Skip to content

Instantly share code, notes, and snippets.

@waynerobinson
Created March 9, 2013 08:18
Show Gist options
  • Save waynerobinson/5123458 to your computer and use it in GitHub Desktop.
Save waynerobinson/5123458 to your computer and use it in GitHub Desktop.
static int performance_file_is_complete_if(char *filename_cp)
{
int bytes = 0;
int nl = 0;
int first_character = TRUE;
char c;
char line[READ_BUFFER_SIZE];
FILE *fh_tp;
fh_tp = fopen(filename_cp, "r");
if(!fh_tp)
{
printf("INVALID FILE\n");
return 0;
}
/* Rewind from end of file until we see 2 x '\n'. */
fseek(fh_tp, -1, SEEK_END);
while(fseek(fh_tp, -2, SEEK_CUR) == 0) {
first_character = FALSE;
bytes++;
c = fgetc(fh_tp);
if ((c == '\n' && ++nl > 0) || READ_BUFFER_SIZE - bytes == 0) {
break;
}
}
/* If last character read not '\n' then we need one more for this to be a valid line. */
if (c != '\n') {
fseek(fh_tp, -1, SEEK_CUR);
}
fgets(line, sizeof line, fh_tp);
printf("LINE: %s\n", line);
fclose(fh_tp);
return(
line[0] == '"'
&& line[1] == 'Z'
&& line[2] == 'Z'
&& line[3] == '"'
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment