Skip to content
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

runtime: Don't hardcode PATH_MAX #1491

Merged
merged 2 commits into from
Oct 18, 2023
Merged

Conversation

Nopey
Copy link
Contributor

@Nopey Nopey commented Oct 9, 2023

Windows' _fullpath and _getcwd will handle allocation if we pass NULL as the buffer, but please note that this will not remove path length limitations.

Unfortunately, posix_fs.jakt is not so straightforward.
realpath: POSIX.1-2008 lets us pass NULL for the second argument, resolved_path; libc will allocate for us.
getcwd: Linux lets us pass NULL, but POSIX defines this as undefined behavior. Can and should we special-case any os/libc whose getcwd will do the allocation for us?

@alimpfard
Copy link
Member

We could add the means to select different modules based on libc, but iirc getcwd() will return with an error if the path doesn't fit in the buffer, so we should be able to keep allocating larger buffers until it returns non-NULL?

@Nopey Nopey changed the title runtime: Don't hardcode PATH_MAX on Windows runtime: Don't hardcode PATH_MAX Oct 13, 2023
@Nopey
Copy link
Contributor Author

Nopey commented Oct 13, 2023

Paths over 4096 can now be returned by jakt's current_directory and real_path: We use the POSIX.1-2008 realpath behavior, and getcwd has a loop to grow the buffer size until the buffer is sufficient.

This does not mean Jakt is long path aware on POSIX, as that would require breaking paths up into relative paths that fit within PATH_MAX (which could be as low as _POSIX_PATH_MAX, 256) and using openat chaining (to implement filesystem apis that may fail on long paths such as as mkdir)

Copy link
Member

@alimpfard alimpfard left a comment

Choose a reason for hiding this comment

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

Apparently I forgot to press "comment" the last time I came to review 😅

runtime/jaktlib/platform/posix_errno.jakt Show resolved Hide resolved
There's still one usage of magic number 4096 in fn current_directory,
but only as an initial guess at the path length.
@alimpfard alimpfard merged commit 239e035 into SerenityOS:main Oct 18, 2023
6 checks passed
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