| 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/scanelf.c,v 1.203 2008/12/30 12:39:53 vapier Exp $ |
4 | * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.204 2008/12/30 13:09:20 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 | |
| 10 | static const char *rcsid = "$Id: scanelf.c,v 1.203 2008/12/30 12:39:53 vapier Exp $"; |
10 | static const char *rcsid = "$Id: scanelf.c,v 1.204 2008/12/30 13:09:20 vapier Exp $"; |
| 11 | const char * const argv0 = "scanelf"; |
11 | const char * const 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 == '+') |
| … | |
… | |
| 76 | static size_t ldcache_size = 0; |
76 | static size_t ldcache_size = 0; |
| 77 | static unsigned long setpax = 0UL; |
77 | static unsigned long setpax = 0UL; |
| 78 | |
78 | |
| 79 | static int has_objdump = 0; |
79 | static int has_objdump = 0; |
| 80 | |
80 | |
| 81 | static char *getstr_perms(const char *fname); |
|
|
| 82 | static char *getstr_perms(const char *fname) |
81 | static const char *getstr_perms(const char *fname) |
| 83 | { |
82 | { |
| 84 | struct stat st; |
83 | struct stat st; |
| 85 | static char buf[8]; |
84 | static char buf[8]; |
| 86 | |
85 | |
| 87 | if ((stat(fname, &st)) == (-1)) |
86 | if (stat(fname, &st) == -1) |
| 88 | return (char *) ""; |
87 | return ""; |
| 89 | |
88 | |
| 90 | snprintf(buf, sizeof(buf), "%o", st.st_mode); |
89 | snprintf(buf, sizeof(buf), "%o", st.st_mode); |
| 91 | |
90 | |
| 92 | return (char *) buf + 2; |
91 | return buf + 2; |
| 93 | } |
92 | } |
| 94 | |
93 | |
| 95 | /* find the path to a file by name */ |
94 | /* find the path to a file by name */ |
| 96 | static char *which(const char *fname) |
95 | static char *which(const char *fname) |
| 97 | { |
96 | { |
| … | |
… | |
| 106 | while ((p = strrchr(path, ':')) != NULL) { |
105 | while ((p = strrchr(path, ':')) != NULL) { |
| 107 | snprintf(fullpath, sizeof(fullpath), "%s/%s", p + 1, fname); |
106 | snprintf(fullpath, sizeof(fullpath), "%s/%s", p + 1, fname); |
| 108 | *p = 0; |
107 | *p = 0; |
| 109 | if (access(fullpath, R_OK) != (-1)) { |
108 | if (access(fullpath, R_OK) != (-1)) { |
| 110 | free(path); |
109 | free(path); |
| 111 | return (char *) fullpath; |
110 | return fullpath; |
| 112 | } |
111 | } |
| 113 | } |
112 | } |
| 114 | free(path); |
113 | free(path); |
| 115 | return NULL; |
114 | return NULL; |
| 116 | } |
115 | } |