mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8140482: Various minor code improvements (runtime)
Reviewed-by: dholmes, coleenp, sspitsyn, dsamersoff
This commit is contained in:
parent
333927f512
commit
3b8c97faae
15 changed files with 142 additions and 115 deletions
|
@ -38,6 +38,7 @@ int pathmap_open(const char* name) {
|
|||
int fd;
|
||||
char alt_path[PATH_MAX + 1], *alt_path_end;
|
||||
const char *s;
|
||||
int free_space;
|
||||
|
||||
if (!alt_root_initialized) {
|
||||
alt_root_initialized = -1;
|
||||
|
@ -48,14 +49,22 @@ int pathmap_open(const char* name) {
|
|||
return open(name, O_RDONLY);
|
||||
}
|
||||
|
||||
strcpy(alt_path, alt_root);
|
||||
alt_path_end = alt_path + strlen(alt_path);
|
||||
|
||||
// Strip path items one by one and try to open file with alt_root prepended
|
||||
if (strlen(alt_root) + strlen(name) < PATH_MAX) {
|
||||
// Buffer too small.
|
||||
return -1;
|
||||
}
|
||||
|
||||
strncpy(alt_path, alt_root, PATH_MAX);
|
||||
alt_path[PATH_MAX] = '\0';
|
||||
alt_path_end = alt_path + strlen(alt_path);
|
||||
free_space = PATH_MAX + 1 - (alt_path_end-alt_path);
|
||||
|
||||
// Strip path items one by one and try to open file with alt_root prepended.
|
||||
s = name;
|
||||
while (1) {
|
||||
strcat(alt_path, s);
|
||||
s += 1;
|
||||
strncat(alt_path, s, free_space);
|
||||
s += 1; // Skip /.
|
||||
|
||||
fd = open(alt_path, O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
|
@ -70,7 +79,8 @@ int pathmap_open(const char* name) {
|
|||
break;
|
||||
}
|
||||
|
||||
*alt_path_end = 0;
|
||||
// Cut off what we appended above.
|
||||
*alt_path_end = '\0';
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue