Fix Savannah bug # 13478. If -L is given, take the latest mtime for a
authorPaul Smith <psmith@gnu.org>
Sat, 25 Jun 2005 23:00:17 +0000 (23:00 +0000)
committerPaul Smith <psmith@gnu.org>
Sat, 25 Jun 2005 23:00:17 +0000 (23:00 +0000)
symlink even if it is "dangling" (it doesn't resolve to a real file).

ChangeLog
glob/ChangeLog
glob/fnmatch.h
glob/glob.c
glob/glob.h
make.h
read.c
remake.c
tests/ChangeLog
tests/scripts/options/symlinks

index c764580..d462182 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2005-06-25  Paul D. Smith  <psmith@gnu.org>
 
+       * make.h [WINDOWS32]: #include <direct.h>.
+       Fixes Savannah bug #13478.
+
+       * remake.c (name_mtime): If the stat() of a file fails and the -L
+       option was given and the file is a symlink, take the best mtime of
+       the symlink we can get as the mtime of the file and don't fail.
+       Fixes Savannah bug #13280.
+
        Fix Savannah bug #1454.
 
        * read.c (find_char_unquote): Accept a new argument IGNOREVARS.
index e4879b5..18c3172 100644 (file)
@@ -1,3 +1,8 @@
+2005-06-25  Paul D. Smith  <psmith@gnu.org>
+
+       * fnmatch.h, glob.h [WINDOWS32]: Fix ifdefs in headers.
+       Fixes Savannah bug #13477.
+
 2005-03-11  Paul D. Smith  <psmith@gnu.org>
 
        * glob.c (glob_in_dir): Change FNM_CASEFOLD to be enabled if
index cc3ec37..54cbf59 100644 (file)
@@ -24,7 +24,7 @@ extern "C" {
 #endif
 
 #if defined __cplusplus || (defined __STDC__ && __STDC__) || defined WINDOWS32
-# if !defined __GLIBC__ || !defined __P
+# if !defined __GLIBC__
 #  undef       __P
 #  define __P(protos)  protos
 # endif
@@ -37,7 +37,7 @@ extern "C" {
 #endif /* C++ or ANSI C.  */
 
 #ifndef const
-# if (defined __STDC__ && __STDC__) || defined __cplusplus
+# if (defined __STDC__ && __STDC__) || defined __cplusplus || defined WINDOWS32
 #  define __const      const
 # else
 #  define __const
index 80d667c..20c48f7 100644 (file)
@@ -299,11 +299,8 @@ static int glob_in_dir __P ((const char *pattern, const char *directory,
 static int prefix_array __P ((const char *prefix, char **array, size_t n));
 static int collated_compare __P ((const __ptr_t, const __ptr_t));
 
-#ifdef VMS
-/* these compilers like prototypes */
 #if !defined _LIBC || !defined NO_GLOB_PATTERN_P
-int __glob_pattern_p (const char *pattern, int quote);
-#endif
+int __glob_pattern_p __P ((const char *pattern, int quote));
 #endif
 
 /* Find the end of the sub-pattern in a brace expression.  We define
index ca523f7..b307c25 100644 (file)
@@ -24,7 +24,7 @@ extern "C" {
 
 #undef __ptr_t
 #if defined __cplusplus || (defined __STDC__ && __STDC__) || defined WINDOWS32
-# if !defined __GLIBC__ || !defined __P
+# if !defined __GLIBC__
 #  undef __P
 #  undef __PMT
 #  define __P(protos)  protos
diff --git a/make.h b/make.h
index 20ee569..55682d8 100644 (file)
--- a/make.h
+++ b/make.h
@@ -358,6 +358,11 @@ extern int strcmpi (const char *,const char *);
 # define PATH_SEPARATOR_CHAR ':'
 #endif
 
+/* This is needed for getcwd() and chdir().  */
+#if defined(_MSC_VER) || defined(__BORLANDC__)
+# include <direct.h>
+#endif
+
 #ifdef WINDOWS32
 # include <fcntl.h>
 # include <malloc.h>
@@ -481,7 +486,7 @@ extern long int lseek ();
 #ifdef  HAVE_GETCWD
 # if !defined(VMS) && !defined(__DECC)
 extern char *getcwd ();
-#endif
+# endif
 #else
 extern char *getwd ();
 # define getcwd(buf, len)       getwd (buf)
diff --git a/read.c b/read.c
index 2e97995..024567a 100644 (file)
--- a/read.c
+++ b/read.c
@@ -2187,9 +2187,6 @@ find_char_unquote (char *string, int stop1, int stop2, int blank,
 {
   unsigned int string_len = 0;
   register char *p = string;
-  int pcount = 0;
-  char openparen;
-  char closeparen;
 
   if (ignorevars)
     ignorevars = '$';
index 5f82f03..750a80c 100644 (file)
--- a/remake.c
+++ b/remake.c
@@ -1328,13 +1328,18 @@ name_mtime (char *name)
   int e;
 
   EINTRLOOP (e, stat (name, &st));
-  if (e != 0)
+  if (e == 0)
+    mtime = FILE_TIMESTAMP_STAT_MODTIME (name, st);
+  else if (errno == ENOENT || errno == ENOTDIR)
+    mtime = NONEXISTENT_MTIME;
+  else
     {
-      if (errno != ENOENT && errno != ENOTDIR)
-        perror_with_name ("stat: ", name);
+      perror_with_name ("stat: ", name);
       return NONEXISTENT_MTIME;
     }
-  mtime = FILE_TIMESTAMP_STAT_MODTIME (name, st);
+
+  /* If we get here we either found it, or it doesn't exist.
+     If it doesn't exist see if we can use a symlink mtime instead.  */
 
 #ifdef MAKE_SYMLINKS
 #ifndef S_ISLNK
@@ -1361,8 +1366,9 @@ name_mtime (char *name)
           EINTRLOOP (e, lstat (lpath, &st));
           if (e)
             {
-              /* Eh?  Just take what we have.  */
-              perror_with_name ("lstat: ", lpath);
+              /* Just take what we have so far.  */
+              if (errno != ENOENT && errno != ENOTDIR)
+                perror_with_name ("lstat: ", lpath);
               break;
             }
 
index fa6420d..143bc2f 100644 (file)
@@ -1,5 +1,8 @@
 2005-06-25  Paul D. Smith  <psmith@gnu.org>
 
+       * scripts/options/symlinks: Test symlinks to non-existent files.
+       Tests fix for Savannah bug #13280.
+
        * scripts/misc/general3: Test semicolons in variable references.
        Tests fix for Savannah bug #1454.
 
index 4dcc67a..d63e222 100644 (file)
@@ -42,6 +42,19 @@ if (eval { symlink("",""); 1 }) {
   run_make_test(undef, '-L', "make targ from sym");
 
   rmfiles('targ', 'dep', 'sym', 'dep1');
+
+  # Check handling when symlinks point to non-existent files.  Without -L we
+  # should get an error: with -L we should use the timestamp of the symlink.
+
+  symlink("../$dirname/dep", 'sym');
+  run_make_test('targ: sym ; @echo make $@ from $<', '',
+                "#MAKE#: *** No rule to make target `sym', needed by `targ'.  Stop.", 512);
+
+  run_make_test('targ: sym ; @echo make $@ from $<', '-L',
+                'make targ from sym');
+
+
+  rmfiles('targ', 'sym');
 }
 
 1;