Lines 43-48
Link Here
|
43 |
char *base_dir = NULL; |
43 |
char *base_dir = NULL; |
44 |
char *dest_dir = NULL; |
44 |
char *dest_dir = NULL; |
45 |
char *list_file = NULL; |
45 |
char *list_file = NULL; |
|
|
46 |
int print_files; |
47 |
int read_only; |
46 |
int list_file_fd = -1; |
48 |
int list_file_fd = -1; |
47 |
|
49 |
|
48 |
typedef unsigned int uint_32; |
50 |
typedef unsigned int uint_32; |
Lines 567-579
Link Here
|
567 |
char *p; |
569 |
char *p; |
568 |
size_t size; |
570 |
size_t size; |
569 |
ssize_t ret; |
571 |
ssize_t ret; |
570 |
if (base_dir) |
|
|
571 |
p = s + strlen (base_dir); |
572 |
else |
573 |
p = s; |
574 |
|
572 |
|
575 |
if (list_file_fd != -1) |
573 |
if (list_file_fd != -1) |
576 |
{ |
574 |
{ |
|
|
575 |
if (base_dir) |
576 |
p = s + strlen (base_dir); |
577 |
else |
578 |
p = s; |
577 |
size = strlen (p) + 1; |
579 |
size = strlen (p) + 1; |
578 |
while (size > 0) |
580 |
while (size > 0) |
579 |
{ |
581 |
{ |
Lines 584-589
Link Here
|
584 |
p += ret; |
586 |
p += ret; |
585 |
} |
587 |
} |
586 |
} |
588 |
} |
|
|
589 |
if (print_files) |
590 |
{ |
591 |
if (base_dir) |
592 |
p = s + strlen (base_dir); |
593 |
else |
594 |
p = s; |
595 |
size = strlen (p) + 1; |
596 |
while (size > 0) |
597 |
{ |
598 |
ret = write (STDOUT_FILENO, p, size); |
599 |
if (ret == -1) |
600 |
break; |
601 |
write (STDOUT_FILENO, "\n", 1); |
602 |
size -= ret; |
603 |
p += ret; |
604 |
} |
605 |
} |
587 |
} |
606 |
} |
588 |
|
607 |
|
589 |
free (s); |
608 |
free (s); |
Lines 1193-1198
Link Here
|
1193 |
"directory to rewrite base-dir into", NULL }, |
1212 |
"directory to rewrite base-dir into", NULL }, |
1194 |
{ "list-file", 'l', POPT_ARG_STRING, &list_file, 0, |
1213 |
{ "list-file", 'l', POPT_ARG_STRING, &list_file, 0, |
1195 |
"file where to put list of source and header file names", NULL }, |
1214 |
"file where to put list of source and header file names", NULL }, |
|
|
1215 |
{ "print", 'p', POPT_ARG_NONE, &print_files, 0, |
1216 |
"print newline delimited list of file names to stdout", NULL }, |
1217 |
{ "read-only", 'r', POPT_ARG_NONE, &read_only, 0, |
1218 |
"open read-only", NULL }, |
1196 |
POPT_AUTOHELP |
1219 |
POPT_AUTOHELP |
1197 |
{ NULL, 0, 0, NULL, 0, NULL, NULL } |
1220 |
{ NULL, 0, 0, NULL, 0, NULL, NULL } |
1198 |
}; |
1221 |
}; |
Lines 1205-1211
Link Here
|
1205 |
int i; |
1228 |
int i; |
1206 |
DSO *dso = NULL; |
1229 |
DSO *dso = NULL; |
1207 |
|
1230 |
|
1208 |
elf = elf_begin (fd, ELF_C_RDWR_MMAP, NULL); |
1231 |
elf = elf_begin (fd, read_only ? ELF_C_READ : ELF_C_RDWR_MMAP, NULL); |
1209 |
if (elf == NULL) |
1232 |
if (elf == NULL) |
1210 |
{ |
1233 |
{ |
1211 |
error (0, 0, "cannot open ELF file: %s", elf_errmsg (-1)); |
1234 |
error (0, 0, "cannot open ELF file: %s", elf_errmsg (-1)); |
Lines 1357-1366
Link Here
|
1357 |
exit (1); |
1380 |
exit (1); |
1358 |
} |
1381 |
} |
1359 |
|
1382 |
|
1360 |
/* Make sure we can read and write */ |
1383 |
if (!read_only) { |
1361 |
chmod (file, stat_buf.st_mode | S_IRUSR | S_IWUSR); |
1384 |
/* Make sure we can read and write */ |
|
|
1385 |
chmod (file, stat_buf.st_mode | S_IRUSR | S_IWUSR); |
1386 |
} |
1362 |
|
1387 |
|
1363 |
fd = open (file, O_RDWR); |
1388 |
fd = open (file, read_only ? O_RDONLY : O_RDWR); |
1364 |
if (fd < 0) |
1389 |
if (fd < 0) |
1365 |
{ |
1390 |
{ |
1366 |
fprintf (stderr, "Failed to open input file '%s': %s\n", file, strerror(errno)); |
1391 |
fprintf (stderr, "Failed to open input file '%s': %s\n", file, strerror(errno)); |
Lines 1393-1399
Link Here
|
1393 |
} |
1418 |
} |
1394 |
} |
1419 |
} |
1395 |
|
1420 |
|
1396 |
if (elf_update (dso->elf, ELF_C_WRITE) < 0) |
1421 |
if (!read_only && elf_update (dso->elf, ELF_C_WRITE) < 0) |
1397 |
{ |
1422 |
{ |
1398 |
fprintf (stderr, "Failed to write file: %s\n", elf_errmsg (elf_errno())); |
1423 |
fprintf (stderr, "Failed to write file: %s\n", elf_errmsg (elf_errno())); |
1399 |
exit (1); |
1424 |
exit (1); |
Lines 1405-1412
Link Here
|
1405 |
} |
1430 |
} |
1406 |
close (fd); |
1431 |
close (fd); |
1407 |
|
1432 |
|
1408 |
/* Restore old access rights */ |
1433 |
if (!read_only) { |
1409 |
chmod (file, stat_buf.st_mode); |
1434 |
/* Restore old access rights */ |
|
|
1435 |
chmod (file, stat_buf.st_mode); |
1436 |
} |
1410 |
|
1437 |
|
1411 |
poptFreeContext (optCon); |
1438 |
poptFreeContext (optCon); |
1412 |
|
1439 |
|