| crackhdr(char *name, int mode) |
| if((fd = open(name, mode)) < 0) |
| if(seek(fd, 0, 0) < 0 || readn(fd, buf, 4) != 4){ |
| hdr = mallocz(sizeof(Fhdr), 1); |
| hdr->filename = strdup(name); |
| werrstr("magic doesn't match"); |
| for(i=0; i<nelem(cracktab); i++) |
| if(cracktab[i].magic == magic && seek(fd, 0, 0) == 0 && cracktab[i].fn(fd, hdr) >= 0){ |
| werrstr("unknown file type: %r"); |
| mapfile(Fhdr *fp, ulong base, Map *map, Regs **regs) |
| werrstr("cannot load map for this file type"); |
| return fp->map(fp, base, map, regs); |
| unmapfile(Fhdr *fp, Map *map) |
| if(map == nil || fp == nil) |
| for(i=0; i<map->nseg; i++){ |
| while(i<map->nseg && map->seg[i].fd == fp->fd){ |
| memmove(&map->seg[i], &map->seg[i+1], |
| (map->nseg-i)*sizeof(map->seg[0])); |