comparison main.c @ 0:b8f7423e385c

import 0.13
author Peter Meerwald <pmeerw@pmeerw.net>
date Fri, 20 Jul 2012 01:51:24 +0200
parents
children 7bf4a164d5bb
comparison
equal deleted inserted replaced
-1:000000000000 0:b8f7423e385c
1 /*
2 * Author: Petter Reinholdtsen <pere@hungry.com>
3 * date: 2001-01-20
4 *
5 * Alter ELF rpath information (insert, modify, remove).
6 *
7 * Based on source from Peeter Joot <peeterj@ca.ibm.com> and Geoffrey
8 * Keating <geoffk@ozemail.com.au>.
9 */
10
11 #ifdef HAVE_CONFIG_H
12 # include "config.h"
13 #endif
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <unistd.h>
18 #ifdef HAVE_GETOPT_H
19 #include <getopt.h>
20 #endif
21 #include "protos.h"
22
23 #ifdef HAVE_GETOPT_LONG
24 # define GETOPT_LONG getopt_long
25
26 static struct option long_options[] =
27 {
28 {"convert", 0, 0, 'c'},
29 {"delete", 0, 0, 'd'},
30 {"help", 0, 0, 'h'},
31 {"keepgoing", 0, 0, 'k'},
32 {"list", 0, 0, 'l'},
33 {"replace", 1, 0, 'r'},
34 {"version", 0, 0, 'v'}
35 };
36
37 #else /* not HAVE_GETOPT_LONG */
38 # define GETOPT_LONG(argc,argv,optstr,lopts,lidx) getopt(argc,argv,optstr)
39 #endif /* not HAVE_GETOPT_LONG */
40
41 static void
42 usage(char *progname)
43 {
44 printf("Usage: %s [-v|-d|-c|-r <path>] <program> [<program> ...]\n\n",
45 progname);
46 printf(" -v|--version Display program version number\n");
47 printf(" -d|--delete Delete current rpath/runpath setting\n");
48 #if defined(DT_RUNPATH)
49 printf(" -c|--convert Convert rpath to runpath\n");
50 #endif /* DT_RUNPATH */
51 printf(" -r <path>|--replace <path> Replace current rpath/runpath setting\n");
52 printf(" with the path given\n");
53 printf(" -l|--list List the current rpath/runpath (default)\n");
54 printf(" -h|--help Show this usage information.\n");
55 #ifndef HAVE_GETOPT_LONG
56 printf("\n *** The long options are not available on this platform");
57 #endif /* not HAVE_GETOPT_LONG */
58 #if !defined(DT_RUNPATH)
59 printf("\n *** There is no support for runpath on this platform");
60 #endif /* DT_RUNPATH */
61 printf("\n");
62 }
63
64 int
65 main(int argc, char * const argv[])
66 {
67 int retval = 0;
68 int convert = 0; /* convert to given type */
69 int remove = 0; /* remove or not */
70 int keep_going = 0; /* Break on first error, or keep going? */
71 char *newpath = NULL; /* insert this path */
72 int opt;
73 #ifdef HAVE_GETOPT_LONG
74 int option_index = 0;
75 #endif /* HAVE_GETOPT_LONG */
76
77 if (argc < 2)
78 {
79 usage(argv[0]);
80 return 1;
81 }
82
83 do {
84 opt = GETOPT_LONG(argc, argv, "cdhklr:v", long_options, &option_index);
85 switch (opt)
86 {
87 #if defined(DT_RUNPATH)
88 case 'c':
89 convert = 1;
90 break;
91 #endif /* DT_RUNPATH */
92 case 'd':
93 remove = 1;
94 break;
95 case 'k':
96 keep_going = 1;
97 break;
98 case 'r':
99 newpath = optarg;
100 break;
101 case 'v':
102 printf("%s version %s\n", PACKAGE, VERSION);
103 exit(0);
104 break;
105 case 'l': /* This is the default action */
106 newpath = NULL;
107 break;
108 case -1:
109 break;
110 default:
111 printf("Invalid argument '%c'\n", opt);
112 case 'h':
113 usage(argv[0]);
114 exit(0);
115 break;
116 }
117 } while (-1 != opt);
118
119 while (optind < argc && (!retval || keep_going))
120 {
121 if (remove)
122 retval |= killrpath(argv[optind++]);
123 else
124 /* list by default, replace if path is set */
125 retval |= chrpath(argv[optind++], newpath, convert);
126 }
127
128 return retval;
129 }

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.