From 2cfd87717af00101b0095d9fcc4fada0b79bce0b Mon Sep 17 00:00:00 2001 From: ru Date: Fri, 2 Mar 2012 14:05:50 +0000 Subject: Removed excessive _seekdir() call in closedir(). This saves one lseek() syscall. Before r5958, seekdir() was called for its side effect of freeing memory allocated by opendir() for rewinddir(), but that revision added _reclaim_telldir() that frees all memory allocated by telldir() calls, making this call redundant. This introduces a slight change. If an application duplicated the descriptor obtained through dirfd(), it can no longer rely on file position to be reset to the start of file after a call to closedir(). It's believed to be safe because neither POSIX, nor any other OS I've tested (NetBSD, Linux, OS X) rewind the file offset pointer on closedir(). Reported by: Igor Sysoev --- lib/libc/gen/closedir.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/gen/closedir.c b/lib/libc/gen/closedir.c index 44e2bdf..5db351b 100644 --- a/lib/libc/gen/closedir.c +++ b/lib/libc/gen/closedir.c @@ -48,14 +48,12 @@ __FBSDID("$FreeBSD$"); * close a directory. */ int -closedir(dirp) - DIR *dirp; +closedir(DIR *dirp) { int fd; if (__isthreaded) _pthread_mutex_lock(&dirp->dd_lock); - _seekdir(dirp, dirp->dd_rewind); /* free seekdir storage */ fd = dirp->dd_fd; dirp->dd_fd = -1; dirp->dd_loc = 0; -- cgit v1.1