1 /* 2 * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org> 3 * 4 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. 5 */ 6 7 #include <dirent.h> 8 #include <errno.h> 9 #include <stdlib.h> 10 #include <unistd.h> 11 #include "dirstream.h" 12 #include <not-cancel.h> 13 14 closedir(DIR * dir)15int closedir(DIR * dir) 16 { 17 int fd; 18 19 if (!dir) { 20 __set_errno(EBADF); 21 return -1; 22 } 23 24 /* We need to check dd_fd. */ 25 if (dir->dd_fd == -1) { 26 __set_errno(EBADF); 27 return -1; 28 } 29 __UCLIBC_MUTEX_LOCK(dir->dd_lock); 30 fd = dir->dd_fd; 31 dir->dd_fd = -1; 32 __UCLIBC_MUTEX_UNLOCK(dir->dd_lock); 33 free(dir->dd_buf); 34 free(dir); 35 return close_not_cancel(fd); 36 } 37 libc_hidden_def(closedir) 38