2010-03-05  Juan Manuel Guerrero <juan.guerrero@gmx.de>

	* src/cmp.c (main): Use CANONICALIZE_PATH to canonicalize the passed
	file names.

	* src/diff.c (main): Use CANONICALIZE_PATH to canonicalize the passed
	file names.

	* src/diff3.c (main): Use CANONICALIZE_PATH to canonicalize the passed
	file names.

	* src/sdiff.c (main): Use CANONICALIZE_PATH to canonicalize the passed
	file names.

	* src/system.h [DJGPP]: New macro CANONICALIZE_PATH defined.  For all
	other systems this is a no-ops.


2010-02-14  Juan Manuel Guerrero <juan.guerrero@gmx.de>

	* lib/btowc.c [__DJGPP__]: Include <stdlib.h> for mbtowc declaration.

	* lib/mbrtowc.c [__DJGPP__]: Define EILSEQ if not defined.

	* lib/mbsrtowcs.c [__DJGPP__]: Define EILSEQ if not defined.

	* lib/progname.c [MSDOS]: Define new macro GET_LAST_SLASH to find
	the last directory separator character.  On DOS-Like systems these
	are slash, backslash or colon.  For POSIX this is simple a slash.

	* lib/tempname.c: New macro HAVE_DIFFERENT_TMPDIR.  Value depends on
	if the OS is posix or not.
	(direxists): Use ISSLASH to check for the OS dependent directory
	separator character.  Use HAVE_DIFFERENT_TMPDIR to check for TMP and
	TEMP too, if none of them are defined or do not point to an existing
	directory default to the current directory.

	* lib/wcrtomb.c [__DJGPP__]: Define EILSEQ if not defined.

	* src/cmp.c (main): Use STRIP_FULL_PATH_AND_EXTENSION to strip path
	and extension from argv[0].

	* src/diff.c (main): Use STRIP_FULL_PATH_AND_EXTENSION to strip path
	and extension from argv[0].

	* src/diff3.c (main): Use STRIP_FULL_PATH_AND_EXTENSION to strip path
	and extension from argv[0].

	* src/system.h [DJGPP]: New macros HAVE_LFN_SUPPORT, IS_SLASH and
	STRIP_FULL_PATH_AND_EXTENSION defined.  For all other systems these
	are no-ops.

	* src/sdiff.c (main): Bug fix.  Pass the the pointer to the quoted
	string to shell_quote_copy as required.
	Use STRIP_FULL_PATH_AND_EXTENSION to strip path and extension from
	argv[0].
	(temporary_file): Use HAVE_LFN_SUPPORT to determinate at run time
	the temp file pattern to be used.

	* src/util.c (begin_output): Bug fix.  Pass the the pointer to the
	quoted string to shell_quote_copy as required.





diff -aprNU5 diffutils-2.9.orig/lib/btowc.c diffutils-2.9/lib/btowc.c
--- diffutils-2.9.orig/lib/btowc.c	2010-01-08 10:35:20 +0000
+++ diffutils-2.9/lib/btowc.c	2010-03-08 23:41:08 +0000
@@ -20,10 +20,16 @@
 /* Specification.  */
 #include <wchar.h>
 
 #include <stdio.h>
 
+#ifdef __DJGPP__
+/*  Stock DJGPP  2.04 declares mbtowc in stdlib.h
+    Fixed in CVS repository.  */
+# include <stdlib.h>
+#endif
+
 wint_t
 btowc (int c)
 {
   if (c != EOF)
     {
diff -aprNU5 diffutils-2.9.orig/lib/mbrtowc.c diffutils-2.9/lib/mbrtowc.c
--- diffutils-2.9.orig/lib/mbrtowc.c	2010-01-08 10:35:20 +0000
+++ diffutils-2.9/lib/mbrtowc.c	2010-03-08 23:41:08 +0000
@@ -15,10 +15,16 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 
+#if defined(__DJGPP__) && !defined(EILSEQ)
+# if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || !defined(__STRICT_ANSI__)
+#   define EILSEQ   41
+# endif /* (__STDC_VERSION__ >= 199901L) || !__STRICT_ANSI__ */
+#endif
+
 /* Specification.  */
 #include <wchar.h>
 
 #if GNULIB_defined_mbstate_t
 /* Implement mbrtowc() on top of mbtowc().  */
diff -aprNU5 diffutils-2.9.orig/lib/mbsrtowcs.c diffutils-2.9/lib/mbsrtowcs.c
--- diffutils-2.9.orig/lib/mbsrtowcs.c	2010-01-08 10:35:20 +0000
+++ diffutils-2.9/lib/mbsrtowcs.c	2010-03-08 23:41:08 +0000
@@ -15,10 +15,16 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 
+#if defined(__DJGPP__) && !defined(EILSEQ)
+# if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || !defined(__STRICT_ANSI__)
+#   define EILSEQ   41
+# endif /* (__STDC_VERSION__ >= 199901L) || !__STRICT_ANSI__ */
+#endif
+
 /* Specification.  */
 #include <wchar.h>
 
 #include <errno.h>
 #include <limits.h>
diff -aprNU5 diffutils-2.9.orig/lib/progname.c diffutils-2.9/lib/progname.c
--- diffutils-2.9.orig/lib/progname.c	2010-01-08 10:35:20 +0000
+++ diffutils-2.9/lib/progname.c	2010-03-08 23:41:10 +0000
@@ -25,10 +25,33 @@
 #include <errno.h> /* get program_invocation_name declaration */
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+/* MS-DOS and similar non-Posix systems have some peculiarities:
+    - they use both `/' and `\\' as directory separator in file names;
+    - they can have a drive letter X: prepended to a file name;
+   These are all parameterized here.  */
+
+#ifdef MSDOS
+# include <libc/unconst.h>
+# undef  IS_SLASH
+# define IS_SLASH(c)  ((c) == '/' || (c) == '\\' || (c) == ':')
+# define GET_LAST_SLASH(filename)                  \
+  ({                                               \
+      char *_slash = unconst((filename), char *);  \
+      while (*_slash++)                            \
+        ;                                          \
+      while ((--_slash - (filename)))              \
+        if (IS_SLASH(*_slash))                     \
+          break;                                   \
+      _slash;                                      \
+  })
+#else
+# define GET_LAST_SLASH(filename)  (strrchr((filename), '/'))
+#endif
+
 
 /* String containing name the program is called with.
    To be initialized by main().  */
 const char *program_name = NULL;
 
@@ -54,13 +77,21 @@ set_program_name (const char *argv0)
       fputs ("A NULL argv[0] was passed through an exec system call.\n",
              stderr);
       abort ();
     }
 
-  slash = strrchr (argv0, '/');
+  slash = GET_LAST_SLASH (argv0);
   base = (slash != NULL ? slash + 1 : argv0);
-  if (base - argv0 >= 7 && strncmp (base - 7, "/.libs/", 7) == 0)
+  if (base - argv0 >= 7 && (strncmp (base - 7, "/.libs/", 7) == 0
+#ifdef MSDOS
+     || strncmp (base - 7, "\\.libs/", 7) == 0
+     || strncmp (base - 7, "\\.libs\\", 7) == 0
+     || strncmp (base - 7, "/_libs/", 7) == 0
+     || strncmp (base - 7, "\\_libs/", 7) == 0
+     || strncmp (base - 7, "\\_libs\\", 7) == 0
+#endif
+     ))
     {
       argv0 = base;
       if (strncmp (base, "lt-", 3) == 0)
         {
           argv0 = base + 3;
diff -aprNU5 diffutils-2.9.orig/lib/tempname.c diffutils-2.9/lib/tempname.c
--- diffutils-2.9.orig/lib/tempname.c	2010-01-08 10:35:20 +0000
+++ diffutils-2.9/lib/tempname.c	2010-03-08 23:41:10 +0000
@@ -28,10 +28,16 @@
 #include <errno.h>
 #ifndef __set_errno
 # define __set_errno(Val) errno = (Val)
 #endif
 
+#ifdef MSDOS
+# define HAVE_DIFFERENT_TMPDIR  1
+#else
+# define HAVE_DIFFERENT_TMPDIR  0
+#endif
+
 #include <stdio.h>
 #ifndef P_tmpdir
 # define P_tmpdir "/tmp"
 #endif
 #ifndef TMP_MAX
@@ -141,30 +147,41 @@ __path_search (char *tmpl, size_t tmpl_l
   if (try_tmpdir)
     {
       d = __secure_getenv ("TMPDIR");
       if (d != NULL && direxists (d))
         dir = d;
+#if HAVE_ALTERNATE_TMPDIR
+      else if ((d = __secure_getenv ("TMP")) && direxists (d))
+	dir = d;
+      else if ((d = __secure_getenv ("TEMP")) && direxists (d))
+	dir = d;
+#endif
       else if (dir != NULL && direxists (dir))
         /* nothing */ ;
       else
         dir = NULL;
     }
   if (dir == NULL)
     {
       if (direxists (P_tmpdir))
         dir = P_tmpdir;
+#if !HAVE_ALTERNATE_TMPDIR
       else if (strcmp (P_tmpdir, "/tmp") != 0 && direxists ("/tmp"))
         dir = "/tmp";
+#else
+      else if (strcmp (P_tmpdir, ".") != 0 && direxists ("."))
+	dir = "./";
+#endif
       else
         {
           __set_errno (ENOENT);
           return -1;
         }
     }
 
   dlen = strlen (dir);
-  while (dlen > 1 && dir[dlen - 1] == '/')
+  while (dlen > 1 && ISSLASH (dir[dlen - 1] == '/'))
     dlen--;                     /* remove trailing slashes */
 
   /* check we have room for "${dir}/${pfx}XXXXXX\0" */
   if (tmpl_len < dlen + 1 + plen + 6 + 1)
     {
diff -aprNU5 diffutils-2.9.orig/lib/wcrtomb.c diffutils-2.9/lib/wcrtomb.c
--- diffutils-2.9.orig/lib/wcrtomb.c	2010-01-08 10:35:20 +0000
+++ diffutils-2.9/lib/wcrtomb.c	2010-03-08 23:41:10 +0000
@@ -15,10 +15,16 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 
+#if defined(__DJGPP__) && !defined(EILSEQ)
+# if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || !defined(__STRICT_ANSI__)
+#   define EILSEQ   41
+# endif /* (__STDC_VERSION__ >= 199901L) || !__STRICT_ANSI__ */
+#endif
+
 /* Specification.  */
 #include <wchar.h>
 
 #include <errno.h>
 #include <stdlib.h>
diff -aprNU5 diffutils-2.9.orig/src/cmp.c diffutils-2.9/src/cmp.c
--- diffutils-2.9.orig/src/cmp.c	2010-02-11 09:39:16 +0000
+++ diffutils-2.9/src/cmp.c	2010-03-08 23:43:26 +0000
@@ -201,10 +201,11 @@ main (int argc, char **argv)
   set_program_name (argv[0]);
   setlocale (LC_ALL, "");
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
   c_stack_action (0);
+  STRIP_FULL_PATH_AND_EXTENSION(argv[0]);
 
   /* Parse command line options.  */
 
   while ((c = getopt_long (argc, argv, "bci:ln:sv", long_options, 0))
 	 != -1)
@@ -259,10 +260,12 @@ main (int argc, char **argv)
   if (optind == argc)
     try_help ("missing operand after `%s'", argv[argc - 1]);
 
   file[0] = argv[optind++];
   file[1] = optind < argc ? argv[optind++] : "-";
+  CANONICALIZE_PATH(file[0]);
+  CANONICALIZE_PATH(file[1]);
 
   for (f = 0; f < 2 && optind < argc; f++)
     {
       char *arg = argv[optind++];
       specify_ignore_initial (f, &arg, 0);
diff -aprNU5 diffutils-2.9.orig/src/diff.c diffutils-2.9/src/diff.c
--- diffutils-2.9.orig/src/diff.c	2010-02-11 09:39:16 +0000
+++ diffutils-2.9/src/diff.c	2010-03-08 23:41:10 +0000
@@ -277,10 +277,11 @@ main (int argc, char **argv)
   set_program_name (argv[0]);
   setlocale (LC_ALL, "");
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
   c_stack_action (0);
+  STRIP_FULL_PATH_AND_EXTENSION(argv[0]);
   function_regexp_list.buf = &function_regexp;
   ignore_regexp_list.buf = &ignore_regexp;
   re_set_syntax (RE_SYNTAX_GREP | RE_NO_POSIX_BACKTRACKING);
   excluded = new_exclude ();
 
@@ -723,21 +724,21 @@ main (int argc, char **argv)
       if (to_file)
 	fatal ("--from-file and --to-file both specified");
       else
 	for (; optind < argc; optind++)
 	  {
-	    int status = compare_files (NULL, from_file, argv[optind]);
+	    int status = compare_files (NULL, from_file, CANONICALIZE_PATH(argv[optind]));
 	    if (exit_status < status)
 	      exit_status = status;
 	  }
     }
   else
     {
       if (to_file)
 	for (; optind < argc; optind++)
 	  {
-	    int status = compare_files (NULL, argv[optind], to_file);
+	    int status = compare_files (NULL, CANONICALIZE_PATH(argv[optind]), to_file);
 	    if (exit_status < status)
 	      exit_status = status;
 	  }
       else
 	{
@@ -747,10 +748,12 @@ main (int argc, char **argv)
 		try_help ("missing operand after `%s'", argv[argc - 1]);
 	      else
 		try_help ("extra operand `%s'", argv[optind + 2]);
 	    }
 
+	  CANONICALIZE_PATH(argv[optind]);
+	  CANONICALIZE_PATH(argv[optind + 1]);
 	  exit_status = compare_files (NULL, argv[optind], argv[optind + 1]);
 	}
     }
 
   /* Print any messages that were saved up for last.  */
diff -aprNU5 diffutils-2.9.orig/src/diff3.c diffutils-2.9/src/diff3.c
--- diffutils-2.9.orig/src/diff3.c	2010-02-11 09:39:16 +0000
+++ diffutils-2.9/src/diff3.c	2010-03-08 23:41:10 +0000
@@ -235,10 +235,11 @@ main (int argc, char **argv)
   set_program_name (argv[0]);
   setlocale (LC_ALL, "");
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
   c_stack_action (0);
+  STRIP_FULL_PATH_AND_EXTENSION(argv[0]);
 
   while ((c = getopt_long (argc, argv, "aeimvx3AEL:TX", longopts, 0)) != -1)
     {
       switch (c)
 	{
@@ -322,11 +323,11 @@ main (int argc, char **argv)
     }
 
   file = &argv[optind];
 
   for (i = tag_count; i < 3; i++)
-    tag_strings[i] = file[i];
+    tag_strings[i] = CANONICALIZE_PATH(file[i]);
 
   /* Always compare file1 to file2, even if file2 is "-".
      This is needed for -mAeExX3.  Using the file0 as
      the common file would produce wrong results, because if the
      file0-file1 diffs didn't line up with the file0-file2 diffs
diff -aprNU5 diffutils-2.9.orig/src/sdiff.c diffutils-2.9/src/sdiff.c
--- diffutils-2.9.orig/src/sdiff.c	2010-02-11 09:39:16 +0000
+++ diffutils-2.9/src/sdiff.c	2010-03-08 23:41:10 +0000
@@ -467,10 +467,11 @@ main (int argc, char *argv[])
   set_program_name (argv[0]);
   setlocale (LC_ALL, "");
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
   c_stack_action (cleanup);
+  STRIP_FULL_PATH_AND_EXTENSION(argv[0]);
 
   prog = getenv ("EDITOR");
   if (prog)
     editor_program = prog;
 
@@ -596,12 +597,12 @@ main (int argc, char *argv[])
       FILE *left, *right, *out, *diffout;
       bool interact_ok;
       struct line_filter lfilt;
       struct line_filter rfilt;
       struct line_filter diff_filt;
-      bool leftdir = diraccess (argv[optind]);
-      bool rightdir = diraccess (argv[optind + 1]);
+      bool leftdir = diraccess (CANONICALIZE_PATH(argv[optind]));
+      bool rightdir = diraccess (CANONICALIZE_PATH(argv[optind + 1]));
 
       if (leftdir & rightdir)
 	fatal ("both files to be compared are directories");
 
       lname = expand_name (argv[optind], leftdir, argv[optind + 1]);
@@ -627,11 +628,11 @@ main (int argc, char *argv[])
 	for (i = 0;  diffargv[i];  i++)
 	  cmdsize += shell_quote_length (diffargv[i]) + 1;
 	command = p = xmalloc (cmdsize);
 	for (i = 0;  diffargv[i];  i++)
 	  {
-	    p = shell_quote_copy (diffargv[i]);
+	    p = shell_quote_copy (p, diffargv[i]);
 	    *p++ = ' ';
 	  }
 	p[-1] = 0;
 	errno = 0;
 	diffout = popen (command, "r");
@@ -1220,11 +1221,14 @@ temporary_file (void)
   char *buf = xmalloc (strlen (dir) + 1 + 5 + 6 + 1);
   int fd;
   int e;
   sigset_t procmask;
   sigset_t blocked;
-  sprintf (buf, "%s/sdiffXXXXXX", dir);
+  if (HAVE_LFN_SUPPORT (dir))
+    sprintf (buf, "%s/sdiffXXXXXX", dir);
+  else
+    sprintf (buf, "%s/dfXXXXXX", dir);
   sigemptyset (&blocked);
   sigaddset (&blocked, SIGINT);
   sigprocmask (SIG_BLOCK, &blocked, &procmask);
   fd = mkstemp (buf);
   e = errno;
diff -aprNU5 diffutils-2.9.orig/src/system.h diffutils-2.9/src/system.h
--- diffutils-2.9.orig/src/system.h	2010-02-05 08:10:14 +0000
+++ diffutils-2.9/src/system.h	2010-03-08 23:41:10 +0000
@@ -226,5 +226,43 @@ verify (sizeof (lin) <= sizeof (long int
     && (s)->st_mtime == (t)->st_mtime \
     && (s)->st_ctime == (t)->st_ctime)
 #endif
 
 #define STREQ(a, b) (strcmp (a, b) == 0)
+
+#ifdef __DJGPP__
+# include <libc/unconst.h>
+# define HAVE_LFN_SUPPORT(name)  (pathconf ((name), _PC_NAME_MAX) > 12)
+# define IS_SLASH(c)             ((c) == '/' || (c) == '\\' || (c) == ':')
+# define STRIP_FULL_PATH_AND_EXTENSION(filename)   \
+  ({                                               \
+      char *_dst, *_src;                           \
+      _dst = _src = unconst((filename), char *);   \
+      while (*_src++)                              \
+        ;                                          \
+      while ((_src - _dst) && (*--_src != '.'))    \
+        ;                                          \
+      for (*_src = '\0'; (_src - _dst); _src--)    \
+        if (IS_SLASH(*_src))                       \
+          break;                                   \
+      if (_src - _dst)                             \
+        while ((*_dst++ = *++_src))                \
+          ;                                        \
+      (filename);                                  \
+  })
+# define CANONICALIZE_PATH(path)                   \
+  ({                                               \
+      if ((path))                                  \
+      {                                            \
+        char *_p = unconst((path), char *);        \
+        for (; *_p; _p++)                          \
+          if (*_p == '\\')                         \
+            *_p = '/';                             \
+      }                                            \
+      (path);                                      \
+  })
+#else
+# define HAVE_LFN_SUPPORT(name)  (true)
+# define STRIP_FULL_PATH_AND_EXTENSION(filename)
+# define CANONICALIZE_PATH(path)  (path)
+#endif
+
diff -aprNU5 diffutils-2.9.orig/src/util.c diffutils-2.9/src/util.c
--- diffutils-2.9.orig/src/util.c	2010-02-11 09:39:16 +0000
+++ diffutils-2.9/src/util.c	2010-03-08 23:41:10 +0000
@@ -226,11 +226,11 @@ begin_output (void)
 	char *command = xmalloc (sizeof pr_program - 1 + 7
 				 + shell_quote_length (name) + 1);
 	char *p;
 	sprintf (command, "%s -f -h ", pr_program);
 	p = command + sizeof pr_program - 1 + 7;
-	p = shell_quote_copy (name);
+	p = shell_quote_copy (p, name);
 	*p = 0;
 	errno = 0;
 	outfile = popen (command, "w");
 	if (!outfile)
 	  pfatal_with_name (command);
