Deleted Added
full compact
ctfconvert.c (178529) ctfconvert.c (178546)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

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

41#include <assert.h>
42
43#include "ctftools.h"
44#include "memory.h"
45
46const char *progname;
47int debug_level = DEBUG_LEVEL;
48
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

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

41#include <assert.h>
42
43#include "ctftools.h"
44#include "memory.h"
45
46const char *progname;
47int debug_level = DEBUG_LEVEL;
48
49static const char *infile = NULL;
49static char *infile = NULL;
50static const char *outfile = NULL;
51static int dynsym;
52
53static void
54usage(void)
55{
56 (void) fprintf(stderr,
57 "Usage: %s [-gis] -l label | -L labelenv [-o outfile] object_file\n"
58 "\n"
59 " Note: if -L labelenv is specified and labelenv is not set in\n"
60 " the environment, a default value is used.\n",
61 progname);
62}
63
64static void
65terminate_cleanup(void)
66{
50static const char *outfile = NULL;
51static int dynsym;
52
53static void
54usage(void)
55{
56 (void) fprintf(stderr,
57 "Usage: %s [-gis] -l label | -L labelenv [-o outfile] object_file\n"
58 "\n"
59 " Note: if -L labelenv is specified and labelenv is not set in\n"
60 " the environment, a default value is used.\n",
61 progname);
62}
63
64static void
65terminate_cleanup(void)
66{
67#if !defined(__FreeBSD__)
67 if (!outfile) {
68 fprintf(stderr, "Removing %s\n", infile);
69 unlink(infile);
70 }
68 if (!outfile) {
69 fprintf(stderr, "Removing %s\n", infile);
70 unlink(infile);
71 }
72#endif
71}
72
73static void
74handle_sig(int sig)
75{
76 terminate("Caught signal %d - exiting\n", sig);
77}
78
79static int
73}
74
75static void
76handle_sig(int sig)
77{
78 terminate("Caught signal %d - exiting\n", sig);
79}
80
81static int
80file_read(tdata_t *td, const char *filename, int ignore_non_c)
82file_read(tdata_t *td, char *filename, int ignore_non_c)
81{
83{
82 typedef int (*reader_f)(tdata_t *, Elf *, const char *);
83 static const reader_f readers[] = {
84 typedef int (*reader_f)(tdata_t *, Elf *, char *);
85 static reader_f readers[] = {
84 stabs_read,
85 dw_read,
86 NULL
87 };
88
89 source_types_t source_types;
90 Elf *elf;
91 int i, rc, fd;

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

142
143 return (rc);
144}
145
146int
147main(int argc, char **argv)
148{
149 tdata_t *filetd, *mstrtd;
86 stabs_read,
87 dw_read,
88 NULL
89 };
90
91 source_types_t source_types;
92 Elf *elf;
93 int i, rc, fd;

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

144
145 return (rc);
146}
147
148int
149main(int argc, char **argv)
150{
151 tdata_t *filetd, *mstrtd;
150 char *label = NULL;
152 const char *label = NULL;
151 int verbose = 0;
152 int ignore_non_c = 0;
153 int keep_stabs = 0;
154 int c;
155
153 int verbose = 0;
154 int ignore_non_c = 0;
155 int keep_stabs = 0;
156 int c;
157
158#if defined(sun)
156 sighold(SIGINT);
157 sighold(SIGQUIT);
158 sighold(SIGTERM);
159 sighold(SIGINT);
160 sighold(SIGQUIT);
161 sighold(SIGTERM);
162#endif
159
160 progname = basename(argv[0]);
161
162 if (getenv("CTFCONVERT_DEBUG_LEVEL"))
163 debug_level = atoi(getenv("CTFCONVERT_DEBUG_LEVEL"));
164 if (getenv("CTFCONVERT_DEBUG_PARSE"))
165 debug_parse = atoi(getenv("CTFCONVERT_DEBUG_PARSE"));
166

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

212 * such that a subsequent make will eventually cause this command to
213 * be re-run. If we remove the input file (which we do if we get a
214 * signal and the user didn't specify a separate output file), make
215 * will need to rebuild the input file, and will then need to re-run
216 * ctfconvert, which is what we want.
217 */
218 set_terminate_cleanup(terminate_cleanup);
219
163
164 progname = basename(argv[0]);
165
166 if (getenv("CTFCONVERT_DEBUG_LEVEL"))
167 debug_level = atoi(getenv("CTFCONVERT_DEBUG_LEVEL"));
168 if (getenv("CTFCONVERT_DEBUG_PARSE"))
169 debug_parse = atoi(getenv("CTFCONVERT_DEBUG_PARSE"));
170

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

216 * such that a subsequent make will eventually cause this command to
217 * be re-run. If we remove the input file (which we do if we get a
218 * signal and the user didn't specify a separate output file), make
219 * will need to rebuild the input file, and will then need to re-run
220 * ctfconvert, which is what we want.
221 */
222 set_terminate_cleanup(terminate_cleanup);
223
224#if defined(sun)
220 sigset(SIGINT, handle_sig);
221 sigset(SIGQUIT, handle_sig);
222 sigset(SIGTERM, handle_sig);
225 sigset(SIGINT, handle_sig);
226 sigset(SIGQUIT, handle_sig);
227 sigset(SIGTERM, handle_sig);
228#else
229 signal(SIGINT, handle_sig);
230 signal(SIGQUIT, handle_sig);
231 signal(SIGTERM, handle_sig);
232#endif
223
224 filetd = tdata_new();
225
226 if (!file_read(filetd, infile, ignore_non_c))
227 terminate("%s doesn't have type data to convert\n", infile);
228
229 if (verbose)
230 iidesc_stats(filetd->td_iihash);

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

238 * If the user supplied an output file that is different from the
239 * input file, write directly to the output file. Otherwise, write
240 * to a temporary file, and replace the input file when we're done.
241 */
242 if (outfile && strcmp(infile, outfile) != 0) {
243 write_ctf(mstrtd, infile, outfile, dynsym | keep_stabs);
244 } else {
245 char *tmpname = mktmpname(infile, ".ctf");
233
234 filetd = tdata_new();
235
236 if (!file_read(filetd, infile, ignore_non_c))
237 terminate("%s doesn't have type data to convert\n", infile);
238
239 if (verbose)
240 iidesc_stats(filetd->td_iihash);

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

248 * If the user supplied an output file that is different from the
249 * input file, write directly to the output file. Otherwise, write
250 * to a temporary file, and replace the input file when we're done.
251 */
252 if (outfile && strcmp(infile, outfile) != 0) {
253 write_ctf(mstrtd, infile, outfile, dynsym | keep_stabs);
254 } else {
255 char *tmpname = mktmpname(infile, ".ctf");
246
247 write_ctf(mstrtd, infile, tmpname, dynsym | keep_stabs);
248 if (rename(tmpname, infile) != 0)
249 terminate("Couldn't rename temp file %s", tmpname);
250 free(tmpname);
251 }
252
253 return (0);
254}
256 write_ctf(mstrtd, infile, tmpname, dynsym | keep_stabs);
257 if (rename(tmpname, infile) != 0)
258 terminate("Couldn't rename temp file %s", tmpname);
259 free(tmpname);
260 }
261
262 return (0);
263}