10 #include <gnu/a.out.h>
12 _PROTOTYPE( unsigned int gnu_load
, (char *filename
, struct nlist
**start
) );
13 _PROTOTYPE( void do_error
, (char *message
) );
15 unsigned int gnu_load( filename
, start
)
20 unsigned int nsym
, string_size
;
25 if ( (fd
= open( filename
, 0)) < 0 ||
26 read( fd
, (char *) &header
, sizeof header
) != sizeof header
)
28 do_error( "gnu_load" );
29 if ( fd
>= 0) close( fd
);
33 if ( lseek( fd
, N_STROFF( header
), 0 ) != N_STROFF( header
) )
35 do_error( "gnu_load - reading header" );
40 if ( read( fd
, (char *) &string_size
, sizeof string_size
) < 0 )
42 do_error( "gnu_load - reading header" );
47 if ( (int) header
.a_syms
< 0 ||
48 (unsigned) header
.a_syms
!= header
.a_syms
||
49 (*start
= (struct nlist
*) malloc( (unsigned) header
.a_syms
+
51 == (struct nlist
*) NULL
&&
58 lseek( fd
, N_SYMOFF( header
), 0 );
60 if ( read( fd
, (char *) *start
, (int) header
.a_syms
+ string_size
) < 0 )
62 do_error( "gnu_load - reading symbols" );
68 nsym
= (unsigned int) header
.a_syms
/ sizeof (struct nlist
);
69 names
= (char *) *start
+ header
.a_syms
;
71 for ( p
= *start
; p
< *start
+ nsym
; p
++)
73 p
->n_un
.n_name
= names
+ p
->n_un
.n_strx
;