1 /* Copyright (c) 1982 Regents of the University of California */ 2 3 static char sccsid[] = "@(#)opendir.c 4.2 03/10/82"; 4 5 #include <sys/types.h> 6 #include <sys/stat.h> 7 #include <ndir.h> 8 9 /* 10 * open a directory. 11 */ 12 DIR * 13 opendir(name) 14 char *name; 15 { 16 register DIR *dirp; 17 struct stat sbuf; 18 19 dirp = (DIR *)malloc(sizeof(DIR)); 20 dirp->dd_fd = open(name, 0); 21 if (dirp->dd_fd == -1) { 22 free(dirp); 23 return NULL; 24 } 25 fstat(dirp->dd_fd, &sbuf); 26 if ((sbuf.st_mode & S_IFDIR) == 0) { 27 free(dirp); 28 return NULL; 29 } 30 dirp->dd_loc = 0; 31 return dirp; 32 } 33