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

Function compareFileMem

ThirdParty/libxml2/vtklibxml2/runtest.c:418–478  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

416}
417
418static int compareFileMem(const char *filename, const char *mem, int size) {
419 int res;
420 int fd;
421 char bytes[4096];
422 int idx = 0;
423 struct stat info;
424
425 if (update_results) {
426 if (size == 0) {
427 unlink(filename);
428 return(0);
429 }
430 fd = open(filename, WR_FLAGS, 0644);
431 if (fd < 0) {
432 fprintf(stderr, "failed to open %s for writing", filename);
433 return(-1);
434 }
435 res = write(fd, mem, size);
436 close(fd);
437 return(res != size);
438 }
439
440 if (stat(filename, &info) < 0) {
441 if (size == 0)
442 return(0);
443 fprintf(stderr, "failed to stat %s\n", filename);
444 return(-1);
445 }
446 if (info.st_size != size) {
447 fprintf(stderr, "file %s is %ld bytes, result is %d bytes\n",
448 filename, (long) info.st_size, size);
449 return(-1);
450 }
451 fd = open(filename, RD_FLAGS);
452 if (fd < 0) {
453 fprintf(stderr, "failed to open %s for reading", filename);
454 return(-1);
455 }
456 while (idx < size) {
457 res = read(fd, bytes, 4096);
458 if (res <= 0)
459 break;
460 if (res + idx > size)
461 break;
462 if (memcmp(bytes, &mem[idx], res) != 0) {
463 int ix;
464 for (ix=0; ix<res; ix++)
465 if (bytes[ix] != mem[idx+ix])
466 break;
467 fprintf(stderr,"Compare error at position %d\n", idx+ix);
468 close(fd);
469 return(1);
470 }
471 idx += res;
472 }
473 close(fd);
474 if (idx != size) {
475 fprintf(stderr,"Compare error index %d, size %d\n", idx, size);

Callers 12

pushParseTestFunction · 0.85
pushBoundaryTestFunction · 0.85
memParseTestFunction · 0.85
errParseTestFunction · 0.85
fdParseTestFunction · 0.85
streamProcessTestFunction · 0.85
xmlidDocTestFunction · 0.85
uriCommonTestFunction · 0.85
schemasOneTestFunction · 0.85
rngTestFunction · 0.85
c14nRunTestFunction · 0.85
regexpTestFunction · 0.85

Calls 4

fprintfFunction · 0.85
writeFunction · 0.85
closeFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected