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

LibC: Add readdir_r for re-entrant directory reading #648

Merged
merged 2 commits into from
Oct 12, 2019

Conversation

NattyNarwhal
Copy link
Contributor

This is popular and in POSIX. Some duplicated code between readdir is also unified into some static functions.

This is popular and in POSIX. Some duplicated code between readdir
is also unified into some static functions.
Copy link
Contributor

@awesomekling awesomekling left a comment

Choose a reason for hiding this comment

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

Please use clang-format to align the formatting with the rest of the codebase :)

static bool compare_sys_struct_dirent(sys_dirent* sys_ent, struct dirent* str_ent)
{
// XXX: Can't use min because "no matching function for call to 'min(int, size_t&)"
size_t namelen = (256 < sys_ent->namelen ? 256 : sys_ent->namelen);
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use min() if you just cast one of the inputs so they end up the same type.

{
if (dirp->buffer) {
return 0;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for else after a return statement. Let's avoid nesting :)

int new_errno = errno;
errno = old_errno;
return new_errno;
}
size_t size_to_allocate = max(st.st_size, 4096);
dirp->buffer = (char*)malloc(size_to_allocate);
ssize_t nread = syscall(SC_get_dir_entries, dirp->fd, dirp->buffer, size_to_allocate);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we haven't been handling errors from the get_dir_entries syscall eh.

@awesomekling awesomekling merged commit 6d150df into SerenityOS:master Oct 12, 2019
@awesomekling
Copy link
Contributor

Very nice! Thanks 🎉

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