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 3, 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, see <http://www.gnu.org/licenses/>. */
21 * With contributions for the
22 * object libraries from
24 * kenh@cmf.nrl.navy.mil
29 * Extensions: P. Felber
43 long pos = ftell (libfp);
47 if (((c = getc (libfp)) == 'X' || c == 'D' || c == 'Q') && ((c = getc (libfp)) == 'H' || c == 'L'))
52 if (getc (libfp) == '\n')
64 if (fread (buf, 1, sizeof (buf), libfp) == sizeof (buf) && memcmp (buf, "!FILE ", 6) == 0)
67 fseek (libfp, pos, SEEK_SET);
71 /* Load a standalone or embedded .rel */
73 load_rel (FILE * libfp, long size)
80 end = (size >= 0) ? ftell (libfp) + size : -1;
82 while ((end < 0 || ftell (libfp) < end) && getline (str, sizeof (str), libfp) != NULL)
84 if (0 == strcmp (str, "</REL>"))
98 enum_symbols (FILE * fp, long size, int (*func) (const char *symvoid, void *param), void *param)
101 long end = (size >= 0) ? ftell (fp) + size : -1;
103 assert (func != NULL);
106 * Read in the object file. Look for lines that
107 * begin with "S" and end with "D". These are
108 * symbol table definitions. If we find one, see
109 * if it is our symbol. Make sure we only read in
110 * our object file and don't go into the next one.
113 while ((end < 0 || ftell (fp) < end) && getline (buf, sizeof (buf), fp) != NULL)
115 char symname[NINPUT];
119 * When a 'T line' is found terminate file scan.
120 * All 'S line's preceed 'T line's in .REL files.
126 * Skip everything that's not a symbol record.
131 sscanf (buf, "S %s %c", symname, &c);
133 /* If it's an actual symbol, record it */
136 if ((*func) (symname, param))