Skip to content

Conversation

dgryski
Copy link
Member

@dgryski dgryski commented May 1, 2025

No description provided.

@dgryski
Copy link
Member Author

dgryski commented May 1, 2025

Not sure I like this solution; it pulls in a bunch of code from syscall to get the cwd at process init.

Copy link
Member

@aykevl aykevl left a comment

Choose a reason for hiding this comment

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

This seems like a reasonable solution, even if not perfect (I can't think of a better way right now). Some nits below.


var executablePath string

func platform_argv(argc int32, argv *unsafe.Pointer) {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I'm not sure I like this name. What about storeExecutablePath or something like that?

Comment on lines +295 to +296
const pathMax = 1024
var buf [4 * pathMax]byte
Copy link
Member

Choose a reason for hiding this comment

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

Why use 1024 and then use 4 times that size in the actual buffer? (Also, it would help to give a pointer to why that is the right value, like a link to a man page or something).

if n < 1 {
return ""
}
return string(buf[:n])
Copy link
Member

Choose a reason for hiding this comment

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

You could consider using unsafe.String here to avoid an allocation. It should be safe, since buf is never modified afterwards. (The potential downside is that executablePath will then always be 4kB in size - not sure whether that's a good tradeoff).

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.

2 participants