ignore-value: make ignore_value more generic; deprecate ignore_ptr
[pspp] / lib / save-cwd.c
index 7c2eb6d94f9148efd3f67de78dda69ad1a935c4f..be35192ce2ec6479c2d13bac0b8196beb5c240f7 100644 (file)
@@ -1,7 +1,7 @@
 /* save-cwd.c -- Save and restore current working directory.
 
-   Copyright (C) 1995, 1997, 1998, 2003, 2004, 2005, 2006, 2009 Free
-   Software Foundation, Inc.
+   Copyright (C) 1995, 1997-1998, 2003-2006, 2009-2011 Free Software
+   Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -31,6 +31,7 @@
 #include "chdir-long.h"
 #include "unistd--.h"
 #include "xgetcwd.h"
+#include "cloexec.h"
 
 #if GNULIB_FCNTL_SAFER
 # include "fcntl--.h"
@@ -75,7 +76,7 @@ save_cwd (struct saved_cwd *cwd)
 {
   cwd->name = NULL;
 
-  cwd->desc = open (".", O_RDONLY);
+  cwd->desc = open (".", O_SEARCH);
   if (!GNULIB_FCNTL_SAFER)
     cwd->desc = fd_safer (cwd->desc);
   if (cwd->desc < 0)
@@ -84,6 +85,7 @@ save_cwd (struct saved_cwd *cwd)
       return cwd->name ? 0 : -1;
     }
 
+  set_cloexec_flag (cwd->desc, true);
   return 0;
 }