1--- origsrc/bash-4.4/bashline.c 2017-01-23 13:28:06.955247200 -0600
2+++ src/bash-4.4/bashline.c 2017-01-23 13:55:07.992877600 -0600
3@@ -76,6 +76,16 @@
4 # include "pcomplete.h"
5 #endif
6
7+#if __CYGWIN__
8+# ifdef __x86_64__
9+# define IMP(x) __imp_##x
10+# else
11+# define IMP(x) _imp__##x
12+# endif
13+#else
14+# define IMP(x) x
15+#endif
16+
17 /* These should agree with the defines for emacs_mode and vi_mode in
18 rldefs.h, even though that's not a public readline header file. */
19 #ifndef EMACS_EDITING_MODE
20@@ -271,6 +281,11 @@ int no_empty_command_completion;
21 are the only possible matches, even if FIGNORE says to. */
22 int force_fignore = 1;
23
24+#if __CYGWIN__
25+/* If set, shorten "foo.exe" to "foo" when they are the same file. */
26+int completion_strip_exe;
27+#endif /* __CYGWIN__ */
28+
29 /* Perform spelling correction on directory names during word completion */
30 int dircomplete_spelling = 0;
31
32@@ -498,11 +513,12 @@ initialize_readline ()
33 kseq[0] = CTRL('J');
34 kseq[1] = '\0';
35 func = rl_function_of_keyseq (kseq, emacs_meta_keymap, (int *)NULL);
36- if (func == rl_vi_editing_mode)
37+ extern rl_command_func_t *IMP(rl_vi_editing_mode);
38+ if (func == rl_vi_editing_mode || func == IMP(rl_vi_editing_mode))
39 rl_unbind_key_in_map (CTRL('J'), emacs_meta_keymap);
40 kseq[0] = CTRL('M');
41 func = rl_function_of_keyseq (kseq, emacs_meta_keymap, (int *)NULL);
42- if (func == rl_vi_editing_mode)
43+ if (func == rl_vi_editing_mode || func == IMP(rl_vi_editing_mode))
44 rl_unbind_key_in_map (CTRL('M'), emacs_meta_keymap);
45 #if defined (VI_MODE)
46 rl_unbind_key_in_map (CTRL('E'), vi_movement_keymap);
47@@ -521,7 +537,8 @@ initialize_readline ()
48 kseq[0] = '~';
49 kseq[1] = '\0';
50 func = rl_function_of_keyseq (kseq, emacs_meta_keymap, (int *)NULL);
51- if (func == 0 || func == rl_tilde_expand)
52+ extern rl_command_func_t *IMP(rl_tilde_expand);
53+ if (func == 0 || func == rl_tilde_expand || func == IMP(rl_tilde_expand))
54 rl_bind_keyseq_in_map (kseq, bash_complete_username, emacs_meta_keymap);
55
56 rl_bind_key_if_unbound_in_map ('~', bash_possible_username_completions, emacs_ctlx_keymap);
57@@ -544,7 +561,8 @@ initialize_readline ()
58 kseq[0] = TAB;
59 kseq[1] = '\0';
60 func = rl_function_of_keyseq (kseq, emacs_meta_keymap, (int *)NULL);
61- if (func == 0 || func == rl_tab_insert)
62+ extern rl_command_func_t *IMP(rl_tab_insert);
63+ if (func == 0 || func == rl_tab_insert || func == IMP(rl_tab_insert))
64 rl_bind_key_in_map (TAB, dynamic_complete_history, emacs_meta_keymap);
65
66 /* Tell the completer that we want a crack first. */
67@@ -2194,6 +2212,21 @@ globword:
68
69 if (match && executable_completion ((searching_path ? val : cval), searching_path))
70 {
71+#if __CYGWIN__
72+ if (completion_strip_exe)
73+ {
74+ size_t val_len = strlen (val);
75+ char *candidate;
76+ if (val_len > 4 && !strcasecmp (&val[val_len - 4], ".exe")
77+ && (candidate = strdup (val)))
78+ {
79+ candidate[val_len - 4] = '\0';
80+ if (same_file (val, candidate, NULL, NULL))
81+ temp[strlen (temp) - 4] = '\0';
82+ free (candidate);
83+ }
84+ }
85+#endif
86 if (cval != val)
87 free (cval);
88 free (val);
89@@ -2929,6 +2962,17 @@ test_for_directory (name)
90 int r;
91
92 fn = bash_tilde_expand (name, 0);
93+#if __CYGWIN
94+ /* stat("//server") can only be successful as a directory, but can take
95+ seconds to time out on failure. It is much faster to assume that
96+ "//server" is a valid name than it is to wait for a stat, even if it
97+ gives false positives on bad names. */
98+ if (fn[0] == '/' && fn[1] == '/' && ! strchr (&fn[2], '/'))
99+ {
100+ free (fn);
101+ return 1;
102+ }
103+#endif
104 r = file_isdir (fn);
105 free (fn);
106
107--- origsrc/bash-4.4/builtins/read.def 2017-01-23 13:28:07.017686500 -0600
108+++ src/bash-4.4/builtins/read.def 2017-01-23 13:55:07.992877600 -0600
109@@ -85,7 +85,6 @@ $END
110
111 #ifdef __CYGWIN__
112 # include <fcntl.h>
113-# include <io.h>
114 #endif
115
116 #include "../bashintl.h"
117@@ -530,10 +529,6 @@ read_builtin (list)
118 fflush (stderr);
119 }
120
121-#if defined (__CYGWIN__) && defined (O_TEXT)
122- setmode (0, O_TEXT);
123-#endif
124-
125 ps2 = 0;
126 for (print_ps2 = eof = retval = 0;;)
127 {
128@@ -664,6 +659,14 @@ read_builtin (list)
129 if (c == '\0' && delim != '\0')
130 continue; /* skip NUL bytes in input */
131
132+#ifdef __CYGWIN__
133+ {
134+ extern igncr;
135+ if (igncr && c == '\r' && delim != '\r')
136+ continue; /* skip carriage return */
137+ }
138+#endif
139+
140 if ((skip_ctlesc == 0 && c == CTLESC) || (skip_ctlnul == 0 && c == CTLNUL))
141 {
142 saw_escape++;
143--- origsrc/bash-4.4/builtins/set.def 2016-06-02 19:10:10.000000000 -0500
144+++ src/bash-4.4/builtins/set.def 2017-01-23 13:55:07.992877600 -0600
145@@ -56,6 +56,13 @@ extern int dont_save_function_defs;
146 #if defined (READLINE)
147 extern int no_line_editing;
148 #endif /* READLINE */
149+#ifdef __CYGWIN__
150+extern int igncr;
151+static int set_minus_o_option_maybe (int, const char *, int);
152+# define INTERACTIVE_ONLY ,1
153+#else
154+# define INTERACTIVE_ONLY
155+#endif
156
157 $BUILTIN set
158 $FUNCTION set_builtin
159@@ -92,6 +99,9 @@ Options:
160 #if defined (HISTORY)
161 history enable command history
162 #endif
163+#ifdef __CYGWIN__
164+ igncr on Cygwin, ignore \r in line endings
165+#endif
166 ignoreeof the shell will not exit upon reading EOF
167 interactive-comments
168 allow comments to appear in interactive commands
169@@ -192,29 +202,39 @@ const struct {
170 int *variable;
171 setopt_set_func_t *set_func;
172 setopt_get_func_t *get_func;
173+#ifdef __CYGWIN__
174+ /* Cygwin users have taken to exporting SHELLOPTS for the cygwin-specific
175+ igncr. As a result, we want to ensure SHELLOPTS parsing does not turn
176+ on interactive options when exported from an interactive shell, but
177+ parse in a non-interactive setting, so as not to break POSIX /bin/sh */
178+ int interactive_only;
179+#endif
180 } o_options[] = {
181 { "allexport", 'a', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
182 #if defined (BRACE_EXPANSION)
183 { "braceexpand",'B', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
184 #endif
185 #if defined (READLINE)
186- { "emacs", '\0', (int *)NULL, set_edit_mode, get_edit_mode },
187+ { "emacs", '\0', (int *)NULL, set_edit_mode, get_edit_mode INTERACTIVE_ONLY },
188 #endif
189 { "errexit", 'e', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
190 { "errtrace", 'E', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
191 { "functrace", 'T', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
192 { "hashall", 'h', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
193 #if defined (BANG_HISTORY)
194- { "histexpand", 'H', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
195+ { "histexpand", 'H', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL INTERACTIVE_ONLY },
196 #endif /* BANG_HISTORY */
197 #if defined (HISTORY)
198- { "history", '\0', &enable_history_list, bash_set_history, (setopt_get_func_t *)NULL },
199+ { "history", '\0', &enable_history_list, bash_set_history, (setopt_get_func_t *)NULL INTERACTIVE_ONLY },
200+#endif
201+#ifdef __CYGWIN__
202+ { "igncr", '\0', &igncr, NULL, (setopt_get_func_t *)NULL },
203 #endif
204 { "ignoreeof", '\0', &ignoreeof, set_ignoreeof, (setopt_get_func_t *)NULL },
205 { "interactive-comments", '\0', &interactive_comments, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
206 { "keyword", 'k', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
207 #if defined (JOB_CONTROL)
208- { "monitor", 'm', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
209+ { "monitor", 'm', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL INTERACTIVE_ONLY },
210 #endif
211 { "noclobber", 'C', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
212 { "noexec", 'n', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
213@@ -233,7 +253,7 @@ const struct {
214 { "privileged", 'p', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
215 { "verbose", 'v', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
216 #if defined (READLINE)
217- { "vi", '\0', (int *)NULL, set_edit_mode, get_edit_mode },
218+ { "vi", '\0', (int *)NULL, set_edit_mode, get_edit_mode INTERACTIVE_ONLY },
219 #endif
220 { "xtrace", 'x', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
221 {(char *)NULL, 0 , (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
222@@ -455,6 +475,15 @@ int
223 set_minus_o_option (on_or_off, option_name)
224 int on_or_off;
225 char *option_name;
226+#ifdef __CYGWIN__
227+{
228+ /* See Cygwin comments above. */
229+ return set_minus_o_option_maybe (on_or_off, option_name, 0);
230+}
231+static int
232+set_minus_o_option_maybe (int on_or_off, const char *option_name,
233+ int avoid_interactive)
234+#endif /* __CYGWIN__ */
235 {
236 register int i;
237
238@@ -462,6 +491,10 @@ set_minus_o_option (on_or_off, option_na
239 {
240 if (STREQ (option_name, o_options[i].name))
241 {
242+#ifdef __CYGWIN__
243+ if (o_options[i].interactive_only && avoid_interactive)
244+ return EXECUTION_SUCCESS;
245+#endif
246 if (o_options[i].letter == 0)
247 {
248 previous_option_value = GET_BINARY_O_OPTION_VALUE (i, o_options[i].name);
249@@ -588,7 +621,11 @@ parse_shellopts (value)
250 vptr = 0;
251 while (vname = extract_colon_unit (value, &vptr))
252 {
253+#ifdef __CYGWIN__
254+ set_minus_o_option_maybe (FLAG_ON, vname, !interactive_shell);
255+#else
256 set_minus_o_option (FLAG_ON, vname);
257+#endif
258 free (vname);
259 }
260 }
261--- origsrc/bash-4.4/builtins/shopt.def 2016-05-06 14:00:02.000000000 -0500
262+++ src/bash-4.4/builtins/shopt.def 2017-01-23 13:55:07.992877600 -0600
263@@ -92,6 +92,10 @@ extern int glob_asciirange;
264 extern int lastpipe_opt;
265 extern int inherit_errexit;
266
267+#ifdef __CYGWIN__
268+extern int completion_strip_exe;
269+#endif
270+
271 #if defined (EXTENDED_GLOB)
272 extern int extended_glob;
273 #endif
274@@ -169,6 +173,9 @@ static struct {
275 { "compat41", &shopt_compat41, set_compatibility_level },
276 { "compat42", &shopt_compat42, set_compatibility_level },
277 { "compat43", &shopt_compat43, set_compatibility_level },
278+#ifdef __CYGWIN__
279+ { "completion_strip_exe", &completion_strip_exe, NULL },
280+#endif
281 #if defined (READLINE)
282 { "complete_fullquote", &complete_fullquote, (shopt_set_func_t *)NULL},
283 { "direxpand", &dircomplete_expand, shopt_set_complete_direxpand },
284--- origsrc/bash-4.4/config-top.h 2016-05-19 13:34:02.000000000 -0500
285+++ src/bash-4.4/config-top.h 2017-01-23 13:55:07.992877600 -0600
286@@ -87,10 +87,10 @@
287 #define DEFAULT_BASHRC "~/.bashrc"
288
289 /* System-wide .bashrc file for interactive shells. */
290-/* #define SYS_BASHRC "/etc/bash.bashrc" */
291+#define SYS_BASHRC "/etc/bash.bashrc"
292
293 /* System-wide .bash_logout for login shells. */
294-/* #define SYS_BASH_LOGOUT "/etc/bash.bash_logout" */
295+#define SYS_BASH_LOGOUT "/etc/bash.bash_logout"
296
297 /* Define this to make non-interactive shells begun with argv[0][0] == '-'
298 run the startup files when not in posix mode. */
299@@ -100,7 +100,7 @@
300 sshd and source the .bashrc if so (like the rshd behavior). This checks
301 for the presence of SSH_CLIENT or SSH2_CLIENT in the initial environment,
302 which can be fooled under certain not-uncommon circumstances. */
303-/* #define SSH_SOURCE_BASHRC */
304+#define SSH_SOURCE_BASHRC
305
306 /* Define if you want the case-capitalizing operators (~[~]) and the
307 `capcase' variable attribute (declare -c). */
308--- origsrc/bash-4.4/doc/Makefile.in 2015-12-06 18:55:56.000000000 -0600
309+++ src/bash-4.4/doc/Makefile.in 2017-01-23 13:55:07.992877600 -0600
310@@ -189,7 +189,7 @@ bashref.html: $(BASHREF_FILES) $(HSUSER)
311 $(MAKEINFO) --html --no-split -I$(TEXINPUTDIR) $(srcdir)/bashref.texi
312
313 bash.info: bashref.info
314- ${SHELL} ${INFOPOST} < $(srcdir)/bashref.info > $@ ; \
315+ ${SHELL} ${INFOPOST} < bashref.info > $@ ; \
316
317 bash.txt: bash.1
318 bash.ps: bash.1
319@@ -252,9 +252,9 @@ install: info installdirs
320 -$(INSTALL_DATA) $(srcdir)/bashbug.1 $(DESTDIR)$(man1dir)/bashbug${man1ext}
321 -$(INSTALL_DATA) $(OTHER_DOCS) $(DESTDIR)$(docdir)
322 # uncomment the next lines to install the builtins man page
323-# sed 's:bash\.1:man1/&:' $(srcdir)/builtins.1 > $${TMPDIR:-/var/tmp}/builtins.1
324-# -$(INSTALL_DATA) $${TMPDIR:-/var/tmp}/builtins.1 $(DESTDIR)$(man1dir)/bash_builtins${man1ext}
325-# -$(RM) $${TMPDIR:-/var/tmp}/builtins.1
326+ sed 's:bash\.1:man1/&:' $(srcdir)/builtins.1 > $${TMPDIR:-/var/tmp}/builtins.1
327+ -$(INSTALL_DATA) $${TMPDIR:-/var/tmp}/builtins.1 $(DESTDIR)$(man1dir)/bash_builtins${man1ext}
328+ -$(RM) $${TMPDIR:-/var/tmp}/builtins.1
329 -if test -f bash.info; then d=.; else d=$(srcdir); fi; \
330 $(INSTALL_DATA) $$d/bash.info $(DESTDIR)$(infodir)/bash.info
331 # run install-info if it is present to update the info directory
332--- origsrc/bash-4.4/doc/bash.1 2016-08-26 08:45:17.000000000 -0500
333+++ src/bash-4.4/doc/bash.1 2017-01-23 13:55:08.008447700 -0600
334@@ -9607,6 +9607,10 @@ filenames.
335 This variable is set by default, which is the default bash behavior in
336 versions through 4.2.
337 .TP 8
338+.B completion_strip_exe
339+If set, whenever bash sees \fIfoo.exe\fP during completion, it checks if
340+\fIfoo\fP is the same file and strips the suffix.
341+.TP 8
342 .B direxpand
343 If set,
344 .B bash
345--- origsrc/bash-4.4/doc/bashref.texi 2016-09-07 16:13:36.000000000 -0500
346+++ src/bash-4.4/doc/bashref.texi 2017-01-23 13:55:08.008447700 -0600
347@@ -5123,6 +5123,10 @@ filenames.
348 This variable is set by default, which is the default Bash behavior in
349 versions through 4.2.
350
351+@item completion_strip_exe
352+If set, whenever bash sees @file{foo.exe} during completion, it checks if
353+@file{foo} is the same file and strips the suffix.
354+
355 @item direxpand
356 If set, Bash
357 replaces directory names with the results of word expansion when performing
358--- origsrc/bash-4.4/doc/builtins.1 2012-02-21 13:32:05.000000000 -0600
359+++ src/bash-4.4/doc/builtins.1 2017-01-23 13:55:08.008447700 -0600
360@@ -19,6 +19,6 @@ shift, shopt, source, suspend, test, tim
361 ulimit, umask, unalias, unset, wait \- bash built-in commands, see \fBbash\fR(1)
362 .SH BASH BUILTIN COMMANDS
363 .nr zZ 1
364-.so bash.1
365+.so man1/bash.1
366 .SH SEE ALSO
367 bash(1), sh(1)
368--- origsrc/bash-4.4/general.c 2016-08-11 10:16:56.000000000 -0500
369+++ src/bash-4.4/general.c 2017-01-23 13:55:08.008447700 -0600
370@@ -48,6 +48,10 @@
371
372 #include <tilde/tilde.h>
373
374+#ifdef __CYGWIN__
375+# include <sys/cygwin.h>
376+#endif
377+
378 #if !defined (errno)
379 extern int errno;
380 #endif /* !errno */
381@@ -718,7 +722,8 @@ make_absolute (string, dot_path)
382 {
383 char pathbuf[PATH_MAX + 1];
384
385- cygwin_conv_to_full_posix_path (string, pathbuf);
386+ cygwin_conv_path (CCP_WIN_A_TO_POSIX | CCP_ABSOLUTE, string, pathbuf,
387+ sizeof pathbuf);
388 result = savestring (pathbuf);
389 }
390 #else
391--- origsrc/bash-4.4/input.c 2015-09-24 18:49:23.000000000 -0500
392+++ src/bash-4.4/input.c 2017-01-23 13:55:08.008447700 -0600
393@@ -44,6 +44,10 @@
394 #include "quit.h"
395 #include "trap.h"
396
397+#ifdef __CYGWIN__
398+int igncr;
399+#endif
400+
401 #if !defined (errno)
402 extern int errno;
403 #endif /* !errno */
404@@ -561,6 +565,19 @@ buffered_getchar ()
405 {
406 CHECK_TERMSIG;
407
408+#ifdef __CYGWIN__
409+ /* shopt igncr discards carriage returns from the input stream.
410+ If cr is the only character left in the buffer, recurse to pick
411+ up the next byte; otherwise flatten the buffer. */
412+ if (igncr)
413+ {
414+ int ch;
415+ while ((ch = bufstream_getc (buffers[bash_input.location.buffered_fd]))
416+ == '\r')
417+ ;
418+ return ch;
419+ }
420+#endif
421 #if !defined (DJGPP)
422 return (bufstream_getc (buffers[bash_input.location.buffered_fd]));
423 #else
424--- origsrc/bash-4.4/lib/sh/pathphys.c 2013-05-28 14:33:58.000000000 -0500
425+++ src/bash-4.4/lib/sh/pathphys.c 2017-01-23 13:55:08.008447700 -0600
426@@ -35,6 +35,7 @@
427 #include <stdio.h>
428 #include <chartypes.h>
429 #include <errno.h>
430+#include <stdlib.h>
431
432 #include "shell.h"
433
434@@ -76,6 +77,9 @@ sh_physpath (path, flags)
435 char *path;
436 int flags;
437 {
438+#ifdef __CYGWIN__
439+ return realpath (path, NULL);
440+#endif
441 char tbuf[PATH_MAX+1], linkbuf[PATH_MAX+1];
442 char *result, *p, *q, *qsave, *qbase, *workpath;
443 int double_slash_path, linklen, nlink;
444@@ -214,11 +218,7 @@ error:
445 {
446 q = result;
447 /* Duplicating some code here... */
448-#if defined (__CYGWIN__)
449- qbase = (ISALPHA((unsigned char)workpath[0]) && workpath[1] == ':') ? workpath + 3 : workpath + 1;
450-#else
451 qbase = workpath + 1;
452-#endif
453 double_slash_path = DOUBLE_SLASH (workpath);
454 qbase += double_slash_path;
455
456--- origsrc/bash-4.4/lib/sh/tmpfile.c 2016-08-11 10:05:58.000000000 -0500
457+++ src/bash-4.4/lib/sh/tmpfile.c 2017-01-23 13:55:08.008447700 -0600
458@@ -101,7 +101,7 @@ get_tmpdir (flags)
459 if (tdir && (file_iswdir (tdir) == 0 || strlen (tdir) > PATH_MAX))
460 tdir = 0;
461
462- if (tdir == 0)
463+ if (tdir == 0 || !file_iswdir (tdir))
464 tdir = get_sys_tmpdir ();
465
466 #if defined (HAVE_PATHCONF) && defined (_PC_NAME_MAX)
467--- origsrc/bash-4.4/mksyntax.c 2012-07-29 18:48:38.000000000 -0500
468+++ src/bash-4.4/mksyntax.c 2017-01-23 13:55:08.008447700 -0600
469@@ -29,13 +29,13 @@
470
471 #ifdef HAVE_UNISTD_H
472 # include <unistd.h>
473+#else
474+extern int optind;
475+extern char *optarg;
476 #endif
477
478 #include "syntax.h"
479
480-extern int optind;
481-extern char *optarg;
482-
483 #ifndef errno
484 extern int errno;
485 #endif
486--- origsrc/bash-4.4/parse.y 2016-09-11 10:31:46.000000000 -0500
487+++ src/bash-4.4/parse.y 2017-01-23 13:55:08.008447700 -0600
488@@ -1539,14 +1539,20 @@ yy_string_get ()
489 string = bash_input.location.string;
490
491 /* If the string doesn't exist, or is empty, EOF found. */
492- if (string && *string)
493+ while (string && *string)
494 {
495 c = *string++;
496 bash_input.location.string = string;
497+#ifdef __CYGWIN__
498+ {
499+ extern int igncr;
500+ if (igncr && c == '\r')
501+ continue;
502+ }
503+#endif
504 return (c);
505 }
506- else
507- return (EOF);
508+ return (EOF);
509 }
510
511 static int
512--- origsrc/bash-4.4/subst.c 2017-01-23 13:28:06.955247200 -0600
513+++ src/bash-4.4/subst.c 2017-01-23 13:55:08.008447700 -0600
514@@ -43,6 +43,7 @@
515 #include "posixstat.h"
516 #include "bashintl.h"
517
518+#define NEED_SH_SETLINEBUF_DECL
519 #include "shell.h"
520 #include "parser.h"
521 #include "flags.h"
522@@ -5964,6 +5965,13 @@ read_comsub (fd, quoted, rflag)
523 #endif
524 continue;
525 }
526+#ifdef __CYGWIN__
527+ {
528+ extern int igncr;
529+ if (igncr && c == '\r')
530+ continue;
531+ }
532+#endif
533
534 /* Add the character to ISTRING, possibly after resizing it. */
535 RESIZE_MALLOCED_BUFFER (istring, istring_index, 2, istring_size, DEFAULT_ARRAY_SIZE);
536@@ -6088,6 +6096,28 @@ command_substitute (string, quoted)
537 goto error_exit;
538 }
539
540+#ifdef __CYGWIN__
541+ /* Passing a pipe through std fds can cause hangs when talking to a
542+ non-cygwin child. Move it. */
543+ if (fildes[0] < 3)
544+ {
545+ int fd = fcntl (fildes[0], F_DUPFD, 3);
546+ close (fildes[0]);
547+ fildes[0] = fd;
548+ }
549+ if (fildes[1] < 3)
550+ {
551+ int fd = fcntl (fildes[1], F_DUPFD, 3);
552+ close (fildes[1]);
553+ fildes[1] = fd;
554+ }
555+ if (fildes[0] < 0 || fildes[1] < 0)
556+ {
557+ sys_error (_("cannot make pipe for command substitution"));
558+ goto error_exit;
559+ }
560+#endif /* __CYGWIN__ */
561+
562 old_pid = last_made_pid;
563 #if defined (JOB_CONTROL)
564 old_pipeline_pgrp = pipeline_pgrp;
565--- origsrc/bash-4.4/support/bashversion.c 2008-09-09 08:31:53.000000000 -0500
566+++ src/bash-4.4/support/bashversion.c 2017-01-23 13:55:08.024037200 -0600
567@@ -26,6 +26,9 @@
568
569 #if defined (HAVE_UNISTD_H)
570 # include <unistd.h>
571+#else
572+extern int optind;
573+extern char *optarg;
574 #endif
575
576 #include "bashansi.h"
577@@ -41,9 +44,6 @@
578 #define LFLAG 0x0020
579 #define XFLAG 0x0040
580
581-extern int optind;
582-extern char *optarg;
583-
584 extern char *dist_version;
585 extern int patch_level;
586
587--- origsrc/bash-4.4/support/mkversion.sh 2008-08-13 07:25:57.000000000 -0500
588+++ src/bash-4.4/support/mkversion.sh 2017-01-23 13:55:08.024037200 -0600
589@@ -29,7 +29,7 @@ source_dir="."
590 while [ $# -gt 0 ]; do
591 case "$1" in
592 -o) shift; OUTFILE=$1; shift ;;
593- -b) shift; inc_build=yes ;;
594+ -b) shift; ;; # inc_build=yes ;; # hacked out for cygport
595 -s) shift; rel_status=$1; shift ;;
596 -p) shift; patch_level=$1; shift ;;
597 -d) shift; dist_version=$1; shift ;;
598--- origsrc/bash-4.4/variables.c 2016-06-15 15:05:52.000000000 -0500
599+++ src/bash-4.4/variables.c 2017-01-23 13:55:08.024037200 -0600
600@@ -5239,6 +5239,7 @@ sv_winsize (name)
601 /* Update the value of HOME in the export environment so tilde expansion will
602 work on cygwin. */
603 #if defined (__CYGWIN__)
604+void
605 sv_home (name)
606 char *name;
607 {