15750Smckusick /* Copyright (c) 1982 Regents of the University of California */ 25750Smckusick 3*7659Smckusick static char sccsid[] = "@(#)opendir.c 4.3 08/04/82"; 45750Smckusick 55750Smckusick #include <sys/types.h> 66097Smckusic #include <sys/stat.h> 75750Smckusick #include <ndir.h> 85750Smckusick 95750Smckusick /* 105750Smckusick * open a directory. 115750Smckusick */ 125750Smckusick DIR * 135750Smckusick opendir(name) 145750Smckusick char *name; 155750Smckusick { 166097Smckusic register DIR *dirp; 17*7659Smckusick register int fd; 186097Smckusic struct stat sbuf; 195750Smckusick 20*7659Smckusick if ((fd = open(name, 0)) == -1) 215750Smckusick return NULL; 22*7659Smckusick fstat(fd, &sbuf); 23*7659Smckusick if (((sbuf.st_mode & S_IFDIR) == 0) || 24*7659Smckusick ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL)) { 25*7659Smckusick close (fd); 266097Smckusic return NULL; 276097Smckusic } 28*7659Smckusick dirp->dd_fd = fd; 295750Smckusick dirp->dd_loc = 0; 305750Smckusick return dirp; 315750Smckusick } 32