Hi, Quoting Eli Schwartz (2020-03-22 02:26:48) > On 3/21/20 5:12 AM, Johannes Schauer wrote: > > is there existing code that works with busybox and replaces "readlink -m" > > or "realpath -m" from coreutils? > > > > Resources I found online either show solution for "readlink -f" only, when > > neither readlink nor realpath exists, when Perl is available or when bash is > > available. > I can't think of one, but you could implement it in pure shell by checking > the return code of readlink without options (it will fail if the file is not > a symlink), and walk the path to find the first directory that exists in > order to support -m. This would be pretty compatible with any readlink > implementation, including ones without -f.
I found this one which implements such a shell script in bash: https://github.com/bashup/realpaths I ported that one to POSIX shell: https://gitlab.mister-muffin.de/josch/realpath The result provides "readlink -m" functionality even with busybox only. This indeed needed much more code than I thought it would. > Probably the nicest option would be to submit a patch that implements > readlink -m for busybox, so that it just works. It's a nice, useful option to > have, so why not add it? I am surprised that this is an option. I thought busybox was meant to be very minimal. Looking at the GNU implementation of the code behind "readlink -m" there is quite a lot of code: http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=lib/canonicalize.c Unfortunately, I also need this feature with older versions of busybox and I also wouldn't trust myself with writing that much C without severe bugs. XD Thanks! cheers, josch
signature.asc
Description: signature
_______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
