On 2011/3/26 18:38, H Xu wrote:
On 2011/3/26 15:48, H Xu wrote:
Hello,

To reproduce:
:!echo -n 'Hello' >temp.txt
:echo readfile('temp.txt')

Then an empty list is displayed rather than the content of this file.

The attached patch fixes this problem.


Hello,

The last patch has some problem. Use this patch instead.

The solution is, when readfile() in text mode, if we reach the end of
the file and we still didn't find a NL, then add an NL to the end of the
buffer.

Sorry still send the wrong patch. The attached patch is the correct one.

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff -r 719ff65f993e src/eval.c
--- a/src/eval.c        Tue Mar 22 20:54:25 2011 +0100
+++ b/src/eval.c        Sat Mar 26 18:40:49 2011 +0800
@@ -14237,7 +14237,7 @@
     FILE       *fd;
     listitem_T *li;
 #define FREAD_SIZE 200     /* optimized for text lines */
-    char_u     buf[FREAD_SIZE];
+    char_u     buf[FREAD_SIZE + 1];
     int                readlen;    /* size of last fread() */
     int                buflen;     /* nr of valid chars in buf[] */
     int                filtd;      /* how much in buf[] was NUL -> '\n' 
filtered */
@@ -14249,6 +14249,7 @@
     int                len;
     long       maxline = MAXLNUM;
     long       cnt = 0;
+    int                havenl = 0; /* does the file contain an nl */ 
 
     if (argvars[1].v_type != VAR_UNKNOWN)
     {
@@ -14276,10 +14277,20 @@
        readlen = (int)fread(buf + filtd, 1, FREAD_SIZE - filtd, fd);
        buflen = filtd + readlen;
        tolist = 0;
+
+       if (readlen <= 0 && !havenl && !binary)
+       {
+           buf[buflen] = '\n';
+           ++buflen;
+           ++readlen;
+       }
+
        for ( ; filtd < buflen || readlen <= 0; ++filtd)
        {
            if (buf[filtd] == '\n' || readlen <= 0)
            {
+               havenl = 1;
+
                /* Only when in binary mode add an empty list item when the
                 * last line ends in a '\n'. */
                if (!binary && readlen == 0 && filtd == 0)

Reply via email to