|
|
1.1 root 1: #include <stdio.h>
2: #include "filehdr.h"
3: #include "syms.h"
4: #include "ldfcn.h"
5:
6: char *
7: ldgetname(ldptr, symentry)
8: register LDFILE *ldptr;
9: register SYMENT *symentry;
10: {
11: static char buffer[BUFSIZ + SYMNMLEN];
12: extern int vldldptr();
13: extern char *strncpy();
14: #ifdef FLEXNAMES
15: extern char *strcpy();
16: extern char *malloc();
17: extern void free();
18: static char *strtab = NULL;
19: static int last_fnum_ = 0;
20: static long last_offset = -1L;
21: static long length;
22: #endif
23:
24: if (vldldptr(ldptr) != SUCCESS)
25: return (NULL);
26: #ifdef FLEXNAMES
27: if (symentry->n_zeroes == 0L) /* stored in string table */
28: {
29: /*
30: * Different archive members are noted by the OFFSET change.
31: * Otherwise, normal other ldptr's are distinguished by
32: * the different _fnum_'s.
33: */
34: if (last_offset != OFFSET(ldptr) ||
35: last_fnum_ != ldptr->_fnum_)
36: {
37: long string_begin, home;
38:
39: if (strtab != NULL)
40: free(strtab);
41: string_begin = HEADER(ldptr).f_symptr +
42: HEADER(ldptr).f_nsyms * SYMESZ;
43: home = FTELL(ldptr);
44: if (FSEEK(ldptr, string_begin, BEGINNING) != OKFSEEK ||
45: FREAD((char *)&length, sizeof(long), 1, ldptr)
46: != 1 ||
47: (strtab = malloc((unsigned)length)) == NULL ||
48: FREAD(strtab + sizeof(long), sizeof(char),
49: length - sizeof(long), ldptr)
50: != length - sizeof(long) ||
51: fseek(IOPTR(ldptr), home, 0) != OKFSEEK ||
52: strtab[length - 1] != '\0')
53: {
54: /*
55: * Try to have no side effects if an error
56: * occurs somewhere...
57: */
58: (void)fseek(IOPTR(ldptr), home, 0);
59: return (NULL);
60: }
61: last_fnum_ = ldptr->_fnum_;
62: last_offset = OFFSET(ldptr);
63: }
64: if (length <= symentry->n_offset)
65: return (NULL);
66: return (strcpy(buffer, strtab + symentry->n_offset));
67: }
68: else /* still in old COFF location */
69: #endif
70: {
71: (void)strncpy(buffer, symentry->n_name, SYMNMLEN);
72: buffer[SYMNMLEN] = '\0';
73: return (buffer);
74: }
75: }
76:
77: static char ID[] = "@(#) ldgetname.c: 1.2 2/16/83";
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.