MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / findNthAtom

Function findNthAtom

xs/platforms/mc/xsHosts.c:470–503  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

468}
469
470char *findNthAtom(uint32_t atomTypeIn, int index, const uint8_t *xsb, int xsbSize, int *atomSizeOut)
471{
472 const uint8_t *atom = xsb, *xsbEnd = xsb + xsbSize;
473
474 if (0 == index) { // hack - only validate XS_A header at root...
475 if (c_read32be(xsb + 4) != FOURCC('X', 'S', '_', 'A'))
476 return NULL;
477
478 atom += 8;
479 }
480
481 while (atom < xsbEnd) {
482 int32_t atomSize = c_read32be(atom);
483 uint32_t atomType = c_read32be(atom + 4);
484
485 if ((atomSize < 8) || ((atom + atomSize) > xsbEnd))
486 return NULL;
487
488 if (atomType == atomTypeIn) {
489 index -= 1;
490 if (index <= 0) {
491 if (atomSizeOut)
492 *atomSizeOut = atomSize - 8;
493 return (char *)(atom + 8);
494 }
495 }
496 atom += atomSize;
497 }
498
499 if (atomSizeOut)
500 *atomSizeOut = 0;
501
502 return NULL;
503}
504
505#endif
506

Callers 4

findModFunction · 0.85
findModFunction · 0.85
findModFunction · 0.85
modGetModAtomFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected