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-2010 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
34 #include "lk_readnl.h"
42 long pos
= ftell (libfp
);
46 if (((c
= getc (libfp
)) == 'X' || c
== 'D' || c
== 'Q') && ((c
= getc (libfp
)) == 'H' || c
== 'L'))
56 if (getc (libfp
) == '\n')
66 if (getc (libfp
) == '\n')
78 if (fread (buf
, 1, sizeof (buf
), libfp
) == sizeof (buf
) && memcmp (buf
, "!FILE ", 6) == 0)
81 fseek (libfp
, pos
, SEEK_SET
);
85 /* Load a standalone or embedded .rel */
87 load_rel (FILE * libfp
, long size
)
94 end
= (size
>= 0) ? ftell (libfp
) + size
: -1;
96 while ((end
< 0 || ftell (libfp
) < end
) && lk_readnl (str
, sizeof (str
), libfp
) != NULL
)
98 if (0 == strcmp (str
, "</REL>"))
112 enum_symbols (FILE * fp
, long size
, int (*func
) (const char *symvoid
, void *param
), void *param
)
115 long end
= (size
>= 0) ? ftell (fp
) + size
: -1;
117 assert (func
!= NULL
);
120 * Read in the object file. Look for lines that
121 * begin with "S" and end with "D". These are
122 * symbol table definitions. If we find one, see
123 * if it is our symbol. Make sure we only read in
124 * our object file and don't go into the next one.
127 while ((end
< 0 || ftell (fp
) < end
) && lk_readnl (buf
, sizeof (buf
), fp
) != NULL
)
129 char symname
[NINPUT
];
133 * When a 'T line' is found terminate file scan.
134 * All 'S line's preceed 'T line's in .REL files.
140 * Skip everything that's not a symbol record.
145 sscanf (buf
, "S %s %c", symname
, &c
);
147 /* If it's an actual symbol, record it */
150 if ((*func
) (symname
, param
))