static int pe_load_def(TCCState *s1, int fd) { int state = 0, ret = -1, dllindex = 0, ord; char line[400], dllname[80], *p, *x; FILE *fp; fp = fdopen(dup(fd), "rb"); while (fgets(line, sizeof line, fp)) { p = trimfront(trimback(line, strchr(line, 0))); if (0 == *p || ';' == *p) continue; switch (state) { case 0: if (0 != strnicmp(p, "LIBRARY", 7)) goto quit; pstrcpy(dllname, sizeof dllname, trimfront(p+7)); ++state; continue; case 1: if (0 != stricmp(p, "EXPORTS")) goto quit; ++state; continue; case 2: dllindex = add_dllref(s1, dllname); ++state; /* fall through */ default: /* get ordinal and will store in sym->st_value */ ord = 0; x = strchr(p, ' '); if (x) { *x = 0, x = strrchr(x + 1, '@'); if (x) { char *d; ord = (int)strtol(x + 1, &d, 10); if (*d) ord = 0; } } /* strip param bytes number */ if (*p != '?') { x = strrchr(p, '@'); if (x) { char *d; strtol(x + 1, &d, 10); if (*d == 0) *x = 0; } } pe_putimport(s1, dllindex, p, ord); continue; } } ret = 0; quit: fclose(fp); return ret; }