NASM 0.98p3.4
[nasm/avx512.git] / rdoff / rdlib.c
blobbc8d1e351883f567be8e80ee9092ef586ab887da
1 #include <stdio.h>
2 #include <stdlib.h>
4 #include "rdoff.h"
5 #include "rdlib.h"
7 int rdl_error = 0;
9 char *rdl_errors[3] = {
10 "no error","could not open file", "invalid file structure",
13 int rdl_searchlib (struct librarynode * lib,
14 const char * label, rdffile * f)
16 char buf[257];
17 int i;
18 void * hdr;
19 rdfheaderrec * r;
21 rdl_error = 0;
22 lib->referenced ++;
24 if (! lib->fp)
26 lib->fp = fopen(lib->name,"rb");
28 if (! lib->fp) {
29 rdl_error = 1;
30 return 0;
33 else
34 rewind(lib->fp);
36 while (! feof(lib->fp) )
38 i = 1;
39 while (fread(buf + i,1,1,lib->fp) == 1 && buf[i] && i < 257)
40 i++;
41 buf[0] = ':';
43 if (feof(lib->fp)) break;
45 if ( rdfopenhere(f,lib->fp,&lib->referenced,buf) ) {
46 rdl_error = 2;
47 return 0;
50 hdr = malloc(f->header_len);
51 rdfloadseg(f,RDOFF_HEADER,hdr);
53 while ((r = rdfgetheaderrec(f)))
55 if (r->type != 3) /* not an export */
56 continue;
58 if (! strcmp(r->e.label, label) ) /* match! */
60 free(hdr); /* reset to 'just open' */
61 f->header_loc = NULL; /* state... */
62 f->header_fp = 0;
63 return 1;
67 /* find start of next module... */
68 i = f->data_ofs + f->data_len;
69 rdfclose(f);
70 fseek(lib->fp,i,SEEK_SET);
73 lib->referenced --;
74 if (! lib->referenced)
76 fclose(lib->fp);
77 lib->fp = NULL;
79 return 0;
82 void rdl_perror(const char *apname, const char *filename)
84 fprintf(stderr,"%s:%s:%s\n",apname,filename,rdl_errors[rdl_error]);