9 * format of rdoff library files:
11 * null terminated module name (max 255 chars)
19 * No support exists yet for special modules. But we aren't using
20 * any special modules yet. They are only defined now so that their
21 * existance doesn't break older versions of the linker... presently
22 * anything whose name begins with '.' is ignored.
27 char *rdl_errors
[5] = {
28 "no error","could not open file", "invalid file structure",
29 "file contains modules of an unsupported RDOFF version",
32 int rdl_verify(const char * filename
)
34 FILE * fp
= fopen(filename
, "rb");
38 static char lastverified
[256];
39 static int lastresult
= -1;
41 if (lastresult
!= -1 && !strcmp(filename
, lastverified
))
44 strcpy(lastverified
, filename
);
47 return (rdl_error
= lastresult
= 1);
53 while (fread(buf
+ i
,1,1,fp
) == 1 && buf
[i
] && i
< 257)
61 * a special module, eg a directory.
62 * Format of such a module is defined to be:
63 * six char type identifier (which we've already read)
64 * long count bytes content
66 * so we can handle it uniformaly with RDOFF2 modules...
67 * do nothing here. :-)
70 else if (strncmp(buf
, "RDOFF", 5)) {
71 return rdl_error
= lastresult
= 2;
73 else if (buf
[5] != '2') {
74 return rdl_error
= lastresult
= 3;
77 fread(&length
, 4, 1, fp
);
78 fseek(fp
, length
, SEEK_CUR
); /* skip over the module */
81 return lastresult
= 0; /* library in correct format */
84 int rdl_open (struct librarynode
* lib
, const char * name
)
86 int i
= rdl_verify(name
);
90 lib
->name
= strdup(name
);
96 void rdl_close (struct librarynode
* lib
)
103 int rdl_searchlib (struct librarynode
* lib
,
104 const char * label
, rdffile
* f
)
117 lib
->fp
= fopen(lib
->name
,"rb");
127 while (! feof(lib
->fp
) )
130 * read the module name from the file, and prepend
131 * the library name and '.' to it.
133 strcpy(buf
, lib
->name
);
135 i
= strlen(lib
->name
);
136 buf
[i
++] = '.'; t
= i
;
137 while (fread(buf
+ i
,1,1,lib
->fp
) == 1 && buf
[i
] && i
< 512)
142 if (feof(lib
->fp
)) break;
143 if (!strcmp(buf
+ t
, ".dir")) /* skip over directory */
145 fread (&l
, 4, 1, lib
->fp
);
146 fseek (lib
->fp
, l
, SEEK_CUR
);
150 * open the RDOFF module
152 if ( rdfopenhere(f
,lib
->fp
,&lib
->referenced
,buf
) ) {
153 rdl_error
= 16 * rdf_errno
;
157 * read in the header, and scan for exported symbols
159 hdr
= malloc(f
->header_len
);
160 rdfloadseg(f
,RDOFF_HEADER
,hdr
);
162 while ((r
= rdfgetheaderrec(f
)))
164 if (r
->type
!= 3) /* not an export */
167 if (! strcmp(r
->e
.label
, label
) ) /* match! */
169 free(hdr
); /* reset to 'just open' */
170 f
->header_loc
= NULL
; /* state... */
176 /* find start of next module... */
179 fseek(lib
->fp
,i
,SEEK_SET
);
183 * close the file if nobody else is using it
186 if (! lib
->referenced
)
194 int rdl_openmodule (struct librarynode
* lib
, int moduleno
, rdffile
* f
)
204 lib
->fp
= fopen(lib
->name
, "rb");
207 return (rdl_error
= 1);
214 while (!feof(lib
->fp
))
216 strcpy(buf
, lib
->name
);
218 buf
[i
++] = '.'; t
= i
;
219 while (fread(buf
+ i
,1,1,lib
->fp
) == 1 && buf
[i
] && i
< 512)
222 if (feof(lib
->fp
)) break;
224 if (buf
[t
] != '.') /* special module - not counted in the numbering */
225 cmod
++; /* of RDOFF modules - must be referred to by name */
227 if (cmod
== moduleno
) {
229 rdfopenhere(f
, lib
->fp
, &lib
->referenced
, buf
);
231 if (!lib
->referenced
) {
238 fread(buf
, 6, 1, lib
->fp
);
243 else if (strncmp(buf
, "RDOFF", 5)) {
244 if (! --lib
->referenced
) {
248 return rdl_error
= 2;
250 else if (buf
[5] != '2') {
251 if (! --lib
->referenced
) {
255 return rdl_error
= 3;
258 fread(&length
, 4, 1, lib
->fp
);
259 fseek(lib
->fp
, length
, SEEK_CUR
); /* skip over the module */
261 if (! --lib
->referenced
) {
265 return rdl_error
= 4; /* module not found */
268 void rdl_perror(const char *apname
, const char *filename
)
271 rdfperror(apname
, filename
);
273 fprintf(stderr
,"%s:%s:%s\n",apname
,filename
,rdl_errors
[rdl_error
]);