qemu-trivial
[Top][All Lists]
Advanced

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

Re: [PATCH v3] util/oslib-posix: : qemu_init_exec_dir implementation for


From: Peter Maydell
Subject: Re: [PATCH v3] util/oslib-posix: : qemu_init_exec_dir implementation for Mac
Date: Tue, 16 Jun 2020 10:15:52 +0100

On Mon, 15 Jun 2020 at 20:14, David CARLIER <devnexen@gmail.com> wrote:
>
> With this basic program
>
> #include <mach-o/dyld.h>
> #include <stdio.h>
>
> int main(void)
> {
> char buf[4096];
> uint32_t bufsize = sizeof(buf);
> _NSGetExecutablePath(buf, &bufsize);
> printf("%s\n", buf);
> return 0;
> }
>
> I get
>
> Davids-MacBook-Pro-2:Contribs dcarlier$ ./a.out
> /Users/dcarlier/Contribs/./a.out

Hmm. I think we should run that through realpath() just
to get rid of the /./ in that. This is similar to how
Chromium uses it (though it uses a different API for
doing the absolutifying):
https://chromium.googlesource.com/chromium/src/base/+/master/base_paths_mac.mm#41

Thanks for the test program, I used it a minor variation of
it to confirm that this does do the right thing even when
argv[0] has been passed as a different string:

$ (exec -a foo /tmp/zz9)
_NSGetExecutablePath: /tmp/zz9
argv[0]: foo

So _NSGetExecutablePath() is definitely the thing to use here.

> The cast was to avoid possible warning with pedantic compile flags if used.

We don't compile with -pedantic, so you don't need to guard
against using it.

thanks
-- PMM



reply via email to

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