]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/lddlibc4.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / lddlibc4.c
CommitLineData
528c1f1c 1/* Stub for ldd script to print Linux libc4 dependencies.
2b778ceb 2 Copyright (C) 1998-2021 Free Software Foundation, Inc.
528c1f1c
UD
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
5
6 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
528c1f1c
UD
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 14 Lesser General Public License for more details.
528c1f1c 15
41bdb6e2 16 You should have received a copy of the GNU Lesser General Public
59ba27a6 17 License along with the GNU C Library; if not, see
5a82c748 18 <https://www.gnu.org/licenses/>. */
528c1f1c
UD
19
20/* This code is based on the `ldd' program code from the Linux ld.so
21 package. */
22
23#include <a.out.h>
24#include <errno.h>
e2102c14 25#include <error.h>
528c1f1c
UD
26#include <libintl.h>
27#include <locale.h>
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31#include <unistd.h>
32
33/* Get libc version number. */
34#include "../version.h"
35
36#define PACKAGE _libc_intl_domainname
37
38
39int
40main (int argc, char *argv[])
41{
42 const char *filename;
43 size_t filename_len;
44 struct exec exec;
45 char *buf;
46 FILE *fp;
47
48 /* Set locale via LC_ALL. */
49 setlocale (LC_ALL, "");
50
51 /* Set the text message domain. */
52 textdomain (PACKAGE);
53
54 /* We expect exactly one argument. */
55 if (argc != 2)
56 return 1;
57
cbbcaf23
UD
58 if (strcmp (argv[1], "--help") == 0)
59 {
60 printf (gettext ("Usage: lddlibc4 FILE\n\n"));
8b748aed
JM
61 printf (gettext ("For bug reporting instructions, please see:\n\
62%s.\n"), REPORT_BUGS_TO);
cbbcaf23
UD
63 return 0;
64 }
65 else if (strcmp (argv[1], "--version") == 0)
66 {
8b748aed 67 printf ("lddlibc4 %s%s\n", PKGVERSION, VERSION);
cbbcaf23
UD
68 printf (gettext ("\
69Copyright (C) %s Free Software Foundation, Inc.\n\
70This is free software; see the source for copying conditions. There is NO\n\
71warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
5f72f980 72"), "2020");
cbbcaf23
UD
73 return 0;
74 }
75
528c1f1c
UD
76 filename = argv[1];
77
78 /* First see whether this is really an a.out binary. */
79 fp = fopen (filename, "rb");
80 if (fp == NULL)
81 error (2, errno, gettext ("cannot open `%s'"), filename);
82
83 /* Read the program header. */
84 if (fread (&exec, sizeof exec, 1, fp) < 1)
85 error (2, errno, gettext ("cannot read header from `%s'"), filename);
86
87 /* Test for the magic numbers. */
88 if (N_MAGIC (exec) != ZMAGIC && N_MAGIC (exec) != QMAGIC
89 && N_MAGIC (exec) != OMAGIC)
90 exit (3);
91
92 /* We don't need the file open anymore. */
93 fclose (fp);
94
e2e9ee17 95 /* We must put `__LDD_ARGV0=<program-name>' in the environment. */
528c1f1c
UD
96 filename_len = strlen (filename);
97 buf = (char *) alloca (sizeof "__LDD_ARGV0=" + filename_len);
98 mempcpy (mempcpy (buf, "__LDD_ARGV0=", sizeof "__LDD_ARGV0=" - 1),
e2e9ee17 99 filename, filename_len + 1);
528c1f1c
UD
100 /* ...and put the value in the environment. */
101 putenv (buf);
102
103 /* Now we can execute the binary. */
3dead500 104 return execv (filename, &argv[argc]) ? 4 : 0;
528c1f1c 105}