MCPcopy Create free account
hub / github.com/Kitware/VTK / loadMem

Function loadMem

ThirdParty/libxml2/vtklibxml2/runtest.c:480–508  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

478}
479
480static int loadMem(const char *filename, const char **mem, int *size) {
481 int fd, res;
482 struct stat info;
483 char *base;
484 int siz = 0;
485 if (stat(filename, &info) < 0)
486 return(-1);
487 base = malloc(info.st_size + 1);
488 if (base == NULL)
489 return(-1);
490 if ((fd = open(filename, RD_FLAGS)) < 0) {
491 free(base);
492 return(-1);
493 }
494 while ((res = read(fd, &base[siz], info.st_size - siz)) > 0) {
495 siz += res;
496 }
497 close(fd);
498#if !defined(_WIN32)
499 if (siz != info.st_size) {
500 free(base);
501 return(-1);
502 }
503#endif
504 base[siz] = 0;
505 *mem = base;
506 *size = siz;
507 return(0);
508}
509
510static int unloadMem(const char *mem) {
511 free((char *)mem);

Callers 5

pushParseTestFunction · 0.85
pushBoundaryTestFunction · 0.85
memParseTestFunction · 0.85
streamMemParseTestFunction · 0.85
c14nRunTestFunction · 0.85

Calls 2

closeFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected