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