1 /* Copyright (c) 1982 Regents of the University of California */ 2 3 static char sccsid[] = "@(#)opendir.c 4.3 08/04/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 register int fd; 18 struct stat sbuf; 19 20 if ((fd = open(name, 0)) == -1) 21 return NULL; 22 fstat(fd, &sbuf); 23 if (((sbuf.st_mode & S_IFDIR) == 0) || 24 ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL)) { 25 close (fd); 26 return NULL; 27 } 28 dirp->dd_fd = fd; 29 dirp->dd_loc = 0; 30 return dirp; 31 } 32