xref: /csrg-svn/lib/libc/gen/opendir.c (revision 36545)
121350Sdist /*
221350Sdist  * Copyright (c) 1983 Regents of the University of California.
334790Sbostic  * All rights reserved.
434790Sbostic  *
534790Sbostic  * Redistribution and use in source and binary forms are permitted
634790Sbostic  * provided that the above copyright notice and this paragraph are
734790Sbostic  * duplicated in all such forms and that any documentation,
834790Sbostic  * advertising materials, and other materials related to such
934790Sbostic  * distribution and use acknowledge that the software was developed
1034790Sbostic  * by the University of California, Berkeley.  The name of the
1134790Sbostic  * University may not be used to endorse or promote products derived
1234790Sbostic  * from this software without specific prior written permission.
1334790Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1434790Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1534790Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1621350Sdist  */
1721350Sdist 
1826573Sdonn #if defined(LIBC_SCCS) && !defined(lint)
19*36545Smckusick static char sccsid[] = "@(#)opendir.c	5.4 (Berkeley) 01/11/89";
2034790Sbostic #endif /* LIBC_SCCS and not lint */
215750Smckusick 
229142Smckusick #include <sys/param.h>
23*36545Smckusick #include <dirent.h>
245750Smckusick 
255750Smckusick /*
265750Smckusick  * open a directory.
275750Smckusick  */
285750Smckusick DIR *
295750Smckusick opendir(name)
305750Smckusick 	char *name;
315750Smckusick {
326097Smckusic 	register DIR *dirp;
337659Smckusick 	register int fd;
345750Smckusick 
357659Smckusick 	if ((fd = open(name, 0)) == -1)
365750Smckusick 		return NULL;
379142Smckusick 	if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
387659Smckusick 		close (fd);
396097Smckusic 		return NULL;
406097Smckusic 	}
417659Smckusick 	dirp->dd_fd = fd;
425750Smckusick 	dirp->dd_loc = 0;
435750Smckusick 	return dirp;
445750Smckusick }
45