bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Computing `cur_prefix_arg` argument to `set_relocation_prefix`


From: Reuben Thomas
Subject: Computing `cur_prefix_arg` argument to `set_relocation_prefix`
Date: Sat, 30 Jan 2021 18:25:45 +0000

I'm using the relocatable-prog module, and assuming that my program may be running on a platform that needs to call `set_relocation_prefix`.

Therefore, I need to compute the `cur_prefix_arg`.

I assume that the program is installed with the standard directory layout under some prefix. To compute the current prefix, I use two values: argv[0], to give me the path to the executable, and the relative path from bindir to prefix. Then I compute (leaving out error checking):

        // rel_prefix is `realpath --relative-to=@bindir@ @prefix@`
        char *rel_dir = mfile_name_concat(cur_bindir, rel_prefix, NULL);
        char *can_prefix = canonicalize_filename_mode(rel_dir, CAN_MISSING);

(I use `CAN_MISSING` as I want to leave checks of the file system until later, but of course some other mode could be used.)

Because `realpath` is not available on all platforms, I have copied `relpath.[ch]` from GNU coreutils into my project, with some slight patching so that I don't need to import coreutils's system.h.

I have two questions:

1. Have I overlooked a simpler method of computing `cur_prefix_arg`? Whether or not there is a simpler way, it would be good to have this functionality included in the relocatable-prog gnulib module.
2. Even if I could have computed `cur_prefix_arg` more simply, `relpath` seems like quite useful functionality; would it be good to have as a gnulib module?

--
https://rrt.sc3d.org

reply via email to

[Prev in Thread] Current Thread [Next in Thread]