int rdfopen(rdffile *f, const char *name) { FILE * fp; fp = fopen(name,"rb"); if (!fp) return rdf_errno = 1; /* error 1: file open error */ return rdfopenhere(f,fp,NULL,""); }
int rdfopen(rdffile * f, const char *name) { FILE *fp; fp = fopen(name, "rb"); if (!fp) return rdf_errno = RDF_ERR_OPEN; return rdfopenhere(f, fp, NULL, name); }
int rdl_openmodule(struct librarynode *lib, int moduleno, rdffile * f) { char buf[512]; int i, cmod, t; int32_t length; lib->referenced++; if (!lib->fp) { lib->fp = fopen(lib->name, "rb"); if (!lib->fp) { lib->referenced--; return (rdl_error = 1); } } else rewind(lib->fp); cmod = -1; while (!feof(lib->fp)) { strcpy(buf, lib->name); i = strlen(buf); buf[i++] = '.'; t = i; while (fread(buf + i, 1, 1, lib->fp) == 1 && i < 512 && buf[i]) i++; buf[i] = 0; if (feof(lib->fp)) break; if (buf[t] != '.') /* special module - not counted in the numbering */ cmod++; /* of RDOFF modules - must be referred to by name */ if (cmod == moduleno) { rdl_error = 16 * rdfopenhere(f, lib->fp, &lib->referenced, buf); lib->referenced--; if (!lib->referenced) { fclose(lib->fp); lib->fp = NULL; } return rdl_error; } nasm_read(buf, 6, lib->fp); buf[6] = 0; if (buf[t] == '.') { /* do nothing */ } else if (strncmp(buf, "RDOFF", 5)) { if (!--lib->referenced) { fclose(lib->fp); lib->fp = NULL; } return rdl_error = 2; } else if (buf[5] != '2') { if (!--lib->referenced) { fclose(lib->fp); lib->fp = NULL; } return rdl_error = 3; } nasm_read(&length, 4, lib->fp); fseek(lib->fp, length, SEEK_CUR); /* skip over the module */ } if (!--lib->referenced) { fclose(lib->fp); lib->fp = NULL; } return rdl_error = 4; /* module not found */ }
int rdl_searchlib(struct librarynode *lib, const char *label, rdffile * f) { char buf[512]; int i, t; void *hdr; rdfheaderrec *r; int32_t l; rdl_error = 0; lib->referenced++; if (!lib->fp) { lib->fp = fopen(lib->name, "rb"); if (!lib->fp) { rdl_error = 1; return 0; } } else rewind(lib->fp); while (!feof(lib->fp)) { /* * read the module name from the file, and prepend * the library name and '.' to it. */ strcpy(buf, lib->name); i = strlen(lib->name); buf[i++] = '.'; t = i; while (fread(buf + i, 1, 1, lib->fp) == 1 && i < 512 && buf[i]) i++; buf[i] = 0; if (feof(lib->fp)) break; if (!strcmp(buf + t, ".dir")) { /* skip over directory */ nasm_read(&l, 4, lib->fp); fseek(lib->fp, l, SEEK_CUR); continue; } /* * open the RDOFF module */ if (rdfopenhere(f, lib->fp, &lib->referenced, buf)) { rdl_error = 16 * rdf_errno; return 0; } /* * read in the header, and scan for exported symbols */ hdr = nasm_malloc(f->header_len); rdfloadseg(f, RDOFF_HEADER, hdr); while ((r = rdfgetheaderrec(f))) { if (r->type != 3) /* not an export */ continue; if (!strcmp(r->e.label, label)) { /* match! */ nasm_free(hdr); /* reset to 'just open' */ f->header_loc = NULL; /* state... */ f->header_fp = 0; return 1; } } /* find start of next module... */ i = f->eof_offset; rdfclose(f); fseek(lib->fp, i, SEEK_SET); } /* * close the file if nobody else is using it */ lib->referenced--; if (!lib->referenced) { fclose(lib->fp); lib->fp = NULL; } return 0; }