static inline id EnumerateFat()

in FBControlCore/Applications/FBBinaryDescriptor.m [122:152]


static inline id EnumerateFat(FILE *file, uint32_t fatMagic, id(^block)(struct fat_arch fatArch, uint32_t magic))
{
  // Get the Fat Header.
  struct fat_header header = ReadFatHeader(file, fatMagic);

  long fatArchPosition = sizeof(struct fat_header);
  for (uint32_t index = 0; index < header.nfat_arch; index++) {
    // Seek-to then get the Fat Arch info
    fseek(file, fatArchPosition, SEEK_SET);
    struct fat_arch fatArch;
    fread(&fatArch, sizeof(struct fat_arch), 1, file);
    if (IsSwap(fatMagic)) {
      swap_fat_arch(&fatArch, 1, 0);
    }

    // Seek to the start position of the arch
    fseek(file, fatArch.offset, SEEK_SET);
    uint32_t magic = GetMagic(file);
    if (!IsMagic(magic)){
      return nil;
    }

    // Call the block
    id value = block(fatArch, magic);
    if (value) {
      return value;
    }
    fatArchPosition += sizeof(struct fat_arch);
  }
  return nil;
}