]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/lddlibc4.c
1 /* Stub for ldd script to print Linux libc4 dependencies.
2 Copyright (C) 1998-2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 /* This code is based on the `ldd' program code from the Linux ld.so
32 /* Get libc version number. */
33 #include "../version.h"
35 #define PACKAGE _libc_intl_domainname
39 main (int argc
, char *argv
[])
47 /* Set locale via LC_ALL. */
48 setlocale (LC_ALL
, "");
50 /* Set the text message domain. */
53 /* We expect exactly one argument. */
57 if (strcmp (argv
[1], "--help") == 0)
59 printf (gettext ("Usage: lddlibc4 FILE\n\n"));
60 printf (gettext ("For bug reporting instructions, please see:\n\
61 %s.\n"), REPORT_BUGS_TO
);
64 else if (strcmp (argv
[1], "--version") == 0)
66 printf ("lddlibc4 %s%s\n", PKGVERSION
, VERSION
);
68 Copyright (C) %s Free Software Foundation, Inc.\n\
69 This is free software; see the source for copying conditions. There is NO\n\
70 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
77 /* First see whether this is really an a.out binary. */
78 fp
= fopen (filename
, "rb");
80 error (2, errno
, gettext ("cannot open `%s'"), filename
);
82 /* Read the program header. */
83 if (fread (&exec
, sizeof exec
, 1, fp
) < 1)
84 error (2, errno
, gettext ("cannot read header from `%s'"), filename
);
86 /* Test for the magic numbers. */
87 if (N_MAGIC (exec
) != ZMAGIC
&& N_MAGIC (exec
) != QMAGIC
88 && N_MAGIC (exec
) != OMAGIC
)
91 /* We don't need the file open anymore. */
94 /* We must put `__LDD_ARGV0=<program-name>' in the environment. */
95 filename_len
= strlen (filename
);
96 buf
= (char *) alloca (sizeof "__LDD_ARGV0=" + filename_len
);
97 mempcpy (mempcpy (buf
, "__LDD_ARGV0=", sizeof "__LDD_ARGV0=" - 1),
98 filename
, filename_len
+ 1);
99 /* ...and put the value in the environment. */
102 /* Now we can execute the binary. */
103 return execv (filename
, &argv
[argc
]) ? 4 : 0;