patch 9.1.1139: [fifo] is not displayed when editing a fifo

Problem:  [fifo] is not displayed when editing a fifo
          (after v7.4.2189)
Solution: stat the filename and detect the type correctly

fixes: #16702
closes: #16705

Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/buffer.c b/src/buffer.c
index a925552..68388db 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -275,6 +275,8 @@
 	{
 	    curbuf->b_p_bin = save_bin;
 	    if (retval == OK)
+		// don't add READ_FIFO here, otherwise we won't be able to
+		// detect the encoding
 		retval = read_buffer(FALSE, eap, flags);
 	}
 #endif
diff --git a/src/fileio.c b/src/fileio.c
index a2031e9..24a01a0 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -366,15 +366,18 @@
 	    goto theend;
 	}
     }
-
-    if (!read_stdin && !read_buffer && !read_fifo)
-    {
 #if defined(UNIX) || defined(VMS)
+    if (!read_stdin && fname != NULL)
 	/*
 	 * On Unix it is possible to read a directory, so we have to
 	 * check for it before the mch_open().
 	 */
 	perm = mch_getperm(fname);
+#endif
+
+    if (!read_stdin && !read_buffer && !read_fifo)
+    {
+#if defined(UNIX) || defined(VMS)
 	if (perm >= 0 && !S_ISREG(perm)		    // not a regular file ...
 		      && !S_ISFIFO(perm)	    // ... or fifo
 		      && !S_ISSOCK(perm)	    // ... or socket
diff --git a/src/testdir/test_startup_utf8.vim b/src/testdir/test_startup_utf8.vim
index e8b99e7..9377667 100644
--- a/src/testdir/test_startup_utf8.vim
+++ b/src/testdir/test_startup_utf8.vim
@@ -60,6 +60,33 @@
   call delete('Xtestout')
 endfunc
 
+func Test_detect_fifo()
+  CheckUnix
+  " Using bash/zsh's process substitution.
+  if executable('bash')
+    set shell=bash
+  elseif executable('zsh')
+    set shell=zsh
+  else
+    throw 'Skipped: bash or zsh is required'
+  endif
+  let linesin = ['one', 'two']
+  call writefile(linesin, 'Xtestin_fifo', 'D')
+  let after = [
+	\ 'call writefile(split(execute(":mess"), "\\n"), "Xtestout")',
+	\ 'quit!',
+	\ ]
+  if RunVim([], after, '<(cat Xtestin_fifo)')
+    let lines = readfile('Xtestout')
+    call assert_match('\[fifo\]', lines[0])
+    call assert_match('\[fifo\]', lines[1])
+  else
+    call assert_equal('', 'RunVim failed.')
+  endif
+
+  call delete('Xtestout')
+endfunc
+
 func Test_detect_ambiwidth()
   CheckRunVimInTerminal
 
diff --git a/src/version.c b/src/version.c
index 87ed059..fe6ebd2 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1139,
+/**/
     1138,
 /**/
     1137,