diff --git a/libc/dirent/dnewdir.cpp b/libc/dirent/dnewdir.cpp index b2f0148b..c7946ce0 100644 --- a/libc/dirent/dnewdir.cpp +++ b/libc/dirent/dnewdir.cpp @@ -39,6 +39,7 @@ extern "C" DIR* dnewdir(void) return NULL; dir->flags = 0; dir->free_func = dfreedir; + dir->closedir_indirect = closedir; dregister(dir); return dir; } diff --git a/libc/include/DIR.h b/libc/include/DIR.h index 065afa85..26c83bb5 100644 --- a/libc/include/DIR.h +++ b/libc/include/DIR.h @@ -59,6 +59,7 @@ struct DIR int (*close_func)(void* user); void (*free_func)(DIR* dir); /* Application writers shouldn't use anything beyond this point. */ + int (*closedir_indirect)(DIR*); DIR* prev; DIR* next; struct dirent* entry; diff --git a/libc/stdlib/exit.cpp b/libc/stdlib/exit.cpp index 161af10f..8ccda665 100644 --- a/libc/stdlib/exit.cpp +++ b/libc/stdlib/exit.cpp @@ -62,7 +62,7 @@ extern "C" void exit(int status) pthread_mutex_lock(&__first_file_lock); while ( __first_dir ) - closedir(__first_dir); + __first_dir->closedir_indirect(__first_dir); while ( __first_file ) fclose(__first_file);