fix /proc/#/maps parse faliures, formatting cleanup

This commit is contained in:
Glenn Maynard
2004-01-02 04:13:43 +00:00
parent a9985795a4
commit eb63dc754f
+14 -17
View File
@@ -199,7 +199,7 @@ static int get_readable_ranges( const void **starts, const void **ends, int size
int file_used = 0; int file_used = 0;
bool eof = false; bool eof = false;
int got = 0; int got = 0;
while(!eof && got < size-1 ) while( !eof && got < size-1 )
{ {
int ret = read( fd, file+file_used, sizeof(file) - file_used); int ret = read( fd, file+file_used, sizeof(file) - file_used);
if( ret < int(sizeof(file)) - file_used) if( ret < int(sizeof(file)) - file_used)
@@ -215,41 +215,38 @@ static int get_readable_ranges( const void **starts, const void **ends, int size
break; break;
*p++ = 0; *p++ = 0;
char line[1024];
strcpy( line, file );
memmove(file, p, file_used);
file_used -= p-file;
/* Search for the hyphen. */ /* Search for the hyphen. */
char *hyphen = strchr( file, '-' ); char *hyphen = strchr( line, '-' );
if( hyphen == NULL ) if( hyphen == NULL )
{ continue; /* Parse error. */
/* Parse error. */
continue;
}
/* Search for the space. */ /* Search for the space. */
char *space = strchr( hyphen, ' ' ); char *space = strchr( hyphen, ' ' );
if( space == NULL ) if( space == NULL )
{ continue; /* Parse error. */
/* Parse error. */
continue;
}
/* " rwxp". If space[1] isn't 'r', then the block isn't readable. */ /* " rwxp". If space[1] isn't 'r', then the block isn't readable. */
if( strlen(space) < 2 || space[1] != 'r' ) if( strlen(space) < 2 || space[1] != 'r' )
continue; continue;
*starts++ = (const void *) xtoi( file ); *starts++ = (const void *) xtoi( line );
*ends++ = (const void *) xtoi( hyphen+1 ); *ends++ = (const void *) xtoi( hyphen+1 );
file_used -= p-file;
memmove(file, p, file_used);
} }
if( file_used == sizeof(file) ) if( file_used == sizeof(file) )
{ {
/* Line longer than the buffer. Weird; bail. */ /* Line longer than the buffer. Weird; bail. */
break;
}
}
close(fd); close(fd);
return false;
}
}
*starts++ = NULL; *starts++ = NULL;
*ends++ = NULL; *ends++ = NULL;