make-w32
[Top][All Lists]
Advanced

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

Re: Make CVS HEAD version build out of the box


From: Eli Zaretskii
Subject: Re: Make CVS HEAD version build out of the box
Date: Mon, 01 Oct 2007 23:00:58 +0200

> Date: Mon, 01 Oct 2007 22:34:30 +0200
> From: Eli Zaretskii <address@hidden>
> Cc: address@hidden
> 
> It's valid C, allright, but the code clearly wants not to modify the
> `name' argument to the function, and the function's prototype promises
> that it won't be modified.  So modifying it would be a breach of
> contract between the function and its callers.  If, for example, at
> some point, `find_directory' is passed a constant string literal as
> its argument, Make could crash at run time.
> 
> I will suggest an alternative patch in a while.

Here's my suggestion.  Could Yongwei Wu please test this and see if it
works?

2007-10-01  Eli Zaretskii  <address@hidden>

        * dir.c (find_directory) [WINDOWS32]: Don't modify the const
        string pointed by p.

--- dir.c~0     2007-07-21 19:06:58.251125000 +0300
+++ dir.c       2007-10-01 22:57:29.531250000 +0200
@@ -453,27 +453,24 @@ find_directory (const char *name)
       hash_insert_at (&directories, dir, dir_slot);
       /* The directory is not in the name hash table.
         Find its device and inode numbers, and look it up by them.  */
-
-#ifdef WINDOWS32
-      /* Remove any trailing '\'.  Windows32 stat fails even on valid
-         directories if they end in '\'. */
-      if (p[-1] == '\\')
-        p[-1] = '\0';
-#endif
-
 #ifdef VMS
       r = vmsstat_dir (name, &st);
+#elif defined(WINDOWS32)
+      {
+       char tem[MAXPATHLEN], *t;
+
+       /* Remove any trailing slashes.  Windows32 stat fails even on
+          valid directories if they end in a slash. */
+       memcpy (tem, name, p - name + 1);
+       t = tem + (p - name - 1);
+       if (*t == '/' || *t == '\\')
+         *t = '\0';
+       r = stat (tem, &st);
+      }
 #else
       EINTRLOOP (r, stat (name, &st));
 #endif
 
-#ifdef WINDOWS32
-      /* Put back the trailing '\'.  If we don't, we're permanently
-         truncating the value!  */
-      if (p[-1] == '\0')
-        p[-1] = '\\';
-#endif
-
       if (r < 0)
         {
        /* Couldn't stat the directory.  Mark this by




reply via email to

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