1 /* Copyright (C) 1991, 1996 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with the GNU C Library; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 /* Search the executable FILE for symbols matching those in NL,
26 which is terminated by an element with a NULL `n_un.n_name' member,
27 and fill in the elements of NL. */
29 nlist (const char *file
, struct nlist
*nl
)
34 struct nlist
*symbols
;
35 unsigned long int string_table_size
;
45 f
= fopen (file
, "r");
49 if (fread ((void *) &header
, sizeof (header
), 1, f
) != 1)
52 if (fseek (f
, N_SYMOFF (header
), SEEK_SET
) != 0)
55 symbols
= (struct nlist
*) __alloca (header
.a_syms
);
56 nsymbols
= header
.a_syms
/ sizeof (symbols
[0]);
58 if (fread ((void *) symbols
, sizeof (symbols
[0]), nsymbols
, f
) != nsymbols
)
61 if (fread ((void *) &string_table_size
, sizeof (string_table_size
), 1, f
)
64 string_table_size
-= sizeof (string_table_size
);
66 string_table
= (char *) __alloca (string_table_size
);
67 if (fread ((void *) string_table
, string_table_size
, 1, f
) != 1)
70 for (i
= 0; i
< nsymbols
; ++i
)
72 register struct nlist
*nlp
;
73 for (nlp
= nl
; nlp
->n_un
.n_name
!= NULL
; ++nlp
)
74 if (!strcmp (nlp
->n_un
.n_name
,
75 &string_table
[symbols
[i
].n_un
.n_strx
-
76 sizeof (string_table_size
)]))
78 char *const name
= nlp
->n_un
.n_name
;
80 nlp
->n_un
.n_name
= name
;