1 /* lkrel.c - .rel object file handling
3 Copyright (C) 1989-1995 Alan R. Baldwin
4 721 Berkeley St., Kent, Ohio 44240
5 Copyright (C) 2008-2009 Borut Razem, borut dot razem at siol dot net
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 * With contributions for the
23 * object libraries from
25 * kenh@cmf.nrl.navy.mil
30 * Extensions: P. Felber
44 long pos = ftell (libfp);
48 if (((c = getc (libfp)) == 'X' || c == 'D' || c == 'Q') && ((c = getc (libfp)) == 'H' || c == 'L'))
53 if (getc (libfp) == '\n')
65 if (fread (buf, 1, sizeof (buf), libfp) == sizeof (buf) && memcmp (buf, "!FILE ", 6) == 0)
68 fseek (libfp, pos, SEEK_SET);
72 /* Load a standalone or embedded .rel */
74 load_rel (FILE * libfp, long size)
81 end = (size >= 0) ? ftell (libfp) + size : -1;
83 while ((end < 0 || ftell (libfp) < end) && getline (str, sizeof (str), libfp) != NULL)
85 if (0 == strcmp (str, "</REL>"))
99 enum_symbols (FILE * fp, long size, int (*func) (const char *symvoid, void *param), void *param)
102 long end = (size >= 0) ? ftell (fp) + size : -1;
104 assert (func != NULL);
107 * Read in the object file. Look for lines that
108 * begin with "S" and end with "D". These are
109 * symbol table definitions. If we find one, see
110 * if it is our symbol. Make sure we only read in
111 * our object file and don't go into the next one.
114 while ((end < 0 || ftell (fp) < end) && getline (buf, sizeof (buf), fp) != NULL)
116 char symname[NINPUT];
120 * When a 'T line' is found terminate file scan.
121 * All 'S line's preceed 'T line's in .REL files.
127 * Skip everything that's not a symbol record.
132 sscanf (buf, "S %s %c", symname, &c);
134 /* If it's an actual symbol, record it */
137 if ((*func) (symname, param))