#include #include #include "stl.h" /* load a STL file and return a pointer to the stl_t struct */ stl_t * stl_load(const char * filename) { struct stat s; if (stat(filename, &s)) return NULL; int size = s.st_size; if (size < sizeof(stl_t)) return NULL; FILE *fil; if ((fil = fopen(filename, "rb")) == NULL) return NULL; stl_t * stl = (stl_t *) malloc(s.st_size); fread(stl, 1, s.st_size, fil); fclose(fil); if (s.st_size < sizeof(stl_t) + sizeof(stl_face_t) * (stl_num_faces(stl)-1)) { free(stl); return NULL; } return stl; }