import of ftp.dlink.com/GPL/DSMG-600_reB/ppclinux.tar.gz
[linux-2.4.21-pre4.git] / arch / ppc / kernel / find_name.c
1 /*
2  * BK Id: SCCS/s.find_name.c 1.7 06/05/01 21:22:02 paulus
3  */
4 #include <stdio.h>
5 #include <asm/page.h>
6 #include <sys/mman.h>
7 #include <strings.h>
8 /*
9  * Finds a given address in the System.map and prints it out
10  * with its neighbors.  -- Cort
11  */
12
13 int main(int argc, char **argv)
14 {
15         unsigned long addr, cmp, i;
16         FILE *f;
17         char s[256], last[256];
18         
19         if ( argc < 2 )
20         {
21                 fprintf(stderr, "Usage: %s <address>\n", argv[0]);
22                 return -1;
23         }
24
25         for ( i = 1 ; argv[i] ; i++ )
26         {
27                 sscanf( argv[i], "%0lx", &addr );
28                 /* adjust if addr is relative to kernelbase */
29                 if ( addr < PAGE_OFFSET )
30                         addr += PAGE_OFFSET;
31                 
32                 if ( (f = fopen( "System.map", "r" )) == NULL )
33                 {
34                         perror("fopen()\n");
35                         exit(-1);
36                 }
37                 
38                 while ( !feof(f) )
39                 {
40                         fgets(s, 255 , f);
41                         sscanf( s, "%0lx", &cmp );
42                         if ( addr < cmp )
43                                 break;
44                         strcpy( last, s);
45                 }
46                 
47                 printf( "%s%s", last, s );
48         }               
49         fclose(f);
50         return 0;
51 }