Don't try to cleanup libselinux and libaudit.
[glibc.git] / sysdeps / unix / sysv / linux / lddlibc4.c
blob694d1291cd056b3b911fc3b1ac9237d9e5392a7e
1 /* Stub for ldd script to print Linux libc4 dependencies.
2 Copyright (C) 1998, 2005, 2009 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
6 The GNU C Library is free software; you can redistribute it and/or
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.
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
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 /* This code is based on the `ldd' program code from the Linux ld.so
22 package. */
24 #include <a.out.h>
25 #include <errno.h>
26 #include <error.h>
27 #include <libintl.h>
28 #include <locale.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <unistd.h>
34 /* Get libc version number. */
35 #include "../version.h"
37 #define PACKAGE _libc_intl_domainname
40 int
41 main (int argc, char *argv[])
43 const char *filename;
44 size_t filename_len;
45 struct exec exec;
46 char *buf;
47 FILE *fp;
49 /* Set locale via LC_ALL. */
50 setlocale (LC_ALL, "");
52 /* Set the text message domain. */
53 textdomain (PACKAGE);
55 /* We expect exactly one argument. */
56 if (argc != 2)
57 return 1;
59 if (strcmp (argv[1], "--help") == 0)
61 printf (gettext ("Usage: lddlibc4 FILE\n\n"));
62 printf (gettext ("For bug reporting instructions, please see:\n\
63 <http://www.gnu.org/software/libc/bugs.html>.\n"));
64 return 0;
66 else if (strcmp (argv[1], "--version") == 0)
68 printf ("lddlibc4 (GNU %s) %s\n", PACKAGE, VERSION);
69 printf (gettext ("\
70 Copyright (C) %s Free Software Foundation, Inc.\n\
71 This is free software; see the source for copying conditions. There is NO\n\
72 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
73 "), "2009");
74 return 0;
77 filename = argv[1];
79 /* First see whether this is really an a.out binary. */
80 fp = fopen (filename, "rb");
81 if (fp == NULL)
82 error (2, errno, gettext ("cannot open `%s'"), filename);
84 /* Read the program header. */
85 if (fread (&exec, sizeof exec, 1, fp) < 1)
86 error (2, errno, gettext ("cannot read header from `%s'"), filename);
88 /* Test for the magic numbers. */
89 if (N_MAGIC (exec) != ZMAGIC && N_MAGIC (exec) != QMAGIC
90 && N_MAGIC (exec) != OMAGIC)
91 exit (3);
93 /* We don't need the file open anymore. */
94 fclose (fp);
96 /* We must put `__LDD_ARGV0=<program-name>' in the environment. */
97 filename_len = strlen (filename);
98 buf = (char *) alloca (sizeof "__LDD_ARGV0=" + filename_len);
99 mempcpy (mempcpy (buf, "__LDD_ARGV0=", sizeof "__LDD_ARGV0=" - 1),
100 filename, filename_len + 1);
101 /* ...and put the value in the environment. */
102 putenv (buf);
104 /* Now we can execute the binary. */
105 return execv (filename, &argv[argc]) ? 4 : 0;