STACK_OF(X509)* sk;
FILE* in;
int content = 0;
- char buf[128];
+ long flen;
if(file == NULL || strcmp(file, "") == 0) {
return NULL;
}
#endif
return NULL;
}
+ if(fseek(in, 0, SEEK_END) < 0)
+ printf("%s fseek: %s\n", file, strerror(errno));
+ flen = ftell(in);
+ if(fseek(in, 0, SEEK_SET) < 0)
+ printf("%s fseek: %s\n", file, strerror(errno));
while(!feof(in)) {
X509* x = PEM_read_X509(in, NULL, NULL, NULL);
if(x == NULL) {
exit(0);
}
content = 1;
- /* read away newline after --END CERT-- */
- if(!fgets(buf, (int)sizeof(buf), in))
+ /* feof may not be true yet, but if the position is
+ * at end of file, stop reading more certificates. */
+ if(ftell(in) == flen)
break;
}
fclose(in);