xref: /original-bsd/lib/libc/gen/opendir.c (revision 5b10f61c)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  */
6 
7 #ifndef lint
8 static char sccsid[] = "@(#)opendir.c	5.1 (Berkeley) 05/30/85";
9 #endif not lint
10 
11 #include <sys/param.h>
12 #include <sys/dir.h>
13 
14 /*
15  * open a directory.
16  */
17 DIR *
18 opendir(name)
19 	char *name;
20 {
21 	register DIR *dirp;
22 	register int fd;
23 
24 	if ((fd = open(name, 0)) == -1)
25 		return NULL;
26 	if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
27 		close (fd);
28 		return NULL;
29 	}
30 	dirp->dd_fd = fd;
31 	dirp->dd_loc = 0;
32 	return dirp;
33 }
34