Added a separate keymap for escaped scancodes. This makes the code
[minix.git] / commands / mdb / gnu_load.c
blobbc3e2aba3fab5cc48d32c443bd26126d21cf189c
1 /*
2 * gnu_load for mdb.c
3 */
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>
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)
16 char *filename;
17 struct nlist **start;
19 struct exec header;
20 unsigned int nsym, string_size;
21 char *names;
22 struct nlist *p;
23 int fd;
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 );
30 return 0;
33 if ( lseek( fd, N_STROFF( header ), 0 ) != N_STROFF( header ) )
35 do_error( "gnu_load - reading header" );
36 close( fd );
37 return 0;
40 if ( read( fd, (char *) &string_size, sizeof string_size ) < 0 )
42 do_error( "gnu_load - reading header" );
43 close( fd );
44 return 0;
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 )
54 close( fd );
55 return 0;
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" );
63 close( fd );
64 return 0;
66 close( fd );
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++)
72 if(p->n_un.n_strx)
73 p->n_un.n_name = names + p->n_un.n_strx;
75 return nsym;