comparison 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
comparison
equal deleted inserted replaced
23601:3b600f015796 23602:7b3317e959e3
1638 } 1638 }
1639 1639
1640 /* 1640 /*
1641 * "readfile()" function 1641 * "readfile()" function
1642 */ 1642 */
1643 void 1643 static void
1644 f_readfile(typval_T *argvars, typval_T *rettv) 1644 read_file_or_blob(typval_T *argvars, typval_T *rettv, int always_blob)
1645 { 1645 {
1646 int binary = FALSE; 1646 int binary = FALSE;
1647 int blob = FALSE; 1647 int blob = always_blob;
1648 int failed = FALSE; 1648 int failed = FALSE;
1649 char_u *fname; 1649 char_u *fname;
1650 FILE *fd; 1650 FILE *fd;
1651 char_u buf[(IOSIZE/256)*256]; // rounded to avoid odd + 1 1651 char_u buf[(IOSIZE/256)*256]; // rounded to avoid odd + 1
1652 int io_size = sizeof(buf); 1652 int io_size = sizeof(buf);
1794 // have to shuffle buf to close gap 1794 // have to shuffle buf to close gap
1795 int adjust_prevlen = 0; 1795 int adjust_prevlen = 0;
1796 1796
1797 if (dest < buf) 1797 if (dest < buf)
1798 { 1798 {
1799 adjust_prevlen = (int)(buf - dest); // must be 1 or 2 1799 // must be 1 or 2
1800 adjust_prevlen = (int)(buf - dest);
1800 dest = buf; 1801 dest = buf;
1801 } 1802 }
1802 if (readlen > p - buf + 1) 1803 if (readlen > p - buf + 1)
1803 mch_memmove(dest, p + 1, readlen - (p - buf) - 1); 1804 mch_memmove(dest, p + 1, readlen - (p - buf) - 1);
1804 readlen -= 3 - adjust_prevlen; 1805 readlen -= 3 - adjust_prevlen;
1862 rettv_list_alloc(rettv); 1863 rettv_list_alloc(rettv);
1863 } 1864 }
1864 1865
1865 vim_free(prev); 1866 vim_free(prev);
1866 fclose(fd); 1867 fclose(fd);
1868 }
1869
1870 /*
1871 * "readblob()" function
1872 */
1873 void
1874 f_readblob(typval_T *argvars, typval_T *rettv)
1875 {
1876 read_file_or_blob(argvars, rettv, TRUE);
1877 }
1878
1879 /*
1880 * "readfile()" function
1881 */
1882 void
1883 f_readfile(typval_T *argvars, typval_T *rettv)
1884 {
1885 read_file_or_blob(argvars, rettv, FALSE);
1867 } 1886 }
1868 1887
1869 /* 1888 /*
1870 * "resolve()" function 1889 * "resolve()" function
1871 */ 1890 */