]> git.pld-linux.org Git - packages/chrpath.git/blame - chrpath-multilib.patch
- biarch experimental patch. testing...
[packages/chrpath.git] / chrpath-multilib.patch
CommitLineData
6416aa35
PS
1--- a/configure.ac 2004-09-19 10:28:33.000000000 +0200
2+++ b/configure.ac 2006-02-27 16:12:00.282066250 +0100
3@@ -16,6 +16,7 @@
4 dnl Checks for programs.
5 AC_PROG_CC
6 AC_PROG_INSTALL
7+AC_PROG_LIBTOOL
8
9 dnl Checks for libraries.
10
11@@ -26,7 +27,6 @@
12 dnl Checks for typedefs, structures, and compiler characteristics.
13 AC_C_CONST
14 AC_C_BIGENDIAN
15-AC_CHECK_SIZEOF(void *)
16
17 dnl Checks for library functions.
18 AC_CHECK_FUNCS(getopt_long)
19--- a/Makefile.am 2004-09-19 10:29:28.000000000 +0200
20+++ b/Makefile.am 2006-02-27 16:57:31.166290750 +0100
21@@ -12,12 +12,17 @@
22 fakeroot debian/rules binary
23
24 chrpath_SOURCES = \
25- chrpath.c \
26- killrpath.c \
27 main.c \
28- elf.c \
29 protos.h
30
31+chrpath_LDADD = -ldl
32+
33+lib_LTLIBRARIES = libchrpath32.la libchrpath64.la
34+libchrpath32_la_SOURCES = chrpath.c killrpath.c elf.c protos.h
35+libchrpath32_la_CFLAGS = -DSIZEOF_VOID_P=4
36+libchrpath64_la_SOURCES = chrpath.c killrpath.c elf.c protos.h
37+libchrpath64_la_CFLAGS = -DSIZEOF_VOID_P=8
38+
39 EXTRA_DIST = ChangeLog.usermap $(man_MANS)
40
41 CLEANFILES = *.bb *.bbg *.da *.gcov testsuite/*.bb testsuite/*.bbg
42--- a/main.c 2004-09-19 10:33:37.000000000 +0200
43+++ b/main.c 2006-02-27 17:23:39.400267750 +0100
44@@ -12,13 +12,19 @@
45 # include "config.h"
46 #endif
47
48+#include <dlfcn.h>
49+#include <elf.h>
50+#include <fcntl.h>
51 #include <stdio.h>
52 #include <stdlib.h>
53+#include <string.h>
54 #include <unistd.h>
55 #ifdef HAVE_GETOPT_H
56 #include <getopt.h>
57 #endif
58-#include "protos.h"
59+
60+typedef int (*killrpath_t)(const char *filename);
61+typedef int (*chrpath_t)(const char *filename, const char *newpath, int convert);
62
63 #ifdef HAVE_GETOPT_LONG
64 # define GETOPT_LONG getopt_long
65@@ -61,6 +67,30 @@
66 printf("\n");
67 }
68
69+static unsigned
70+elf_class(const char *filename)
71+{
72+ Elf32_Ehdr ehdr;
73+ int fd;
74+
75+ fd = open(filename, O_RDONLY);
76+ if (fd == -1)
77+ return 0;
78+ if (read(fd, &ehdr, sizeof(ehdr)) != sizeof(ehdr))
79+ {
80+ close(fd);
81+ return 0;
82+ }
83+ close(fd);
84+ if ((memcmp(ehdr.e_ident, ELFMAG, SELFMAG) != 0)
85+ || (ehdr.e_ident[EI_VERSION] != EV_CURRENT))
86+ {
87+ fprintf(stderr, "`%s' probably isn't an ELF file.\n", filename);
88+ return 0;
89+ }
90+ return ehdr.e_ident[EI_CLASS];
91+}
92+
93 int
94 main(int argc, char * const argv[])
95 {
96@@ -73,6 +103,9 @@
97 #ifdef HAVE_GETOPT_LONG
98 int option_index = 0;
99 #endif /* HAVE_GETOPT_LONG */
100+ void* dll[2];
101+ killrpath_t killrpath[2];
102+ chrpath_t chrpath[2];
103
104 if (argc < 2)
105 {
106@@ -116,14 +149,31 @@
107 }
108 } while (-1 != opt);
109
110+ dll[0] = dlopen("libchrpath32.so.0.0.0", RTLD_LAZY);
111+ killrpath[0] = (killrpath_t)dlsym(dll[0], "killrpath");
112+ chrpath[0] = (chrpath_t)dlsym(dll[0], "chrpath");
113+
114+ dll[1] = dlopen("libchrpath64.so.0.0.0", RTLD_LAZY);
115+ killrpath[1] = (killrpath_t)dlsym(dll[1], "killrpath");
116+ chrpath[1] = (chrpath_t)dlsym(dll[1], "chrpath");
117+
118 while (optind < argc && (!retval || keep_going))
119 {
120+ const char* program = argv[optind++];
121+ unsigned eclass = elf_class(program);
122+ if (!eclass)
123+ {
124+ retval = 1;
125+ continue;
126+ }
127 if (remove)
128- retval |= killrpath(argv[optind++]);
129+ retval |= killrpath[eclass - ELFCLASS32](program);
130 else
131 /* list by default, replace if path is set */
132- retval |= chrpath(argv[optind++], newpath, convert);
133+ retval |= chrpath[eclass - ELFCLASS32](program, newpath, convert);
134 }
135
136+ dlclose(dll[0]);
137+ dlclose(dll[1]);
138 return retval;
139 }
This page took 0.11606 seconds and 4 git commands to generate.