Skip to content

Add os.exePath #1029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 16, 2025
Merged

Add os.exePath #1029

merged 2 commits into from
Apr 16, 2025

Conversation

saghul
Copy link
Contributor

@saghul saghul commented Apr 15, 2025

It gets the current executable path. Implementation lifted from libuv. Currently implemented for the following platforms:

  • Linux
  • macOS
  • Windows

@saghul saghul requested a review from bnoordhuis April 15, 2025 11:23
@saghul saghul marked this pull request as ready for review April 15, 2025 11:23
size_t len = sizeof(buf);
if (js_exepath(buf, &len))
return JS_UNDEFINED;
return JS_NewStringLen(ctx, buf, len);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure you aware but paths that aren't proper UTF-8 are going to get mangled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When could that happen? On Windows? We utf8 encode the result there...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux file paths are really just byte strings and can have any encoding. macOS's HFS+ uses UTF-8 but in NFD1 so filenames don't round-trip the way you would expect them to.

1 Not even canonical NFD, I think, so even if you pass in a path that's fully decomposed to NFD, you're still not guaranteed to get back a byte-for-byte copy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's solve that when it arises ;-)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux file paths are really just byte strings and can have any encoding. macOS's HFS+ uses UTF-8 but in NFD1 so filenames don't round-trip the way you would expect them to.

1 Not even canonical NFD, I think, so even if you pass in a path that's fully decomposed to NFD, you're still not guaranteed to get back a byte-for-byte copy.

Yes filenames on macOS are converted to a form where accented letters are decomposed into the base character followed by the modifier codepoints. My understanding is it simplifies the case independent filename matching for file systems that support it. This becomes a problem when trying to match filenames returned by opendir/readdir with known filenames, and when trying to detect if 2 pathnames refer to the same file, which can fail for so many other reasons that nobody sane should try and rely on pathnames for this.

saghul added 2 commits April 16, 2025 08:53
It gets the current executable path. Implementation lifted from libuv.
Currently implemented for the following platforms:

- Linux
- macOS
- Windows
@saghul saghul merged commit 8ead934 into master Apr 16, 2025
126 checks passed
@saghul saghul deleted the exepath branch April 16, 2025 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants