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

	* gl/lib/backupfile.c (numbered_backup): Support for numbered backups
	for SFN systems like DOS.


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

	* gl/lib/backupfile.c (check_extension) [HAVE_DOS_FILE_NAMES]: Support
	for numbered backups for SFN systems like DOS.


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

	* pc/pc_inode.c (create_inode): New function.  Creates an entry for a
	given file name in the inode_table array storing the file name and is
	currently associated file descriptor.  The array index is used as the
	unique st_ino value for this file during runtime.  An array entry is
	never deleted during runtime, so its index can be used as a unique and
	persistent st_ino value.
	(get_inode): New function.  If it finds an entry for the given file
	descriptor in the inode_table array, it returns the array index as
	inode number else -1.
	(reset_descriptor): New function.  If it finds the file descriptor in
	the inode_table array, its set the corresponding file descriptor entry
	to -1.
	(open_wrapper):  New function.  Calls libc open() function and creates
	an entry in inode_table for the given file name and descriptor calling
	create_node.  If an entry already exists for the file name only the
	descriptor is stored.
	(close_wrapper):  New function.  Calls libc close() function and resets
	the descriptor value for the file name entry in inode_tabler calling
	reset_descriptor.
	(stat_wrapper):  New function.  Calls libc stat() function and creates
	an entry in inode_table for the given file name calling create_node.
	If an entry already exists for the file name only the descriptor is
	reset to -1.
	(fstat_wrapper):  New function.  Calls libc fstat() function and sets
	the inode number for that file descriptor calling get_inode.  If no
	inode number is returned by get_inode, the original is left unaltered.


2010-04-24  Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	* gl/lib/backupfile.c (numbered_backup): Support for numbered backups
	for SFN systems like DOS.


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

	* gl/lib/backupfile.c [__libsupp_h__]: Only undef opendir if not
	compiled with libsupp.


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

	* src/quotesys.c (quote_system_arg): If quote_system_arg_func defined
	call a platform specific quoting scheme of "system".

	* src/common.h [HAVE_SETMODE_DOS]: Include io.h to provide the function
	prototype of setmode.


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

	* gl/lib/quotearg.c: New macros defined.  DJGPP specific definitions are
	provided by config.h.  If not defined DEFAULT_OS_QUOTING_STYLE defaults
	to "shell_quoting_style" and DEFAULT_OS_QUOTING_STYLE_DCL to empty.
	Add "dos-shell" and "nt-shell" to quoting_style_args.
	(set_quoting_style): Set quoting style to DEFAULT_OS_QUOTING_STYLE.
	(quotearg_buffer_restyled): Quote DJGPP and DOS specific characters
	"'", "." and "%".

	* gl/lib/quotearg.h: Add default_quoting_style, dos_shell_quoting_style
	and nt_shell_quoting_style to quoting_style.
	[DEFAULT_QUOTING_STYLE]: If not defined define DEFAULT_QUOTING_STYLE
	to default_quoting_style.

	* src/patch.c (main): Use macro DEFAULT_QUOTING_STYLE instead of
	default UNIX shell quoting style.


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

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

	* src/patch.c (main): Use STRIP_EXTENSION to strip the extension from
	argv[0].
	[FILESYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR]: If defined use P_tmpdir
	as TMPDIR value, if not default to "c:".

	* pc/pc_quote.c: DJGPP/DOS specific file handling the quoting flavor of
	the different kind of supported shells.  These are ndos.com, 4dos.com,
	cmd.exe, command.com and bash.exe.






diff -aprNU5 patch-2.6.1.orig/gl/lib/backupfile.c patch-2.6.1/gl/lib/backupfile.c
--- patch-2.6.1.orig/gl/lib/backupfile.c	2009-11-02 19:09:56 +0000
+++ patch-2.6.1/gl/lib/backupfile.c	2010-05-15 22:20:34 +0000
@@ -80,12 +80,14 @@
    of `digit' even when the host does not conform to POSIX.  */
 #define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
 
 /* The results of opendir() in this file are not used with dirfd and fchdir,
    therefore save some unnecessary work in fchdir.c.  */
+#ifndef __libsupp_h__
 #undef opendir
 #undef closedir
+#endif
 
 /* The extension added to file names to produce a simple (as opposed
    to numbered) backup file name. */
 char const *simple_backup_suffix = "~";
 
@@ -124,11 +126,83 @@ check_extension (char *file, size_t file
     }
 
   if (HAVE_DOS_FILE_NAMES && baselen_max <= 12)
     {
       /* Live within DOS's 8.3 limit.  */
-      char *dot = strchr (base, '.');
+      char *dot, *ext = base + filelen;
+      size_t extlen = baselen - filelen;  /* Including terminating zero and discarding leading dot.  */
+
+      for (dot = ext - 1; *dot != '.' && dot > base; dot--)
+        ;
+
+      if (dot > base)
+      {
+#define EXT_PART_PART_LEN  3
+
+        /* DOS doesn't allow more than a single dot.  */
+        ext++;
+
+        /* If EXT is "~N~" and there's not enough space to append it,
+           lose the leading `~' so that we could salvage more of the
+           original name ("foo.c" + ".~9~" -> "foo.c9~" or
+           "bar.txt" + ".~12~" -> "bar.12~").  */
+        if (*ext == '~')
+        {
+          ext++;
+          extlen--;
+        }
+        if (extlen < EXT_PART_PART_LEN + 2)
+        {
+          memcpy(dot + EXT_PART_PART_LEN - extlen + 1, ext, extlen);
+          return;
+        }
+
+#undef EXT_PART_PART_LEN
+      }
+      else
+      {
+#define BASE_PART_LEN  8
+
+        if (ext[1] == '~')
+        {
+          ext++;
+          extlen--;
+        }
+
+        if (extlen < 5)
+        {
+          /* If the file has no extension and the back up extension,
+             after removing the leading tilde, fits in the 3 characters
+             long extension append it to the base part of the file name.
+             E.g.:  "foobar" + "~12~" -> "foobar.12~".  */
+
+          memcpy(ext, ext + 1, extlen);
+          return;
+        }
+
+        if (extlen > 4 && BASE_PART_LEN - (extlen - 1) > 0)
+        {
+          /* If the file has no extension and the back up extension
+             is larger than 3 characters, use the base part of the
+             file name.  The first file name character is always retained.
+             If this is not possible give up.
+             E.g.:  "foobar" + "~123456~" -> "f123456~".  */
+
+          size_t base_offset, diff = filelen + extlen - 1 - BASE_PART_LEN;  /*  one more for the terminating zero.  */
+
+          if (*ext == '~')
+            ext++;
+          base_offset = diff > 0 ? filelen - diff : filelen;
+          memcpy(base + base_offset, ext, extlen);
+          return;
+        }
+
+        dot = NULL;
+
+#undef  BASE_PART_LEN
+      }
+
       if (!dot)
 	baselen_max = 8;
       else
 	{
 	  char const *second_dot = strchr (dot + 1, '.');
@@ -201,21 +275,49 @@ numbered_backup (char **buffer, size_t b
 
   while ((dp = readdir (dirp)) != NULL)
     {
       char const *p;
       char *q;
-      bool all_9s;
+      bool all_9s, names_are_different;
       size_t versionlen;
       size_t new_buflen;
+      size_t i;
 
-      if (! REAL_DIR_ENTRY (dp) || _D_EXACT_NAMLEN (dp) < baselen + 4)
+      if (! REAL_DIR_ENTRY (dp)
+	  /* Under DOS 8+3 file name limits, backup extensions
+	     may consume part of the original name.  */
+	  || (! HAVE_DOS_FILE_NAMES && _D_EXACT_NAMLEN (dp) < baselen + 4)
+	  || _D_EXACT_NAMLEN (dp) < baselen)
 	continue;
 
+#if HAVE_DOS_FILE_NAMES
+      q = buf + base_offset;
+      for (names_are_different = false, i = 0; i < baselen; i++)
+        if (!filename_char_eq(q[i], dp->d_name[i]))
+        {
+          names_are_different = true;
+          break;
+        }
+      if (names_are_different)
+        continue;
+
+      /* The case "foobar.txt" vs "foobar.12~".  */
+      if (q[i] == '.' && dp->d_name[i] == '.')
+      {
+        if (i++, q[i] == '~' && dp->d_name[i] == '~')
+          p = dp->d_name + baselen + 2;
+        else
+          p = dp->d_name + baselen + 1;
+      }
+      else
+        continue;
+#else
       if (memcmp (buf + base_offset, dp->d_name, baselen + 2) != 0)
 	continue;
 
       p = dp->d_name + baselen + 2;
+#endif
 
       /* Check whether this file has a version number and if so,
 	 whether it is larger.  Use string operations rather than
 	 integer arithmetic, to avoid problems with integer overflow.  */
 
diff -aprNU5 patch-2.6.1.orig/gl/lib/quotearg.c patch-2.6.1/gl/lib/quotearg.c
--- patch-2.6.1.orig/gl/lib/quotearg.c	2009-11-02 19:09:56 +0000
+++ patch-2.6.1/gl/lib/quotearg.c	2010-05-12 19:47:34 +0000
@@ -22,10 +22,18 @@
 
 #include "quotearg.h"
 
 #include "xalloc.h"
 
+#ifndef DEFAULT_OS_QUOTING_STYLE
+# define DEFAULT_OS_QUOTING_STYLE shell_quoting_style
+#endif
+
+#ifdef DEFAULT_OS_QUOTING_STYLE_DCL
+ DEFAULT_OS_QUOTING_STYLE_DCL
+#endif
+
 #include <ctype.h>
 #include <errno.h>
 #include <limits.h>
 #include <stdbool.h>
 #include <stdlib.h>
@@ -65,10 +73,12 @@ char const *const quoting_style_args[] =
   "c",
   "c-maybe",
   "escape",
   "locale",
   "clocale",
+  "dos-shell",
+  "nt-shell",
   0
 };
 
 /* Correspondences to quoting style names.  */
 enum quoting_style const quoting_style_vals[] =
@@ -109,10 +119,12 @@ get_quoting_style (struct quoting_option
 /* In O (or in the default if O is null),
    set the value of the quoting style to S.  */
 void
 set_quoting_style (struct quoting_options *o, enum quoting_style s)
 {
+  if (s == default_quoting_style)
+    s = DEFAULT_OS_QUOTING_STYLE;
   (o ? o : &default_quoting_options)->style = s;
 }
 
 /* In O (or in the default if O is null),
    set the value of the quoting options for character C to I.
@@ -270,10 +282,14 @@ quotearg_buffer_restyled (char *buffer,
 
     case literal_quoting_style:
       elide_outer_quotes = false;
       break;
 
+    case dos_shell_quoting_style:
+    case nt_shell_quoting_style:
+      break;
+
     default:
       abort ();
     }
 
   for (i = 0;  ! (argsize == SIZE_MAX ? arg[i] == '\0' : i == argsize);  i++)
@@ -408,10 +424,13 @@ quotearg_buffer_restyled (char *buffer,
 		goto force_outer_quoting_style;
 	      STORE ('\'');
 	      STORE ('\\');
 	      STORE ('\'');
 	    }
+	  else if ((quoting_style == dos_shell_quoting_style) ||
+	           (quoting_style == nt_shell_quoting_style))
+		goto force_outer_quoting_style;
 	  break;
 
 	case '%': case '+': case ',': case '-': case '.': case '/':
 	case '0': case '1': case '2': case '3': case '4': case '5':
 	case '6': case '7': case '8': case '9': case ':':
@@ -424,10 +443,23 @@ quotearg_buffer_restyled (char *buffer,
 	case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
 	case 'o': case 'p': case 'q': case 'r': case 's': case 't':
 	case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
 	  /* These characters don't cause problems, no matter what the
 	     quoting style is.  They cannot start multibyte sequences.  */
+	  switch (c)
+	    {
+	    case '.': /* `...': special in DJGPP wildcard expansion */
+	      if (quoting_style != shell_quoting_style
+	          && arg[i + 1] == '.' && arg[i + 2] == '.'
+	          && strchr ("\\/", arg[i + 3]))
+	        goto force_outer_quoting_style;
+	      break;
+	    case '%':
+	      if (quoting_style == dos_shell_quoting_style)  /* need to double it under DOS shells */
+	        STORE (c);
+	      break;
+	    }
 	  break;
 
 	default:
 	  /* If we have a multibyte sequence, copy it until we reach
 	     its end, find an error, or come back to the initial shift
diff -aprNU5 patch-2.6.1.orig/gl/lib/quotearg.h patch-2.6.1/gl/lib/quotearg.h
--- patch-2.6.1.orig/gl/lib/quotearg.h	2009-11-02 19:09:56 +0000
+++ patch-2.6.1/gl/lib/quotearg.h	2010-05-12 19:47:34 +0000
@@ -29,10 +29,12 @@
    style and the default flags and quoted characters.  Note that the
    examples are shown here as valid C strings rather than what
    displays on a terminal (with "??/" as a trigraph for "\\").  */
 enum quoting_style
   {
+    default_quoting_style,	/* --quoting-style=default */
+
     /* Output names as-is (ls --quoting-style=literal).  Can result in
        embedded null bytes if QA_ELIDE_NULL_BYTES is not in
        effect.
 
        quotearg_buffer:
@@ -109,10 +111,14 @@ enum quoting_style
        quotearg_colon:
        "simple", "\\0 \\t\\n'\"\\033??/\\\\", "a\\:b"
     */
     escape_quoting_style,
 
+    dos_shell_quoting_style,	/* --quoting-style=dos-shell */
+
+    nt_shell_quoting_style,	/* --quoting-style=nt-shell */
+
     /* Like clocale_quoting_style, but quote `like this' instead of
        "like this" in the default C locale (ls --quoting-style=locale).
 
        LC_MESSAGES=C
        quotearg_buffer:
@@ -180,11 +186,11 @@ enum quoting_flags
     QA_SPLIT_TRIGRAPHS = 0x04
   };
 
 /* For now, --quoting-style=literal is the default, but this may change.  */
 # ifndef DEFAULT_QUOTING_STYLE
-#  define DEFAULT_QUOTING_STYLE literal_quoting_style
+#  define DEFAULT_QUOTING_STYLE default_quoting_style
 # endif
 
 /* Names of quoting styles and their corresponding values.  */
 extern char const *const quoting_style_args[];
 extern enum quoting_style const quoting_style_vals[];
diff -aprNU5 patch-2.6.1.orig/pc/pc_inode.c patch-2.6.1/pc/pc_inode.c
--- patch-2.6.1.orig/pc/pc_inode.c	1970-01-01 00:00:00 +0000
+++ patch-2.6.1/pc/pc_inode.c	2010-05-15 16:22:58 +0000
@@ -0,0 +1,238 @@
+/* pc_inode.c - assign the same unique st_ino to a file name
+   and its file descriptor.
+   Copyright (C) 2010 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
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+/* Written by Juan M. Guerrero <juan.guerrero@gmx.de>,  2010-05-08.  */
+
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#if HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
+
+#if HAVE_STRING_H
+# include <string.h>
+#endif
+
+#include <ctype.h>
+#include <stdarg.h>
+#include <stdbool.h>
+
+
+void *xmalloc(size_t size);
+
+typedef struct inode_table_entry_tag *entry_ptr;
+typedef struct inode_table_entry_tag {
+  ino_t      inode_number;
+  int        fd;
+  char      *file_name;
+  entry_ptr  next_inode;
+} inode_table_entry;
+
+static entry_ptr first_inode = NULL;
+
+
+ino_t create_inode(const char *file_name, const int fd)
+{
+  int length;
+  bool file_name_found;
+  entry_ptr last_inode, inode;
+
+
+  if (!first_inode)
+  {
+    first_inode = xmalloc(sizeof(inode_table_entry));
+    first_inode->inode_number = 0;
+    first_inode->fd = -1;
+    first_inode->file_name = NULL;
+    first_inode->next_inode = NULL;
+  }
+  inode = first_inode;
+
+
+  /*
+   *  Check if file name has already been registred.
+   */
+  for (file_name_found = true, last_inode = inode; inode && inode->file_name; last_inode = inode, inode = inode->next_inode, file_name_found = true)
+  {
+    int i;
+
+    for (i = 0; inode->file_name[i] && file_name[i]; i++)
+      if (!filename_char_eq(inode->file_name[i], file_name[i]))
+      {
+        file_name_found = false;
+        break;
+      }
+
+    if (file_name_found && inode->file_name[i] == file_name[i])
+    {
+      if (inode->fd == -1)
+        inode->fd = fd;
+      return inode->inode_number;
+    }
+  }
+
+
+  /*
+   *  File name has not already been registred
+   *  so allocate a new entry in the list and
+   *  return the list index as inode number.
+   */
+  for (length = 0; file_name[length]; length++)
+    ;
+  length++;
+
+  if (!inode)
+  {
+    inode = xmalloc(sizeof(inode_table_entry));
+    last_inode->next_inode = inode;
+  }
+  inode->next_inode = NULL;
+  inode->inode_number = last_inode->inode_number + 1;
+  inode->fd = fd;
+  inode->file_name = xmalloc(length * sizeof(char));;
+  memcpy(inode->file_name, file_name, length);
+ 
+  return inode->inode_number;
+}
+
+
+ino_t get_inode(const int fd)
+{
+  entry_ptr inode;
+
+
+  for (inode = first_inode; inode; inode = inode->next_inode)
+    if (inode->fd == fd)
+      return inode->inode_number;
+
+  return (ino_t)(-1);
+}
+
+
+void reset_descriptor(int fd)
+{
+  entry_ptr inode;
+
+
+  for (inode = first_inode; inode; inode = inode->next_inode)
+    if (inode->fd == fd)
+    {
+      inode->fd = -1;
+      return;
+    }
+}
+
+
+/*  Use DJGPP's stat function in stat_wrapper.  */
+#undef stat
+
+int stat_wrapper(const char *file_name, struct stat *stat_buf)
+{
+  int status;
+
+
+  status = stat(file_name, stat_buf);
+  stat_buf->st_ino = create_inode(file_name, -1);
+
+  return status;
+}
+
+
+/*  Use DJGPP's fstat function in fstat_wrapper.  */
+#undef fstat
+
+int fstat_wrapper(int fd, struct stat *stat_buf)
+{
+  int status;
+  ino_t inode_number;
+
+
+  status = fstat(fd, stat_buf);
+  if (isatty(fd))
+    return status;
+
+  if ((inode_number = get_inode(fd)) != (ino_t)(-1))
+    stat_buf->st_ino = inode_number;
+
+  return status;
+}
+
+
+/*  Use DJGPP's open function in open_wrapper.  */
+#undef open
+
+int open_wrapper(const char *file_name, int mode, ...)
+{
+  int fd, permissions = *(&mode + 1);
+
+
+  fd = open(file_name, mode, permissions);
+  create_inode(file_name, fd);
+
+  return fd;
+}
+
+
+/*  Use DJGPP's close function in close_wrapper.  */
+#undef close
+
+int close_wrapper(int fd)
+{
+  int status;
+
+
+  status = close(fd);
+  reset_descriptor(fd);
+
+  return status;
+}
+
+
+/*  Use DJGPP's fopen function in fopen_wrapper.  */
+#undef fopen
+
+FILE *fopen_wrapper(const char *file_name, const char *mode)
+{
+  FILE *fp;
+
+
+  fp = fopen(file_name, mode);
+  if (fp)
+    create_inode(file_name, fileno(fp));
+
+  return fp;
+}
+
+
+/*  Use DJGPP's fclose function in fclose_wrapper.  */
+#undef fclose
+
+int fclose_wrapper(FILE *fp)
+{
+  int fd, status;
+
+
+  fd = fileno(fp);
+  status = fclose(fp);
+  reset_descriptor(fd);
+
+  return status;
+}
diff -aprNU5 patch-2.6.1.orig/pc/pc_quote.c patch-2.6.1/pc/pc_quote.c
--- patch-2.6.1.orig/pc/pc_quote.c	1970-01-01 00:00:00 +0000
+++ patch-2.6.1/pc/pc_quote.c	2010-05-12 19:47:34 +0000
@@ -0,0 +1,105 @@
+/* pc_quote.c - quoting functions specific to PC environments
+   Copyright (C) 1998 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
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#if HAVE_STDLIB_H
+# include <stdlib.h>
+#else
+extern char *getenv();
+#endif
+
+#if HAVE_STRING_H
+# include <string.h>
+#endif
+
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#ifndef F_OK
+# define F_OK 0
+#endif
+
+#include <ctype.h>
+
+#include <quotearg.h>
+#include <backupfile.h>
+#include <dirname.h>
+
+struct shell_spec {
+  const char *name;
+  const size_t name_len;
+  const enum quoting_style style;
+};
+
+#include <stdio.h>
+
+/* Determine the default quoting style suitable for the user's shell.  */
+enum quoting_style
+dos_nt_quoting (void)
+{
+  /* Environment variables used to specify the user shell.  */
+  static char const *const shell_denominators[] = {
+    "BASH", "SHELL", "COMSPEC", "ComSpec", 0
+  };
+
+  /* List of shells which don't support Unix-style shell_quoting_style.  */
+  static char const command_com[] = "COMMAND.COM";
+  static char const fordos_com[] = "4DOS.COM";
+  static char const ndos_com[] = "NDOS.COM";
+  static char const cmd_exe[] = "CMD.EXE";
+
+  static struct shell_spec const dos_nt_shells[] = {
+    {command_com, sizeof(command_com) - 1, dos_shell_quoting_style},
+    {fordos_com, sizeof(fordos_com) - 1, dos_shell_quoting_style},
+    {ndos_com, sizeof(ndos_com) - 1, dos_shell_quoting_style},
+    {cmd_exe, sizeof(cmd_exe) - 1, nt_shell_quoting_style},
+    {0, 0, 0}
+  };
+
+  const char *const *shell_to_try = shell_denominators;
+  char *shell = NULL;
+
+  while (*shell_to_try
+	 && ((shell = getenv (*shell_to_try)) == NULL
+	     /* Make sure it is indeed a name of an existing file.  */
+	     || access (shell, F_OK) == -1))
+    shell_to_try++;
+
+  if (shell)
+    {
+      char *shell_base = base_name (shell);
+      size_t shell_base_len = strlen (shell_base);
+      const struct shell_spec *try_shell;
+
+      for (try_shell = dos_nt_shells; try_shell->name; try_shell++)
+	if (shell_base_len == try_shell->name_len)
+	  {
+	    const char *s = shell_base, *p = try_shell->name;
+
+	    for ( ; *s && *p && filename_char_eq (*s, *p); s++, p++)
+	      ;
+	    if (*s == '\0' && *p == '\0')
+	      return try_shell->style;
+	  }
+    }
+
+  /* All other shells are assumed to be Unix-like.  */
+  return shell_quoting_style;
+}
diff -aprNU5 patch-2.6.1.orig/src/common.h patch-2.6.1/src/common.h
--- patch-2.6.1.orig/src/common.h	2009-12-30 12:56:30 +0000
+++ patch-2.6.1/src/common.h	2010-05-14 01:10:22 +0000
@@ -246,10 +246,11 @@ extern int errno;
 # undef mkdir
 # define mkdir(name, mode) ((mkdir) (name))
 #endif
 
 #ifdef HAVE_SETMODE_DOS
+# include <io.h>		/* Function prototype of setmode */
   XTERN int binary_transput;	/* O_BINARY if binary i/o is desired */
 #else
 # define binary_transput 0
 #endif
 
@@ -288,5 +289,38 @@ XTERN enum conflict_style conflict_style
 
 bool merge_hunk (int hunk, struct outstate *, LINENUM where, bool *);
 #else
 # define merge_hunk(hunk, outstate, where, somefailed) false
 #endif
+
+#ifdef __DJGPP__
+#undef  IS_DIR_SEPARATOR
+#define IS_DIR_SEPARATOR(c)  ((c) == '/' || (c) == '\\' || (c) == ':')
+# include <libc/unconst.h>
+# define STRIP_EXTENSION(filename)                  \
+  ({                                                \
+      char *_begin, *_end;                          \
+      _begin = _end = unconst((filename), char *);  \
+      while (*_end++)                               \
+        ;                                           \
+      while ((_end - _begin) && (*--_end != '.'))   \
+        ;                                           \
+      if (*_end == '.')                             \
+        *_end = '\0';                               \
+      (filename);                                   \
+  })
+# define CANONICALIZE_PATH(path)                    \
+  ({                                                \
+      if ((path))                                   \
+      {                                             \
+        char *_p = unconst((path), char *);         \
+        for (; *_p; _p++)                           \
+          if (*_p == '\\')                          \
+            *_p = '/';                              \
+      }                                             \
+      (path);                                       \
+  })
+#else
+# define STRIP_EXTENSION(filename)  (filename)
+# define CANONICALIZE_PATH(path)    (path)
+#endif
+
diff -aprNU5 patch-2.6.1.orig/src/patch.c patch-2.6.1/src/patch.c
--- patch-2.6.1.orig/src/patch.c	2009-12-30 12:56:30 +0000
+++ patch-2.6.1/src/patch.c	2010-05-12 19:47:34 +0000
@@ -105,11 +105,11 @@ main (int argc, char **argv)
     char numbuf[LINENUM_LENGTH_BOUND + 1];
     bool written_to_rejname = false;
     bool apply_empty_patch = false;
 
     exit_failure = 2;
-    program_name = argv[0];
+    program_name = STRIP_EXTENSION(argv[0]);
     init_time ();
 
     setbuf(stderr, serrbuf);
 
     bufsize = 8 * 1024;
@@ -119,11 +119,11 @@ main (int argc, char **argv)
 
     val = getenv ("QUOTING_STYLE");
     {
       int i = val ? argmatch (val, quoting_style_args, 0, 0) : -1;
       set_quoting_style ((struct quoting_options *) 0,
-			 i < 0 ? shell_quoting_style : (enum quoting_style) i);
+			 i < 0 ? DEFAULT_QUOTING_STYLE : (enum quoting_style) i);
     }
 
     posixly_correct = getenv ("POSIXLY_CORRECT") != 0;
     backup_if_mismatch = ! posixly_correct;
     patch_get = ((val = getenv ("PATCH_GET"))
@@ -1517,11 +1517,19 @@ similar (register char const *a, registe
 #if HAVE_MKTEMP && ! HAVE_DECL_MKTEMP && ! defined mktemp
 char *mktemp (char *);
 #endif
 
 #ifndef TMPDIR
-#define TMPDIR "/tmp"
+# if FILESYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR
+#  ifdef P_tmpdir
+#   define TMPDIR P_tmpdir
+#  else
+#   define TMPDIR "c:"
+#  endif
+# else /* POSIX systems */
+#  define TMPDIR "/tmp"
+# endif
 #endif
 
 static char const *
 make_temp (char letter)
 {
diff -aprNU5 patch-2.6.1.orig/src/quotesys.c patch-2.6.1/src/quotesys.c
--- patch-2.6.1.orig/src/quotesys.c	2009-11-02 19:09:56 +0000
+++ patch-2.6.1/src/quotesys.c	2010-05-12 19:47:34 +0000
@@ -35,10 +35,16 @@ quote_system_arg (quoted, arg)
      char const *arg;
 {
   char const *a;
   size_t len = 0;
 
+  /* A hook for non-Posix platforms to define a quoting
+     scheme peculiar to their implementation of `system'.  */
+#ifdef quote_system_arg_func
+  return quote_system_arg_func (quoted, arg);
+#else
+
   /* Scan ARG, copying it to QUOTED if QUOTED is not null,
      looking for shell metacharacters.  */
 
   for (a = arg; ; a++)
     {
@@ -120,6 +126,7 @@ quote_system_arg (quoted, arg)
 
       if (quoted)
 	quoted[len] = c;
       len++;
     }
+#endif /* nonposix_quote_system_arg */
 }
