PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/arch/ppc/kernel/find_name.c

https://bitbucket.org/evzijst/gittest
C | 48 lines | 37 code | 6 blank | 5 comment | 7 complexity | 141d195a1407e99dffd53f184a1ed842 MD5 | raw file
 1#include <stdio.h>
 2#include <asm/page.h>
 3#include <sys/mman.h>
 4#include <strings.h>
 5/*
 6 * Finds a given address in the System.map and prints it out
 7 * with its neighbors.  -- Cort
 8 */
 9
10int main(int argc, char **argv)
11{
12	unsigned long addr, cmp, i;
13	FILE *f;
14	char s[256], last[256];
15	
16	if ( argc < 2 )
17	{
18		fprintf(stderr, "Usage: %s <address>\n", argv[0]);
19		return -1;
20	}
21
22	for ( i = 1 ; argv[i] ; i++ )
23	{
24		sscanf( argv[i], "%0lx", &addr );
25		/* adjust if addr is relative to kernelbase */
26		if ( addr < PAGE_OFFSET )
27			addr += PAGE_OFFSET;
28		
29		if ( (f = fopen( "System.map", "r" )) == NULL )
30		{
31			perror("fopen()\n");
32			exit(-1);
33		}
34		
35		while ( !feof(f) )
36		{
37			fgets(s, 255 , f);
38			sscanf( s, "%0lx", &cmp );
39			if ( addr < cmp )
40				break;
41			strcpy( last, s);
42		}
43		
44		printf( "%s%s", last, s );
45	}		
46	fclose(f);
47	return 0;
48}