void xs_system_get_timestamp(xsMachine *the) { MC_FILE *fp; struct img_hdr ih; xsSetInteger(xsResult, 0); if ((fp = mc_fopen("/mcufw", "ra")) != NULL) { if (mc_fread(&ih, sizeof(ih), 1, fp) == 1) xsSetInteger(xsResult, ih.time); mc_fclose(fp); } }
int mc_elf_open(const char *fname, struct mc_elf *elf) { long offset; memset(elf, 0, sizeof(elf)); if ((elf->f = mc_fopen(fname, "r")) == NULL) return -1; if (mc_fread(&elf->eh, sizeof(elf->eh), 1, elf->f) != 1) goto bail; if (memcmp(elf->eh.ident, "\177ELF", 4) != 0) goto bail; if (elf->eh.shentsize != sizeof(struct elf_sheader)) goto bail; offset = elf->eh.shoffset; mc_fseek(elf->f, offset, SEEK_SET); if ((elf->sh = mc_malloc(elf->eh.shentsize * elf->eh.shnum)) == NULL) goto bail; if (mc_fread(elf->sh, elf->eh.shentsize * elf->eh.shnum, 1, elf->f) != 1) goto bail; /* load the string table */ if (elf->eh.shstrndx >= elf->eh.shnum) goto bail; elf->strtabsz = elf->sh[elf->eh.shstrndx].size; if ((elf->strtab = mc_malloc(elf->strtabsz)) == NULL) goto bail; offset = elf->sh[elf->eh.shstrndx].offset; if (mc_fseek(elf->f, offset, SEEK_SET) == -1 || mc_fread(elf->strtab, elf->strtabsz, 1, elf->f) != 1) goto bail; return 0; bail: mc_elf_close(elf); return -1; }