From 6ec83568b5ac5684200a0466831c1717318cbe7a Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Sat, 25 Jun 2016 00:31:46 -0700 Subject: Check for "Windows-3.4.0" as per MS's suggestion. https://github.com/Microsoft/BashOnWindows/issues/545 Just looking for "Mirosoft" is rather general - we don't want to enforce this strange behavior for Windows 12 (or the next beta.) --- src/fish.cpp | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/fish.cpp b/src/fish.cpp index 12688cee..b50a79b7 100644 --- a/src/fish.cpp +++ b/src/fish.cpp @@ -410,29 +410,23 @@ static int fish_parse_opt(int argc, char **argv, std::vector *cmds) /// routines. static void misc_init() { #ifdef OS_IS_CYGWIN - // MS Windows tty devices do not have either a read or write timestamp. Those respective fields + if (cmdfile) fclose(cmdfile) + // MS Windows tty devices do not currently have either a read or write timestamp. Those respective fields // of `struct stat` are always the current time. Which means we can't use them. So we assume no // external program has written to the terminal behind our back. This makes multiline prompts - // usable. See issue #2859. + // usable. See issue #2859 and https://github.com/Microsoft/BashOnWindows/issues/545 has_working_tty_timestamps = false; #else - // This covers Windows Subsystem for Linux (WSL). - int fd = open("/proc/sys/kernel/osrelease", O_RDONLY); - if (fd != -1) { - const char *magic_suffix = "Microsoft"; - int len_magic_suffix = strlen(magic_suffix); - char osrelease[128] = {0}; - int len_osrelease = read(fd, osrelease, sizeof(osrelease) - 1); - if (osrelease[len_osrelease - 1] == '\n') { - osrelease[len_osrelease - 1] = '\0'; - len_osrelease--; - } - if (len_osrelease >= len_magic_suffix && - strcmp(magic_suffix, osrelease + len_osrelease - len_magic_suffix) == 0) { + // This covers preview builds of Windows Subsystem for Linux (WSL). + FILE *procsyskosrel; + if ((procsyskosrel = wfopen(L"/proc/sys/kernel/osrelease", "r"))) { + wcstring osrelease; + fgetws2(&osrelease, procsyskosrel); + if (osrelease.find(L"3.4.0-Microsoft") != wcstring::npos) { has_working_tty_timestamps = false; } - close(fd); } + if (procsyskosrel) { fclose(procsyskosrel); } #endif // OS_IS_MS_WINDOWS } -- cgit v1.2.3