bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: chdir-safer: port to mingw


From: Jim Meyering
Subject: Re: chdir-safer: port to mingw
Date: Sat, 10 May 2008 15:28:20 +0200

Bruno Haible <address@hidden> wrote:
> Any comments on
> <http://lists.gnu.org/archive/html/bug-gnulib/2008-04/msg00253.html>?

I propose the following changes instead.
I want to avoid in-function #ifdefs, and since
you say mingw does not define ELOOP, using it as
a witness to lack of symlink support should be fine.

Plus, I noticed that it'd skip the check whenever O_NOFOLLOW
was nonzero, yet that is no guarantee of working O_NOFOLLOW support.


>From c85241132c918104916bd949f9646f8d807cd0e1 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sat, 10 May 2008 14:50:12 +0200
Subject: [PATCH] Avoid compile failure on systems without ELOOP (like mingw).

* lib/chdir-safer.c (ELOOP): Define if not already defined.
Reported by Bruno Haible.
---
 ChangeLog         |    6 ++++++
 lib/chdir-safer.c |    6 +++++-
 2 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a533eea..0116fbd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-05-10  Jim Meyering  <address@hidden>
+
+       Avoid compile failure on systems without ELOOP (like mingw).
+       * lib/chdir-safer.c (ELOOP): Define if not already defined.
+       Reported by Bruno Haible.
+
 2008-05-10  Bruno Haible  <address@hidden>

        * modules/unilbrk/ulc-width-linebreaks-tests: New file.
diff --git a/lib/chdir-safer.c b/lib/chdir-safer.c
index f7d657c..0df0b9d 100644
--- a/lib/chdir-safer.c
+++ b/lib/chdir-safer.c
@@ -1,6 +1,6 @@
 /* much like chdir(2), but safer

-   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2005-2006, 2008 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
@@ -29,6 +29,10 @@
 #include <sys/stat.h>
 #include "same-inode.h"

+#ifndef ELOOP
+# define ELOOP 0
+#endif
+
 /* Like chdir, but fail if DIR is a symbolic link to a directory (or
    similar funny business), or if DIR is not readable.  This avoids a
    minor race condition between when a directory is created or statted
--
1.5.5.1.179.gdc42


>From 506c4f11cbe4e17c240f4bcb334e69a7b014136c Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sat, 10 May 2008 15:15:11 +0200
Subject: [PATCH] Make chdir-safer.c slightly safer.

* lib/chdir-safer.c (chdir_no_follow): Test HAVE_WORKING_O_NOFOLLOW,
not O_NOFOLLOW, in case the latter is nonzero and open ignores it.
---
 ChangeLog         |    4 ++++
 lib/chdir-safer.c |    2 +-
 2 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0116fbd..d791951 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2008-05-10  Jim Meyering  <address@hidden>

+       Make chdir-safer.c slightly safer.
+       * lib/chdir-safer.c (chdir_no_follow): Test HAVE_WORKING_O_NOFOLLOW,
+       not O_NOFOLLOW, in case the latter is nonzero and open ignores it.
+
        Avoid compile failure on systems without ELOOP (like mingw).
        * lib/chdir-safer.c (ELOOP): Define if not already defined.
        Reported by Bruno Haible.
diff --git a/lib/chdir-safer.c b/lib/chdir-safer.c
index 0df0b9d..a5c9a4d 100644
--- a/lib/chdir-safer.c
+++ b/lib/chdir-safer.c
@@ -51,7 +51,7 @@ chdir_no_follow (char const *dir)
      they are the same file; if they are different files, set errno to
      ELOOP (the same value that open uses for symlinks with
      O_NOFOLLOW) so the caller can report a failure.  */
-  if (! O_NOFOLLOW)
+  if (! HAVE_WORKING_O_NOFOLLOW)
     {
       struct stat sb1;
       result = lstat (dir, &sb1);
--
1.5.5.1.179.gdc42


>From c4e27a9ea234efe6b4b888d67b31e24b722257fc Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sat, 10 May 2008 15:19:43 +0200
Subject: [PATCH] Make chdir-safer.c more efficient on a system with no symlinks.

* lib/chdir-safer.c (chdir_no_follow): Skip lstat and fstat calls
also if ELOOP is zero.  Suggested by Bruno Haible.
---
 ChangeLog         |    4 ++++
 lib/chdir-safer.c |    6 ++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d791951..6fcf932 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2008-05-10  Jim Meyering  <address@hidden>

+       Make chdir-safer.c more efficient on a system with no symlinks.
+       * lib/chdir-safer.c (chdir_no_follow): Skip lstat and fstat calls
+       also if ELOOP is zero.  Suggested by Bruno Haible.
+
        Make chdir-safer.c slightly safer.
        * lib/chdir-safer.c (chdir_no_follow): Test HAVE_WORKING_O_NOFOLLOW,
        not O_NOFOLLOW, in case the latter is nonzero and open ignores it.
diff --git a/lib/chdir-safer.c b/lib/chdir-safer.c
index a5c9a4d..03f3720 100644
--- a/lib/chdir-safer.c
+++ b/lib/chdir-safer.c
@@ -50,8 +50,10 @@ chdir_no_follow (char const *dir)
   /* If open follows symlinks, lstat DIR and fstat FD to ensure that
      they are the same file; if they are different files, set errno to
      ELOOP (the same value that open uses for symlinks with
-     O_NOFOLLOW) so the caller can report a failure.  */
-  if (! HAVE_WORKING_O_NOFOLLOW)
+     O_NOFOLLOW) so the caller can report a failure.
+     Skip this check if ELOOP == 0, which should be the case
+     on any system that lacks symlink support.  */
+  if (ELOOP && ! HAVE_WORKING_O_NOFOLLOW)
     {
       struct stat sb1;
       result = lstat (dir, &sb1);
--
1.5.5.1.179.gdc42




reply via email to

[Prev in Thread] Current Thread [Next in Thread]