KO Myung-Hun wrote: > > @@ -78,11 +82,17 @@ _gl_unregister_dirp_fd (int fd) > > int > > dirfd (DIR *dir_p) > > { > > +#if GNULIB_defined_DIR > > + int fd = dir_p->fd_to_close; > > dirfd() allows to take an invalid `dir_p' ?
No; this must be a misunderstanding. dirfd is specified at https://pubs.opengroup.org/onlinepubs/9699919799/functions/dirfd.html Which says that if "The dirp argument does not refer to a valid directory stream" the function may fail with error EINVAL. It may alternatively simply crash ("the behavior is undefined"). In this code, we have two cases, depending on platforms: - If GNULIB_defined_DIR, it means that gnulib has defined or overridden the 'DIR' type, to include an 'fd_to_close' field'. Currently that's only on native Windows, but I'm suggesting that the same code could also be used on kLIBC. - Otherwise, gnulib uses either the system-provided dirfd function or macro, or does a lookup in dir_p->d_fd or dir_p->dd_fd. Bruno