News for hackers. Stuff that matters.
Re:Why bother with argv[0]? by toast0 on Tuesday September 03, 2024 @03:42PM (#41438410)
> There is almost always an "obviously right" path (the one used when opening the file).

The path used while opening a file is easy to get confused. If your cwd changed names or was deleted since you entered it, and you open an executable with a relative path, what is the "obviously right" path then?

Re:Why bother with argv[0]? by dwattttt on Tuesday September 03, 2024 @09:14PM (#41440930)
In context, there's still a right answer; the absolute path used to run the process should always be right, because the Windows locks the file (I'm sure with enough effort this can be made wrong, but I'm also sure that's not trivial).

Really, this discussion just shows the question is the problem; if you're asking "what path was used the launch the process", that's easy to keep track of & always be right. If you're asking "what is the path right now to the file that launched the process", maybe that has no answer.

Re:Why bother with argv[0]? by kelnos on Tuesday September 03, 2024 @10:14PM (#41441224)
I don't think that really follows. If the OS wants to track this, it should canonicalize the path to the executable on startup, and then stash it somewhere.

(And a program could do that itself, if it wants to.)