options/posix: Fix readdir_r
@@ -77,9 +77,11 @@ int readdir_r(DIR *dir, struct dirent *entry, struct dirent **result) {
if(int e = mlibc::sys_read_entries(dir->__handle, dir->__ent_buffer, 2048, &dir->__ent_limit); e)
__ensure(!"mlibc::sys_read_entries() failed");
dir->__ent_next = 0;
- if(!dir->__ent_limit)
+ if(!dir->__ent_limit) {
+ *result = NULL;
return 0;
}
+ }
auto entp = reinterpret_cast<struct dirent *>(dir->__ent_buffer + dir->__ent_next);
memcpy(entry, entp, sizeof(struct dirent));
