/[gentoo-projects]/pax-utils/scanelf.c
Gentoo

Diff of /pax-utils/scanelf.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.229 Revision 1.230
1/* 1/*
2 * Copyright 2003-2007 Gentoo Foundation 2 * Copyright 2003-2007 Gentoo Foundation
3 * Distributed under the terms of the GNU General Public License v2 3 * Distributed under the terms of the GNU General Public License v2
4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanelf.c,v 1.229 2011/09/27 19:29:19 vapier Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanelf.c,v 1.230 2011/09/27 19:56:15 vapier Exp $
5 * 5 *
6 * Copyright 2003-2007 Ned Ludd - <solar@gentoo.org> 6 * Copyright 2003-2007 Ned Ludd - <solar@gentoo.org>
7 * Copyright 2004-2007 Mike Frysinger - <vapier@gentoo.org> 7 * Copyright 2004-2007 Mike Frysinger - <vapier@gentoo.org>
8 */ 8 */
9 9
10static const char *rcsid = "$Id: scanelf.c,v 1.229 2011/09/27 19:29:19 vapier Exp $"; 10static const char *rcsid = "$Id: scanelf.c,v 1.230 2011/09/27 19:56:15 vapier Exp $";
11const char argv0[] = "scanelf"; 11const char argv0[] = "scanelf";
12 12
13#include "paxinc.h" 13#include "paxinc.h"
14 14
15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+') 15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+')
68static unsigned long setpax = 0UL; 68static unsigned long setpax = 0UL;
69 69
70static int has_objdump = 0; 70static int has_objdump = 0;
71 71
72/* find the path to a file by name */ 72/* find the path to a file by name */
73static char *which(const char *fname) 73static int bin_in_path(const char *fname)
74{ 74{
75 static char fullpath[__PAX_UTILS_PATH_MAX]; 75 char fullpath[__PAX_UTILS_PATH_MAX];
76 char *path, *p; 76 char *path, *p;
77 77
78 path = getenv("PATH"); 78 path = getenv("PATH");
79 if (!path) 79 if (!path)
80 return NULL; 80 return 0;
81 81
82 path = xstrdup(path);
83 while ((p = strrchr(path, ':')) != NULL) { 82 while ((p = strrchr(path, ':')) != NULL) {
84 snprintf(fullpath, sizeof(fullpath), "%s/%s", p + 1, fname); 83 snprintf(fullpath, sizeof(fullpath), "%s/%s", p + 1, fname);
85 *p = 0; 84 *p = 0;
86 if (access(fullpath, R_OK) != -1) { 85 if (access(fullpath, R_OK) != -1)
87 free(path); 86 return 1;
88 return fullpath;
89 } 87 }
90 } 88
91 free(path);
92 return NULL; 89 return 0;
93} 90}
94 91
95/* 1 on failure. 0 otherwise */ 92/* 1 on failure. 0 otherwise */
96static int rematch(const char *regex, const char *match, int cflags) 93static int rematch(const char *regex, const char *match, int cflags)
97{ 94{
1583 return ret; 1580 return ret;
1584} 1581}
1585 1582
1586static int scanelf_from_file(const char *filename) 1583static int scanelf_from_file(const char *filename)
1587{ 1584{
1588 FILE *fp = NULL; 1585 FILE *fp;
1589 char *p; 1586 char *p, *path;
1590 char path[__PAX_UTILS_PATH_MAX]; 1587 size_t len;
1591 int ret = 0; 1588 int ret;
1592 1589
1593 if (strcmp(filename, "-") == 0) 1590 if (strcmp(filename, "-") == 0)
1594 fp = stdin; 1591 fp = stdin;
1595 else if ((fp = fopen(filename, "r")) == NULL) 1592 else if ((fp = fopen(filename, "r")) == NULL)
1596 return 1; 1593 return 1;
1597 1594
1598 while ((fgets(path, __PAX_UTILS_PATH_MAX, fp)) != NULL) { 1595 path = NULL;
1596 len = 0;
1597 ret = 0;
1598 while (getline(&path, &len, fp) != -1) {
1599 if ((p = strchr(path, '\n')) != NULL) 1599 if ((p = strchr(path, '\n')) != NULL)
1600 *p = 0; 1600 *p = 0;
1601 search_path = path; 1601 search_path = path;
1602 ret = scanelf_dir(path); 1602 ret = scanelf_dir(path);
1603 } 1603 }
1604 free(path);
1605
1604 if (fp != stdin) 1606 if (fp != stdin)
1605 fclose(fp); 1607 fclose(fp);
1608
1606 return ret; 1609 return ret;
1607} 1610}
1608 1611
1609#if defined(__GLIBC__) || defined(__UCLIBC__) || defined(__NetBSD__) 1612#if defined(__GLIBC__) || defined(__UCLIBC__) || defined(__NetBSD__)
1610 1613
1611static int load_ld_cache_config(int i, const char *fname) 1614static int load_ld_cache_config(int i, const char *fname)
1612{ 1615{
1613 FILE *fp = NULL; 1616 FILE *fp = NULL;
1614 char *p; 1617 char *p, *path;
1615 char path[__PAX_UTILS_PATH_MAX]; 1618 size_t len;
1616 char _fname[__PAX_UTILS_PATH_MAX]; 1619 char _fname[__PAX_UTILS_PATH_MAX];
1617 1620
1618 fname = maybe_add_root(fname, _fname); 1621 fname = maybe_add_root(fname, _fname);
1619 1622
1620 if ((fp = fopen(fname, "r")) == NULL) 1623 if ((fp = fopen(fname, "r")) == NULL)
1621 return i; 1624 return i;
1622 1625
1623 while ((fgets(path, __PAX_UTILS_PATH_MAX, fp)) != NULL) { 1626 path = NULL;
1627 len = 0;
1628 while (getline(&path, &len, fp) != -1) {
1624 if ((p = strrchr(path, '\r')) != NULL) 1629 if ((p = strrchr(path, '\r')) != NULL)
1625 *p = 0; 1630 *p = 0;
1626 if ((p = strchr(path, '\n')) != NULL) 1631 if ((p = strchr(path, '\n')) != NULL)
1627 *p = 0; 1632 *p = 0;
1628 1633
1656 if (*path != '/') 1661 if (*path != '/')
1657 continue; 1662 continue;
1658 1663
1659 xarraypush(ldpaths, path, strlen(path)); 1664 xarraypush(ldpaths, path, strlen(path));
1660 } 1665 }
1666 free(path);
1661 1667
1662 fclose(fp); 1668 fclose(fp);
1669
1663 return i; 1670 return i;
1664} 1671}
1665 1672
1666#elif defined(__FreeBSD__) || defined(__DragonFly__) 1673#elif defined(__FreeBSD__) || defined(__DragonFly__)
1667 1674
2016 err("Unknown option '%c' or argument missing", optopt); 2023 err("Unknown option '%c' or argument missing", optopt);
2017 default: 2024 default:
2018 err("Unhandled option '%c'; please report this", i); 2025 err("Unhandled option '%c'; please report this", i);
2019 } 2026 }
2020 } 2027 }
2021 if (show_textrels && be_verbose) { 2028 if (show_textrels && be_verbose)
2022 if (which("objdump") != NULL) 2029 has_objdump = bin_in_path("objdump");
2023 has_objdump = 1;
2024 }
2025 /* flatten arrays for display */ 2030 /* flatten arrays for display */
2026 if (array_cnt(find_lib_arr)) 2031 if (array_cnt(find_lib_arr))
2027 find_lib = array_flatten_str(find_lib_arr); 2032 find_lib = array_flatten_str(find_lib_arr);
2028 if (array_cnt(find_section_arr)) 2033 if (array_cnt(find_section_arr))
2029 find_section = array_flatten_str(find_section_arr); 2034 find_section = array_flatten_str(find_section_arr);

Legend:
Removed from v.1.229  
changed lines
  Added in v.1.230

  ViewVC Help
Powered by ViewVC 1.1.20