BSD 4_3 release
[unix-history] / usr / src / lib / libc / gen / opendir.c
index eeb96f1..6996007 100644 (file)
@@ -1,9 +1,15 @@
-/* Copyright (c) 1982 Regents of the University of California */
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
 
 
-static char sccsid[] = "@(#)opendir.c 1.1 %G%";
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)opendir.c  5.2 (Berkeley) 3/9/86";
+#endif LIBC_SCCS and not lint
 
 
-#include <sys/types.h>
-#include <ndir.h>
+#include <sys/param.h>
+#include <sys/dir.h>
 
 /*
  * open a directory.
 
 /*
  * open a directory.
@@ -12,14 +18,16 @@ DIR *
 opendir(name)
        char *name;
 {
 opendir(name)
        char *name;
 {
-       DIR *dirp;
+       register DIR *dirp;
+       register int fd;
 
 
-       dirp = (DIR *)malloc(sizeof(DIR));
-       dirp->dd_fd = open(name, 0);
-       if (dirp->dd_fd == -1) {
-               free(dirp);
+       if ((fd = open(name, 0)) == -1)
+               return NULL;
+       if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
+               close (fd);
                return NULL;
        }
                return NULL;
        }
+       dirp->dd_fd = fd;
        dirp->dd_loc = 0;
        return dirp;
 }
        dirp->dd_loc = 0;
        return dirp;
 }