int canonical_filename_eq (const char * a, const char * b) { char * ca = lrealpath(a); char * cb = lrealpath(b); int res = filename_eq (ca, cb); free (ca); free (cb); return res; }
static bfd_boolean is_sysrooted_pathname (const char *name, bfd_boolean notsame) { char * realname = ld_canon_sysroot ? lrealpath (name) : NULL; int len; bfd_boolean result; if (! realname) return FALSE; len = strlen (realname); if (((! notsame && len == ld_canon_sysroot_len) || (len >= ld_canon_sysroot_len && IS_DIR_SEPARATOR (realname[ld_canon_sysroot_len]) && (realname[ld_canon_sysroot_len] = '\0') == '\0')) && FILENAME_CMP (ld_canon_sysroot, realname) == 0) result = TRUE; else result = FALSE; if (realname) free (realname); return result; }
char * relocate_gdb_directory (const char *initial, int flag) { char *dir; dir = relocate_path (gdb_program_name, initial, flag); if (dir) { struct stat s; if (*dir == '\0' || stat (dir, &s) != 0 || !S_ISDIR (s.st_mode)) { xfree (dir); dir = NULL; } } if (!dir) dir = xstrdup (initial); /* Canonicalize the directory. */ if (*dir) { char *canon_sysroot = lrealpath (dir); if (canon_sysroot) { xfree (dir); dir = canon_sysroot; } } return dir; }
static DBusHandlerResult handle_get_filename (DBusConnection * connection, DBusMessage * message, void *data) { DBusMessage *reply; DBusMessageIter iter; DBusHandlerResult result; char *filename; result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED; // TODO: Should check the message signature matches what we expect? reply = dbus_message_new_method_return (message); if (reply == NULL) { fprintf (stderr, "pcb_dbus: Couldn't create reply message\n"); return result; } dbus_message_iter_init_append (reply, &iter); if (PCB->Filename) filename = lrealpath (PCB->Filename); else filename = NULL; if (filename == NULL) { #ifdef DEBUG fprintf (stderr, "pcb_dbus: DEBUG: Couldn't get working filename, assuming none\n"); #endif filename = strdup (""); if (filename == NULL) { fprintf (stderr, "pcb_dbus: Couldn't strdup( \"\" ) for the filename\n"); goto out; } } if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &filename)) { fprintf (stderr, "pcb_dbus: Couldn't append return filename string to message reply, Out Of Memory!\n"); free (filename); goto out; } free (filename); if (!dbus_connection_send (connection, reply, NULL)) { fprintf (stderr, "pcb_dbus: Couldn't send message, Out Of Memory!\n"); goto out; } result = DBUS_HANDLER_RESULT_HANDLED; out: dbus_message_unref (reply); return result; }
optional<std::string> check_file_core(std::string file, char const * ext) { if (ext) file += ext; std::ifstream ifile(file); if (ifile) return optional<std::string>(lrealpath(file)); else return optional<std::string>(); }
optional<std::string> get_leanpkg_path_file() { auto dir = lrealpath("."); while (true) { auto fn = dir + get_dir_sep() + "leanpkg.path"; if (exists(fn)) return optional<std::string>(fn); auto i = dir.rfind(get_dir_sep()); if (i == std::string::npos) { return optional<std::string>(); } else { dir = dir.substr(0, i); } } }
static bfd_boolean is_sysrooted_pathname (const char *name) { char *realname; int len; bfd_boolean result; if (ld_canon_sysroot == NULL) return FALSE; realname = lrealpath (name); len = strlen (realname); result = FALSE; if (len > ld_canon_sysroot_len && IS_DIR_SEPARATOR (realname[ld_canon_sysroot_len])) { realname[ld_canon_sysroot_len] = '\0'; result = FILENAME_CMP (ld_canon_sysroot, realname) == 0; } free (realname); return result; }
int main (int argc, char **argv) { char *emulation; long start_time = get_run_time (); #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) setlocale (LC_MESSAGES, ""); #endif #if defined (HAVE_SETLOCALE) setlocale (LC_CTYPE, ""); #endif bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); program_name = argv[0]; xmalloc_set_program_name (program_name); START_PROGRESS (program_name, 0); expandargv (&argc, &argv); bfd_init (); bfd_set_error_program_name (program_name); xatexit (ld_cleanup); /* Set up the sysroot directory. */ ld_sysroot = get_sysroot (argc, argv); if (*ld_sysroot) { if (*TARGET_SYSTEM_ROOT == 0) { einfo ("%P%F: this linker was not configured to use sysroots\n"); ld_sysroot = ""; } else ld_canon_sysroot = lrealpath (ld_sysroot); } if (ld_canon_sysroot) ld_canon_sysroot_len = strlen (ld_canon_sysroot); else ld_canon_sysroot_len = -1; /* Set the default BFD target based on the configured target. Doing this permits the linker to be configured for a particular target, and linked against a shared BFD library which was configured for a different target. The macro TARGET is defined by Makefile. */ if (! bfd_set_default_target (TARGET)) { einfo (_("%X%P: can't set BFD default target to `%s': %E\n"), TARGET); xexit (1); } #if YYDEBUG { extern int yydebug; yydebug = 1; } #endif config.build_constructors = TRUE; config.rpath_separator = ':'; config.split_by_reloc = (unsigned) -1; config.split_by_file = (bfd_size_type) -1; config.make_executable = TRUE; config.magic_demand_paged = TRUE; config.text_read_only = TRUE; command_line.warn_mismatch = TRUE; command_line.warn_search_mismatch = TRUE; command_line.check_section_addresses = -1; command_line.disable_target_specific_optimizations = -1; /* We initialize DEMANGLING based on the environment variable COLLECT_NO_DEMANGLE. The gcc collect2 program will demangle the output of the linker, unless COLLECT_NO_DEMANGLE is set in the environment. Acting the same way here lets us provide the same interface by default. */ demangling = getenv ("COLLECT_NO_DEMANGLE") == NULL; link_info.allow_undefined_version = TRUE; link_info.keep_memory = TRUE; link_info.combreloc = TRUE; link_info.strip_discarded = TRUE; link_info.emit_hash = TRUE; link_info.callbacks = &link_callbacks; link_info.input_bfds_tail = &link_info.input_bfds; /* SVR4 linkers seem to set DT_INIT and DT_FINI based on magic _init and _fini symbols. We are compatible. */ link_info.init_function = "_init"; link_info.fini_function = "_fini"; link_info.relax_pass = 1; link_info.pei386_auto_import = -1; link_info.spare_dynamic_tags = 5; link_info.path_separator = ':'; ldfile_add_arch (""); emulation = get_emulation (argc, argv); ldemul_choose_mode (emulation); default_target = ldemul_choose_target (argc, argv); config.maxpagesize = bfd_emul_get_maxpagesize (default_target); config.commonpagesize = bfd_emul_get_commonpagesize (default_target); lang_init (); ldemul_before_parse (); lang_has_input_file = FALSE; parse_args (argc, argv); if (config.hash_table_size != 0) bfd_hash_set_default_size (config.hash_table_size); ldemul_set_symbols (); if (link_info.relocatable) { if (command_line.check_section_addresses < 0) command_line.check_section_addresses = 0; if (link_info.shared) einfo (_("%P%F: -r and -shared may not be used together\n")); } /* We may have -Bsymbolic, -Bsymbolic-functions, --dynamic-list-data, --dynamic-list-cpp-new, --dynamic-list-cpp-typeinfo and --dynamic-list FILE. -Bsymbolic and -Bsymbolic-functions are for shared libraries. -Bsymbolic overrides all others and vice versa. */ switch (command_line.symbolic) { case symbolic_unset: break; case symbolic: /* -Bsymbolic is for shared library only. */ if (link_info.shared) { link_info.symbolic = TRUE; /* Should we free the unused memory? */ link_info.dynamic_list = NULL; command_line.dynamic_list = dynamic_list_unset; } break; case symbolic_functions: /* -Bsymbolic-functions is for shared library only. */ if (link_info.shared) command_line.dynamic_list = dynamic_list_data; break; } switch (command_line.dynamic_list) { case dynamic_list_unset: break; case dynamic_list_data: link_info.dynamic_data = TRUE; case dynamic_list: link_info.dynamic = TRUE; break; } if (! link_info.shared) { if (command_line.filter_shlib) einfo (_("%P%F: -F may not be used without -shared\n")); if (command_line.auxiliary_filters) einfo (_("%P%F: -f may not be used without -shared\n")); } if (! link_info.shared || link_info.pie) link_info.executable = TRUE; /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols). I don't see how else this can be handled, since in this case we must preserve all externally visible symbols. */ if (link_info.relocatable && link_info.strip == strip_all) { link_info.strip = strip_debugger; if (link_info.discard == discard_sec_merge) link_info.discard = discard_all; } /* If we have not already opened and parsed a linker script, try the default script from command line first. */ if (saved_script_handle == NULL && command_line.default_script != NULL) { ldfile_open_command_file (command_line.default_script); parser_input = input_script; yyparse (); } /* If we have not already opened and parsed a linker script read the emulation's appropriate default script. */ if (saved_script_handle == NULL) { int isfile; char *s = ldemul_get_script (&isfile); if (isfile) ldfile_open_default_command_file (s); else { lex_string = s; lex_redirect (s); } parser_input = input_script; yyparse (); lex_string = NULL; } if (trace_file_tries) { if (saved_script_handle) info_msg (_("using external linker script:")); else info_msg (_("using internal linker script:")); info_msg ("\n==================================================\n"); if (saved_script_handle) { static const int ld_bufsz = 8193; size_t n; char *buf = (char *) xmalloc (ld_bufsz); rewind (saved_script_handle); while ((n = fread (buf, 1, ld_bufsz - 1, saved_script_handle)) > 0) { buf[n] = 0; info_msg (buf); } rewind (saved_script_handle); free (buf); } else { int isfile; info_msg (ldemul_get_script (&isfile)); } info_msg ("\n==================================================\n"); } lang_final (); if (!lang_has_input_file) { if (version_printed) xexit (0); einfo (_("%P%F: no input files\n")); } if (trace_files) info_msg (_("%P: mode %s\n"), emulation); ldemul_after_parse (); if (config.map_filename) { if (strcmp (config.map_filename, "-") == 0) { config.map_file = stdout; } else { config.map_file = fopen (config.map_filename, FOPEN_WT); if (config.map_file == (FILE *) NULL) { bfd_set_error (bfd_error_system_call); einfo (_("%P%F: cannot open map file %s: %E\n"), config.map_filename); } } } lang_process (); /* Print error messages for any missing symbols, for any warning symbols, and possibly multiple definitions. */ if (link_info.relocatable) link_info.output_bfd->flags &= ~EXEC_P; else link_info.output_bfd->flags |= EXEC_P; ldwrite (); if (config.map_file != NULL) lang_map (); if (command_line.cref) output_cref (config.map_file != NULL ? config.map_file : stdout); if (nocrossref_list != NULL) check_nocrossrefs (); lang_finish (); /* Even if we're producing relocatable output, some non-fatal errors should be reported in the exit status. (What non-fatal errors, if any, do we want to ignore for relocatable output?) */ if (!config.make_executable && !force_make_executable) { if (trace_files) einfo (_("%P: link errors found, deleting executable `%s'\n"), output_filename); /* The file will be removed by remove_output. */ xexit (1); } else { if (! bfd_close (link_info.output_bfd)) einfo (_("%F%B: final close failed: %E\n"), link_info.output_bfd); /* If the --force-exe-suffix is enabled, and we're making an executable file and it doesn't end in .exe, copy it to one which does. */ if (! link_info.relocatable && command_line.force_exe_suffix) { int len = strlen (output_filename); if (len < 4 || (strcasecmp (output_filename + len - 4, ".exe") != 0 && strcasecmp (output_filename + len - 4, ".dll") != 0)) { FILE *src; FILE *dst; const int bsize = 4096; char *buf = (char *) xmalloc (bsize); int l; char *dst_name = (char *) xmalloc (len + 5); strcpy (dst_name, output_filename); strcat (dst_name, ".exe"); src = fopen (output_filename, FOPEN_RB); dst = fopen (dst_name, FOPEN_WB); if (!src) einfo (_("%X%P: unable to open for source of copy `%s'\n"), output_filename); if (!dst) einfo (_("%X%P: unable to open for destination of copy `%s'\n"), dst_name); while ((l = fread (buf, 1, bsize, src)) > 0) { int done = fwrite (buf, 1, l, dst); if (done != l) einfo (_("%P: Error writing file `%s'\n"), dst_name); } fclose (src); if (fclose (dst) == EOF) einfo (_("%P: Error closing file `%s'\n"), dst_name); free (dst_name); free (buf); } } } END_PROGRESS (program_name); if (config.stats) { #ifdef HAVE_SBRK char *lim = (char *) sbrk (0); #endif long run_time = get_run_time () - start_time; fflush (stdout); fprintf (stderr, _("%s: total time in link: %ld.%06ld\n"), program_name, run_time / 1000000, run_time % 1000000); #ifdef HAVE_SBRK fprintf (stderr, _("%s: data size %ld\n"), program_name, (long) (lim - (char *) &environ)); #endif fflush (stderr); } /* Prevent remove_output from doing anything, after a successful link. */ output_filename = NULL; xexit (0); return 0; }
gdb_bfd_ref_ptr build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id) { char *link, *debugdir; VEC (char_ptr) *debugdir_vec; struct cleanup *back_to; int ix; gdb_bfd_ref_ptr abfd; int alloc_len; /* DEBUG_FILE_DIRECTORY/.build-id/ab/cdef */ alloc_len = (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1 + 2 * build_id_len + (sizeof ".debug" - 1) + 1); link = (char *) alloca (alloc_len); /* Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will cause "/.build-id/..." lookups. */ debugdir_vec = dirnames_to_char_ptr_vec (debug_file_directory); back_to = make_cleanup_free_char_ptr_vec (debugdir_vec); for (ix = 0; VEC_iterate (char_ptr, debugdir_vec, ix, debugdir); ++ix) { size_t debugdir_len = strlen (debugdir); const gdb_byte *data = build_id; size_t size = build_id_len; char *s; char *filename = NULL; struct cleanup *inner; memcpy (link, debugdir, debugdir_len); s = &link[debugdir_len]; s += sprintf (s, "/.build-id/"); if (size > 0) { size--; s += sprintf (s, "%02x", (unsigned) *data++); } if (size > 0) *s++ = '/'; while (size-- > 0) s += sprintf (s, "%02x", (unsigned) *data++); strcpy (s, ".debug"); if (separate_debug_file_debug) printf_unfiltered (_(" Trying %s\n"), link); /* lrealpath() is expensive even for the usually non-existent files. */ if (access (link, F_OK) == 0) filename = lrealpath (link); if (filename == NULL) continue; /* We expect to be silent on the non-existing files. */ inner = make_cleanup (xfree, filename); abfd = gdb_bfd_open (filename, gnutarget, -1); do_cleanups (inner); if (abfd == NULL) continue; if (build_id_verify (abfd.get(), build_id_len, build_id)) break; abfd.release (); } do_cleanups (back_to); return abfd; }
int main (int argc, char **argv) { char *emulation; long start_time = get_run_time (); #ifdef HAVE_SBRK char *start_sbrk = (char *) sbrk (0); #endif #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) setlocale (LC_MESSAGES, ""); #endif #if defined (HAVE_SETLOCALE) setlocale (LC_CTYPE, ""); #endif bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); program_name = argv[0]; xmalloc_set_program_name (program_name); START_PROGRESS (program_name, 0); expandargv (&argc, &argv); bfd_init (); bfd_set_error_program_name (program_name); /* We want to notice and fail on those nasty BFD assertions which are likely to signal incorrect output being generated but otherwise may leave no trace. */ default_bfd_assert_handler = bfd_set_assert_handler (ld_bfd_assert_handler); xatexit (ld_cleanup); /* Set up the sysroot directory. */ ld_sysroot = get_sysroot (argc, argv); if (*ld_sysroot) ld_canon_sysroot = lrealpath (ld_sysroot); if (ld_canon_sysroot) ld_canon_sysroot_len = strlen (ld_canon_sysroot); else ld_canon_sysroot_len = -1; /* Set the default BFD target based on the configured target. Doing this permits the linker to be configured for a particular target, and linked against a shared BFD library which was configured for a different target. The macro TARGET is defined by Makefile. */ if (! bfd_set_default_target (TARGET)) { einfo (_("%X%P: can't set BFD default target to `%s': %E\n"), TARGET); xexit (1); } #if YYDEBUG { extern int yydebug; yydebug = 1; } #endif config.build_constructors = TRUE; config.rpath_separator = ':'; config.split_by_reloc = (unsigned) -1; config.split_by_file = (bfd_size_type) -1; config.make_executable = TRUE; config.magic_demand_paged = TRUE; config.text_read_only = TRUE; link_info.disable_target_specific_optimizations = -1; command_line.warn_mismatch = TRUE; command_line.warn_search_mismatch = TRUE; command_line.check_section_addresses = -1; /* We initialize DEMANGLING based on the environment variable COLLECT_NO_DEMANGLE. The gcc collect2 program will demangle the output of the linker, unless COLLECT_NO_DEMANGLE is set in the environment. Acting the same way here lets us provide the same interface by default. */ demangling = getenv ("COLLECT_NO_DEMANGLE") == NULL; link_info.allow_undefined_version = TRUE; link_info.keep_memory = TRUE; link_info.combreloc = TRUE; link_info.strip_discarded = TRUE; link_info.emit_hash = TRUE; link_info.callbacks = &link_callbacks; link_info.input_bfds_tail = &link_info.input_bfds; /* SVR4 linkers seem to set DT_INIT and DT_FINI based on magic _init and _fini symbols. We are compatible. */ link_info.init_function = "_init"; link_info.fini_function = "_fini"; link_info.relax_pass = 1; link_info.extern_protected_data = -1; link_info.dynamic_undefined_weak = -1; link_info.pei386_auto_import = -1; link_info.spare_dynamic_tags = 5; link_info.path_separator = ':'; #ifdef DEFAULT_FLAG_COMPRESS_DEBUG link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB; #endif ldfile_add_arch (""); emulation = get_emulation (argc, argv); ldemul_choose_mode (emulation); default_target = ldemul_choose_target (argc, argv); config.maxpagesize = bfd_emul_get_maxpagesize (default_target); config.commonpagesize = bfd_emul_get_commonpagesize (default_target); lang_init (); ldexp_init (); ldemul_before_parse (); lang_has_input_file = FALSE; parse_args (argc, argv); if (config.hash_table_size != 0) bfd_hash_set_default_size (config.hash_table_size); #ifdef ENABLE_PLUGINS /* Now all the plugin arguments have been gathered, we can load them. */ plugin_load_plugins (); #endif /* ENABLE_PLUGINS */ ldemul_set_symbols (); /* If we have not already opened and parsed a linker script, try the default script from command line first. */ if (saved_script_handle == NULL && command_line.default_script != NULL) { ldfile_open_command_file (command_line.default_script); parser_input = input_script; yyparse (); } /* If we have not already opened and parsed a linker script read the emulation's appropriate default script. */ if (saved_script_handle == NULL) { int isfile; char *s = ldemul_get_script (&isfile); if (isfile) ldfile_open_default_command_file (s); else { lex_string = s; lex_redirect (s, _("built in linker script"), 1); } parser_input = input_script; yyparse (); lex_string = NULL; } if (verbose) { if (saved_script_handle) info_msg (_("using external linker script:")); else info_msg (_("using internal linker script:")); info_msg ("\n==================================================\n"); if (saved_script_handle) { static const int ld_bufsz = 8193; size_t n; char *buf = (char *) xmalloc (ld_bufsz); rewind (saved_script_handle); while ((n = fread (buf, 1, ld_bufsz - 1, saved_script_handle)) > 0) { buf[n] = 0; info_msg (buf); } rewind (saved_script_handle); free (buf); } else { int isfile; info_msg (ldemul_get_script (&isfile)); } info_msg ("\n==================================================\n"); } if (command_line.print_output_format) info_msg ("%s\n", lang_get_output_target ()); lang_final (); /* If the only command line argument has been -v or --version or --verbose then ignore any input files provided by linker scripts and exit now. We do not want to create an output file when the linker is just invoked to provide version information. */ if (argc == 2 && version_printed) xexit (0); if (!lang_has_input_file) { if (version_printed || command_line.print_output_format) xexit (0); einfo (_("%P%F: no input files\n")); } if (trace_files) info_msg (_("%P: mode %s\n"), emulation); ldemul_after_parse (); if (config.map_filename) { if (strcmp (config.map_filename, "-") == 0) { config.map_file = stdout; } else { config.map_file = fopen (config.map_filename, FOPEN_WT); if (config.map_file == (FILE *) NULL) { bfd_set_error (bfd_error_system_call); einfo (_("%P%F: cannot open map file %s: %E\n"), config.map_filename); } } } lang_process (); /* Print error messages for any missing symbols, for any warning symbols, and possibly multiple definitions. */ if (bfd_link_relocatable (&link_info)) link_info.output_bfd->flags &= ~EXEC_P; else link_info.output_bfd->flags |= EXEC_P; if ((link_info.compress_debug & COMPRESS_DEBUG)) { link_info.output_bfd->flags |= BFD_COMPRESS; if (link_info.compress_debug == COMPRESS_DEBUG_GABI_ZLIB) link_info.output_bfd->flags |= BFD_COMPRESS_GABI; } ldwrite (); if (config.map_file != NULL) lang_map (); if (command_line.cref) output_cref (config.map_file != NULL ? config.map_file : stdout); if (nocrossref_list != NULL) check_nocrossrefs (); if (command_line.print_memory_usage) lang_print_memory_usage (); #if 0 { struct bfd_link_hash_entry * h; h = bfd_link_hash_lookup (link_info.hash, "__image_base__", 0,0,1); fprintf (stderr, "lookup = %p val %lx\n", h, h ? h->u.def.value : 1); } #endif ldexp_finish (); lang_finish (); /* Even if we're producing relocatable output, some non-fatal errors should be reported in the exit status. (What non-fatal errors, if any, do we want to ignore for relocatable output?) */ if (!config.make_executable && !force_make_executable) { if (trace_files) einfo (_("%P: link errors found, deleting executable `%s'\n"), output_filename); /* The file will be removed by ld_cleanup. */ xexit (1); } else { if (! bfd_close (link_info.output_bfd)) einfo (_("%F%B: final close failed: %E\n"), link_info.output_bfd); /* If the --force-exe-suffix is enabled, and we're making an executable file and it doesn't end in .exe, copy it to one which does. */ if (!bfd_link_relocatable (&link_info) && command_line.force_exe_suffix) { int len = strlen (output_filename); if (len < 4 || (strcasecmp (output_filename + len - 4, ".exe") != 0 && strcasecmp (output_filename + len - 4, ".dll") != 0)) { FILE *src; FILE *dst; const int bsize = 4096; char *buf = (char *) xmalloc (bsize); int l; char *dst_name = (char *) xmalloc (len + 5); strcpy (dst_name, output_filename); strcat (dst_name, ".exe"); src = fopen (output_filename, FOPEN_RB); dst = fopen (dst_name, FOPEN_WB); if (!src) einfo (_("%P%F: unable to open for source of copy `%s'\n"), output_filename); if (!dst) einfo (_("%P%F: unable to open for destination of copy `%s'\n"), dst_name); while ((l = fread (buf, 1, bsize, src)) > 0) { int done = fwrite (buf, 1, l, dst); if (done != l) einfo (_("%P: Error writing file `%s'\n"), dst_name); } fclose (src); if (fclose (dst) == EOF) einfo (_("%P: Error closing file `%s'\n"), dst_name); free (dst_name); free (buf); } } } END_PROGRESS (program_name); if (config.stats) { #ifdef HAVE_SBRK char *lim = (char *) sbrk (0); #endif long run_time = get_run_time () - start_time; fflush (stdout); fprintf (stderr, _("%s: total time in link: %ld.%06ld\n"), program_name, run_time / 1000000, run_time % 1000000); #ifdef HAVE_SBRK fprintf (stderr, _("%s: data size %ld\n"), program_name, (long) (lim - start_sbrk)); #endif fflush (stderr); } /* Prevent ld_cleanup from doing anything, after a successful link. */ output_filename = NULL; xexit (0); return 0; }
static void InitPaths (char *argv0) { size_t l; int i; int haspath; char *t1, *t2; int found_bindir = 0; /* see if argv0 has enough of a path to let lrealpath give the * real path. This should be the case if you invoke pcb with * something like /usr/local/bin/pcb or ./pcb or ./foo/pcb * but if you just use pcb and it exists in your path, you'll * just get back pcb again. */ #ifdef FAKE_BINDIR haspath = 1; #else haspath = 0; for (i = 0; i < strlen (argv0) ; i++) { if (argv0[i] == PCB_DIR_SEPARATOR_C) haspath = 1; } #endif #ifdef DEBUG printf ("InitPaths (%s): haspath = %d\n", argv0, haspath); #endif if (haspath) { #ifdef FAKE_BINDIR bindir = strdup(FAKE_BINDIR "/"); #else bindir = strdup (lrealpath (argv0)); #endif found_bindir = 1; } else { char *path, *p, *tmps; struct stat sb; int r; tmps = getenv ("PATH"); if (tmps != NULL) { path = strdup (tmps); /* search through the font path for a font file */ for (p = strtok (path, PCB_PATH_DELIMETER); p && *p; p = strtok (NULL, PCB_PATH_DELIMETER)) { #ifdef DEBUG printf ("Looking for %s in %s\n", argv0, p); #endif if ( (tmps = (char *)malloc ( (strlen (argv0) + strlen (p) + 2) * sizeof (char))) == NULL ) { fprintf (stderr, "InitPaths(): malloc failed\n"); exit (1); } sprintf (tmps, "%s%s%s", p, PCB_DIR_SEPARATOR_S, argv0); r = stat (tmps, &sb); if (r == 0) { #ifdef DEBUG printf ("Found it: \"%s\"\n", tmps); #endif bindir = lrealpath (tmps); found_bindir = 1; free (tmps); break; } free (tmps); } free (path); } } #ifdef DEBUG printf ("InitPaths(): bindir = \"%s\"\n", bindir); #endif if (found_bindir) { /* strip off the executible name leaving only the path */ t2 = NULL; t1 = strchr (bindir, PCB_DIR_SEPARATOR_C); while (t1 != NULL && *t1 != '\0') { t2 = t1; t1 = strchr (t2 + 1, PCB_DIR_SEPARATOR_C); } if (t2 != NULL) *t2 = '\0'; #ifdef DEBUG printf ("After stripping off the executible name, we found\n"); printf ("bindir = \"%s\"\n", bindir); #endif } else { /* we have failed to find out anything from argv[0] so fall back to the original * install prefix */ bindir = strdup (BINDIR); } /* now find the path to exec_prefix */ l = strlen (bindir) + 1 + strlen (BINDIR_TO_EXECPREFIX) + 1; if ( (exec_prefix = (char *) malloc (l * sizeof (char) )) == NULL ) { fprintf (stderr, "InitPaths(): malloc failed\n"); exit (1); } sprintf (exec_prefix, "%s%s%s", bindir, PCB_DIR_SEPARATOR_S, BINDIR_TO_EXECPREFIX); /* now find the path to PCBSHAREDIR */ l = strlen (bindir) + 1 + strlen (BINDIR_TO_PCBSHAREDIR) + 1; if ( (pcblibdir = (char *) malloc (l * sizeof (char) )) == NULL ) { fprintf (stderr, "InitPaths(): malloc failed\n"); exit (1); } sprintf (pcblibdir, "%s%s%s", bindir, PCB_DIR_SEPARATOR_S, BINDIR_TO_PCBSHAREDIR); #ifdef DEBUG printf ("bindir = %s\n", bindir); printf ("pcblibdir = %s\n", pcblibdir); #endif l = sizeof (main_attribute_list) / sizeof (main_attribute_list[0]); for (i = 0; i < l ; i++) { if (NSTRCMP (main_attribute_list[i].name, "lib-command-dir") == 0) { main_attribute_list[i].default_val.str_value = pcblibdir; } if ( (NSTRCMP (main_attribute_list[i].name, "font-path") == 0) || (NSTRCMP (main_attribute_list[i].name, "element-path") == 0) || (NSTRCMP (main_attribute_list[i].name, "lib-path") == 0) ) { main_attribute_list[i].default_val.str_value = pcblibdir; } } { char *tmps; tmps = getenv ("HOME"); if (tmps == NULL) { tmps = getenv ("USERPROFILE"); } if (tmps != NULL) { homedir = strdup (tmps); } else { homedir = NULL; } } resolve_all_paths(fontfile_paths_in, fontfile_paths); }
static char * make_relative_prefix_1 (const char *progname, const char *bin_prefix, const char *prefix, const int resolve_links) { char **prog_dirs = NULL, **bin_dirs = NULL, **prefix_dirs = NULL; int prog_num, bin_num, prefix_num; int i, n, common; int needed_len; char *ret = NULL, *ptr, *full_progname; if (progname == NULL || bin_prefix == NULL || prefix == NULL) return NULL; /* If there is no full pathname, try to find the program by checking in each of the directories specified in the PATH environment variable. */ if (lbasename (progname) == progname) { char *temp; #if 0 temp = getenv ("PATH"); if (temp) { char *startp, *endp, *nstore; size_t prefixlen = strlen (temp) + 1; size_t len; if (prefixlen < 2) prefixlen = 2; len = prefixlen + strlen (progname) + 1; #ifdef HAVE_HOST_EXECUTABLE_SUFFIX len += strlen (HOST_EXECUTABLE_SUFFIX); #endif nstore = (char *) alloca (len); startp = endp = temp; while (1) { if (*endp == PATH_SEPARATOR || *endp == 0) { if (endp == startp) { nstore[0] = '.'; nstore[1] = DIR_SEPARATOR; nstore[2] = '\0'; } else { memcpy (nstore, startp, endp - startp); if (! IS_DIR_SEPARATOR (endp[-1])) { nstore[endp - startp] = DIR_SEPARATOR; nstore[endp - startp + 1] = 0; } else nstore[endp - startp] = 0; } strcat (nstore, progname); if (! access (nstore, X_OK) #ifdef HAVE_HOST_EXECUTABLE_SUFFIX || ! access (strcat (nstore, HOST_EXECUTABLE_SUFFIX), X_OK) #endif ) { #if defined (HAVE_SYS_STAT_H) && defined (S_ISREG) struct stat st; if (stat (nstore, &st) >= 0 && S_ISREG (st.st_mode)) #endif { progname = nstore; break; } } if (*endp == 0) break; endp = startp = endp + 1; } else endp++; } } #endif } if (resolve_links) full_progname = lrealpath (progname); else full_progname = strdup (progname); if (full_progname == NULL) return NULL; prog_dirs = split_directories (full_progname, &prog_num); free (full_progname); if (prog_dirs == NULL) return NULL; bin_dirs = split_directories (bin_prefix, &bin_num); if (bin_dirs == NULL) goto bailout; /* Remove the program name from comparison of directory names. */ prog_num--; /* If we are still installed in the standard location, we don't need to specify relative directories. Also, if argv[0] still doesn't contain any directory specifiers after the search above, then there is not much we can do. */ if (prog_num == bin_num) { for (i = 0; i < bin_num; i++) { if (strcmp (prog_dirs[i], bin_dirs[i]) != 0) break; } if (prog_num <= 0 || i == bin_num) goto bailout; } prefix_dirs = split_directories (prefix, &prefix_num); if (prefix_dirs == NULL) goto bailout; /* Find how many directories are in common between bin_prefix & prefix. */ n = (prefix_num < bin_num) ? prefix_num : bin_num; for (common = 0; common < n; common++) { if (strcmp (bin_dirs[common], prefix_dirs[common]) != 0) break; } /* If there are no common directories, there can be no relative prefix. */ if (common == 0) goto bailout; /* Two passes: first figure out the size of the result string, and then construct it. */ needed_len = 0; for (i = 0; i < prog_num; i++) needed_len += strlen (prog_dirs[i]); needed_len += sizeof (DIR_UP) * (bin_num - common); for (i = common; i < prefix_num; i++) needed_len += strlen (prefix_dirs[i]); needed_len += 1; /* Trailing NUL. */ ret = (char *) malloc (needed_len); if (ret == NULL) goto bailout; /* Build up the pathnames in argv[0]. */ *ret = '\0'; for (i = 0; i < prog_num; i++) strcat (ret, prog_dirs[i]); /* Now build up the ..'s. */ ptr = ret + strlen(ret); for (i = common; i < bin_num; i++) { strcpy (ptr, DIR_UP); ptr += sizeof (DIR_UP) - 1; *(ptr++) = DIR_SEPARATOR; } *ptr = '\0'; /* Put in directories to move over to prefix. */ for (i = common; i < prefix_num; i++) strcat (ret, prefix_dirs[i]); bailout: free_split_directories (prog_dirs); free_split_directories (bin_dirs); free_split_directories (prefix_dirs); return ret; }
DBusHandlerResult handle_dbus_message( DBusConnection *connection, DBusMessage *message, void *data ) { int eax; int esi; int msg_type; switch ( msg_type ) { default: break; case 4: break; case 3: break; case 2: break; case 1: { char *method_name; char *interface_name; if ( dbus_message_get_member( &message ) ) { if ( interface_name ) { /* phantom */ size_t __s1_len; /* phantom */ size_t __s2_len; strcmp( "org.seul.geda.pcb", interface_name ); if ( 1 ) { /* phantom */ size_t __s1_len; /* phantom */ size_t __s2_len; method_name[0] = dbus_message_get_member( &message ); strcmp( "GetFilename", dbus_message_get_member( &message ) ); if ( !1 ) { __fprintf_chk( stderr, 1, "pcb_dbus: Interface '%s' has no method '%s'\n", dbus_message_get_interface( &message ), ebp_184 ); return 1; } else { if ( dbus_message_new_method_return( &message ) ) { dbus_message_iter_init_append( dbus_message_new_method_return( &message ), ebp_112 ); if ( PCB->Filename ) { if ( lrealpath( &PCB->Filename ) == 0 ) goto B38; else { if ( dbus_message_iter_append_basic( ebp_112, 115, ebp_32 ) ) { free( ebp_32 ); } else { __fprintf_chk( stderr, 1, "pcb_dbus: Couldn't append return filename string to message reply, Out Of Memory!\n" ); free( ebp_32 ); dbus_message_unref( &ebx ); return 0; } } } else { } B38:; if ( calloc( 1, 1 ) ) { } else { __fprintf_chk( stderr, 1, ebp_192, ebp_192 ); } } else { } } } else { /* phantom */ size_t __s1_len; /* phantom */ size_t __s2_len; strcmp( "org.seul.geda.pcb.actions", interface_name ); if ( 1 ) { /* phantom */ size_t __s1_len; /* phantom */ size_t __s2_len; method_name[0] = ebp_140; strcmp( "ExecAction", ebp_140 ); if ( !1 ) { __fprintf_chk( stderr, 1, "pcb_dbus: Interface '%s' has no method '%s'\n", dbus_message_get_interface( &message ), ebp_184 ); } else { dbus_error_init( ebp_56 ); if ( dbus_message_get_args( &message, ebp_56, 115, ebp_32, 97, (long long)115, (long long)( ebp_40 ) ) ) { hid_actionv( (char*)calloc( 1, 1 ), ebp_40, ebp_36 ); dbus_free_string_array( 0 ); if ( dbus_message_new_method_return( &message ) ) { dbus_message_iter_init_append( dbus_message_new_method_return( &message ), ebp_112 ); if ( dbus_message_iter_append_basic( ebp_112, 117, ebp_28 ) ) { } else { } } } else { __fprintf_chk( stderr, 1, "Failed to read method arguments\n" ); if ( 0 ) { dbus_free_string_array( 0 ); } } } } else { /* phantom */ size_t __s1_len; /* phantom */ size_t __s2_len; strcmp( "org.freedesktop.DBus.Introspectable", interface_name ); if ( !1 ) { __fprintf_chk( stderr, 1, "pcb_dbus: Interface '%s' was not recognised\n", dbus_message_iter_append_basic( ebp_112, 117, ebp_28 ) ); } { /* phantom */ size_t __s1_len; /* phantom */ size_t __s2_len; method_name[0] = dbus_message_get_member( &message ); strcmp( "Introspect", dbus_message_get_member( &message ) ); if ( !1 ) { __fprintf_chk( stderr, 1, "pcb_dbus: Interface '%s' has no method '%s'\n", dbus_message_get_interface( &message ), ebp_184 ); } else { if ( dbus_message_new_method_return( &message ) ) { dbus_message_iter_init_append( dbus_message_new_method_return( &message ), ebp_112 ); if ( dbus_message_iter_append_basic( ebp_112, 115, pcb_dbus_introspect_xml ) ) { if ( dbus_connection_send( &pcb_dbus_conn, (DBusMessage*)dbus_message_get_interface( &message ), 0 ) ) { dbus_message_unref( &ebx ); return 0; } } else { } } } } } } if ( dbus_connection_send( ebp_200, ebp_200, ebp_196 ) ) { dbus_message_unref( &ebx ); return 0; } } else { } } else { } } break; } __fprintf_chk( stderr, 1, ebp_192, ebp_192 ); }