Deleted Added
full compact
ldd.c (90171) ldd.c (90172)
1/*
2 * Copyright (c) 1993 Paul Kranenburg
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 16 unchanged lines hidden (view full) ---

25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef lint
32static const char rcsid[] =
1/*
2 * Copyright (c) 1993 Paul Kranenburg
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 16 unchanged lines hidden (view full) ---

25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef lint
32static const char rcsid[] =
33 "$FreeBSD: head/usr.bin/ldd/ldd.c 90171 2002-02-04 10:23:23Z sobomax $";
33 "$FreeBSD: head/usr.bin/ldd/ldd.c 90172 2002-02-04 10:33:48Z sobomax $";
34#endif /* not lint */
35
36#include <sys/wait.h>
37#include <machine/elf.h>
38#include <a.out.h>
34#endif /* not lint */
35
36#include <sys/wait.h>
37#include <machine/elf.h>
38#include <a.out.h>
39#include <dlfcn.h>
39#include <err.h>
40#include <fcntl.h>
41#include <stdio.h>
42#include <stdlib.h>
43#include <unistd.h>
44
45extern void dump_file __P((const char *));
46extern int error_count;

--- 64 unchanged lines hidden (view full) ---

111 int fd;
112 union {
113 struct exec aout;
114 Elf_Ehdr elf;
115 } hdr;
116 int n;
117 int status;
118 int file_ok;
40#include <err.h>
41#include <fcntl.h>
42#include <stdio.h>
43#include <stdlib.h>
44#include <unistd.h>
45
46extern void dump_file __P((const char *));
47extern int error_count;

--- 64 unchanged lines hidden (view full) ---

112 int fd;
113 union {
114 struct exec aout;
115 Elf_Ehdr elf;
116 } hdr;
117 int n;
118 int status;
119 int file_ok;
120 int is_shlib;
119
120 if ((fd = open(*argv, O_RDONLY, 0)) < 0) {
121 warn("%s", *argv);
122 rval |= 1;
123 continue;
124 }
125 if ((n = read(fd, &hdr, sizeof hdr)) == -1) {
126 warn("%s: can't read program header", *argv);
127 (void)close(fd);
128 rval |= 1;
129 continue;
130 }
131
132 file_ok = 1;
121
122 if ((fd = open(*argv, O_RDONLY, 0)) < 0) {
123 warn("%s", *argv);
124 rval |= 1;
125 continue;
126 }
127 if ((n = read(fd, &hdr, sizeof hdr)) == -1) {
128 warn("%s: can't read program header", *argv);
129 (void)close(fd);
130 rval |= 1;
131 continue;
132 }
133
134 file_ok = 1;
135 is_shlib = 0;
133 if (n >= sizeof hdr.aout && !N_BADMAG(hdr.aout)) {
134 /* a.out file */
135 if ((N_GETFLAG(hdr.aout) & EX_DPMASK) != EX_DYNAMIC
136#if 1 /* Compatibility */
137 || hdr.aout.a_entry < __LDPGSZ
138#endif
139 ) {
140 warnx("%s: not a dynamic executable", *argv);

--- 21 unchanged lines hidden (view full) ---

162 }
163 if (phdr.p_type == PT_DYNAMIC)
164 dynamic = 1;
165 }
166 }
167 if (!dynamic) {
168 warnx("%s: not a dynamic executable", *argv);
169 file_ok = 0;
136 if (n >= sizeof hdr.aout && !N_BADMAG(hdr.aout)) {
137 /* a.out file */
138 if ((N_GETFLAG(hdr.aout) & EX_DPMASK) != EX_DYNAMIC
139#if 1 /* Compatibility */
140 || hdr.aout.a_entry < __LDPGSZ
141#endif
142 ) {
143 warnx("%s: not a dynamic executable", *argv);

--- 21 unchanged lines hidden (view full) ---

165 }
166 if (phdr.p_type == PT_DYNAMIC)
167 dynamic = 1;
168 }
169 }
170 if (!dynamic) {
171 warnx("%s: not a dynamic executable", *argv);
172 file_ok = 0;
173 } else if (hdr.elf.e_type == ET_DYN) {
174 is_shlib = 1;
170 }
171 } else {
172 warnx("%s: not a dynamic executable", *argv);
173 file_ok = 0;
174 }
175 (void)close(fd);
176 if (!file_ok) {
177 rval |= 1;

--- 21 unchanged lines hidden (view full) ---

199 rval |= 1;
200 } else if (WIFEXITED(status) && WEXITSTATUS(status)) {
201 fprintf(stderr, "%s: exit status %d\n",
202 *argv, WEXITSTATUS(status));
203 rval |= 1;
204 }
205 break;
206 case 0:
175 }
176 } else {
177 warnx("%s: not a dynamic executable", *argv);
178 file_ok = 0;
179 }
180 (void)close(fd);
181 if (!file_ok) {
182 rval |= 1;

--- 21 unchanged lines hidden (view full) ---

204 rval |= 1;
205 } else if (WIFEXITED(status) && WEXITSTATUS(status)) {
206 fprintf(stderr, "%s: exit status %d\n",
207 *argv, WEXITSTATUS(status));
208 rval |= 1;
209 }
210 break;
211 case 0:
207 execl(*argv, *argv, (char *)NULL);
208 warn("%s", *argv);
212 if (is_shlib == 0) {
213 execl(*argv, *argv, (char *)NULL);
214 warn("%s", *argv);
215 } else {
216 dlopen(*argv, RTLD_TRACE);
217 warnx("%s: %s", *argv, dlerror());
218 }
209 _exit(1);
210 }
211 }
212
213 return rval;
214}
219 _exit(1);
220 }
221 }
222
223 return rval;
224}