source: trunk/minix/commands/mdb/gnu_load.c@ 11

Last change on this file since 11 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 2.0 KB
RevLine 
[9]1/*
2 * gnu_load for mdb.c
3 */
4
5#include <stdio.h>
6#include <sys/types.h>
7#include <unistd.h>
8#include <stdlib.h>
9#include <fcntl.h>
10#include <gnu/a.out.h>
11
12_PROTOTYPE( unsigned int gnu_load, (char *filename, struct nlist **start) );
13_PROTOTYPE( void do_error, (char *message) );
14
15unsigned int gnu_load( filename, start)
16char *filename;
17struct nlist **start;
18{
19 struct exec header;
20 unsigned int nsym, string_size;
21 char *names;
22 struct nlist *p;
23 int fd;
24
25 if ( (fd = open( filename, 0)) < 0 ||
26 read( fd, (char *) &header, sizeof header ) != sizeof header )
27 {
28 do_error( "gnu_load" );
29 if ( fd >= 0) close( fd );
30 return 0;
31 }
32
33 if ( lseek( fd, N_STROFF( header ), 0 ) != N_STROFF( header ) )
34 {
35 do_error( "gnu_load - reading header" );
36 close( fd );
37 return 0;
38 }
39
40 if ( read( fd, (char *) &string_size, sizeof string_size ) < 0 )
41 {
42 do_error( "gnu_load - reading header" );
43 close( fd );
44 return 0;
45 }
46
47 if ( (int) header.a_syms < 0 ||
48 (unsigned) header.a_syms != header.a_syms ||
49 (*start = (struct nlist *) malloc( (unsigned) header.a_syms +
50 string_size ))
51 == (struct nlist *) NULL &&
52 header.a_syms != 0 )
53 {
54 close( fd );
55 return 0;
56 }
57
58 lseek( fd, N_SYMOFF( header ), 0 );
59
60 if ( read( fd, (char *) *start, (int) header.a_syms + string_size ) < 0 )
61 {
62 do_error( "gnu_load - reading symbols" );
63 close( fd );
64 return 0;
65 }
66 close( fd );
67
68 nsym = (unsigned int) header.a_syms / sizeof (struct nlist);
69 names = (char *) *start + header.a_syms;
70
71 for ( p = *start; p < *start + nsym; p++)
72 if(p->n_un.n_strx)
73 p->n_un.n_name = names + p->n_un.n_strx;
74
75 return nsym;
76}
Note: See TracBrowser for help on using the repository browser.