diff src/filepath.c @ 23602:7b3317e959e3 v8.2.2343

patch 8.2.2343: Vim9: return type of readfile() is any Commit: https://github.com/vim/vim/commit/c423ad77ed763c11ba67729bbf63c1cf0915231f Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jan 13 20:38:03 2021 +0100 patch 8.2.2343: Vim9: return type of readfile() is any Problem: Vim9: return type of readfile() is any. Solution: Add readblob() so that readfile() can be expected to always return a list of strings. (closes #7671)
author Bram Moolenaar <Bram@vim.org>
date Wed, 13 Jan 2021 20:45:04 +0100
parents 5f69af863502
children 7d3ee4d508b5
line wrap: on
line diff
--- a/src/filepath.c
+++ b/src/filepath.c
@@ -1640,11 +1640,11 @@ f_readdirex(typval_T *argvars, typval_T 
 /*
  * "readfile()" function
  */
-    void
-f_readfile(typval_T *argvars, typval_T *rettv)
+    static void
+read_file_or_blob(typval_T *argvars, typval_T *rettv, int always_blob)
 {
     int		binary = FALSE;
-    int		blob = FALSE;
+    int		blob = always_blob;
     int		failed = FALSE;
     char_u	*fname;
     FILE	*fd;
@@ -1796,7 +1796,8 @@ f_readfile(typval_T *argvars, typval_T *
 
 			if (dest < buf)
 			{
-			    adjust_prevlen = (int)(buf - dest); // must be 1 or 2
+			    // must be 1 or 2
+			    adjust_prevlen = (int)(buf - dest);
 			    dest = buf;
 			}
 			if (readlen > p - buf + 1)
@@ -1867,6 +1868,24 @@ f_readfile(typval_T *argvars, typval_T *
 }
 
 /*
+ * "readblob()" function
+ */
+    void
+f_readblob(typval_T *argvars, typval_T *rettv)
+{
+    read_file_or_blob(argvars, rettv, TRUE);
+}
+
+/*
+ * "readfile()" function
+ */
+    void
+f_readfile(typval_T *argvars, typval_T *rettv)
+{
+    read_file_or_blob(argvars, rettv, FALSE);
+}
+
+/*
  * "resolve()" function
  */
     void