]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - nss/nss_db/db-open.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / nss / nss_db / db-open.c
index 36ce494d0267935651302bdd5176187c4f45eaf4..a60bed97de4f36a087a9c41c197353d75bc61247 100644 (file)
@@ -1,5 +1,5 @@
 /* Common database routines for nss_db.
-   Copyright (C) 2000, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2000-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
 
 #include <errno.h>
 #include <fcntl.h>
 #include <dlfcn.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <sys/mman.h>
 #include <not-cancel.h>
 
-#include <kernel-features.h>
 #include "nss_db.h"
 
 /* Open the database stored in FILE.  If succesful, store either a
@@ -37,11 +36,7 @@ internal_setent (const char *file, struct nss_db_map *mapping)
 {
   enum nss_status status = NSS_STATUS_UNAVAIL;
 
-  int mode = O_RDONLY | O_LARGEFILE;
-#ifdef O_CLOEXEC
-  mode |= O_CLOEXEC;
-#endif
-  int fd = open_not_cancel_2 (file, mode);
+  int fd = __open_nocancel (file, O_RDONLY | O_LARGEFILE | O_CLOEXEC);
   if (fd != -1)
     {
       struct nss_db_header header;
@@ -57,7 +52,7 @@ internal_setent (const char *file, struct nss_db_map *mapping)
            status = NSS_STATUS_TRYAGAIN;
        }
 
-      close_not_cancel_no_status (fd);
+      __close_nocancel_nostatus (fd);
     }
 
   return status;
@@ -68,5 +63,9 @@ internal_setent (const char *file, struct nss_db_map *mapping)
 void
 internal_endent (struct nss_db_map *mapping)
 {
-  munmap (mapping->header, mapping->len);
+  if (mapping->header != NULL)
+    {
+      munmap (mapping->header, mapping->len);
+      mapping->header = NULL;
+    }
 }