2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * symtab - symbol table routines
13 #include <afsconfig.h>
14 #include <afs/param.h>
17 #include "sys/types.h"
21 * using the toc_syment structure, that we fabricate:
22 * sym->n_offset is the string pointer
25 #define sym_str(sym) ((char *) (sym)->n_nptr)
27 #define sym_off(sym) ((sym)->n_offset)
28 #define sym_str(sym) \
29 ((sym)->n_zeroes == 0 ? (char *) sym_off(sym) : (sym)->n_name)
33 sym_lookup(name
, value
)
36 static sym_t
*symsrch(), *search();
43 * first, try just the name. if that fails, try with a
44 * prefix '.', and failing that, a prefix '_'.
46 if (sym
= symsrch(name
))
48 memcpy(buf
+ 1, name
, sizeof(buf
) - 2);
51 if (sym
= symsrch(buf
))
72 for (sp
= toc_syms
; sp
< &toc_syms
[toc_nsyms
]; ++sp
) {
73 if (sp
->n_value
<= addr
&& sp
->n_value
>= value
) {
76 if (sp
->n_value
== addr
)
80 return save
? sym_flex(save
) : 0;
93 * determine length of symbol
95 for (len
= 0, p
= s
; *p
; ++p
)
99 for (sp
= toc_syms
; sp
< &toc_syms
[toc_nsyms
]; ++sp
) {
101 * exact matches preferred
103 if (strcmp(sym_str(sp
), s
) == 0) {
108 * otherwise, prefices might interest us.
110 if (!found
&& (strncmp(sym_str(sp
), s
, len
) == 0)) {
116 return found
? sym_flex(found
) : 0;
120 * sym_flex - convert a symbol so that there is no distinction between
121 * flex-string and non flex-string format.
124 * sym - ^ to symbol table entry
127 * ^ to static location containing modified symbol.
134 static char name
[48];
136 strncpy(name
, sym_str(sym
), sizeof(name
) - 1);
139 if (sym
->n_zeroes
!= 0)
140 name
[8] = 0; /* make sure that we truncate correctly */
145 symbol
.n_nptr
= name
;