[BusyBox 0005124]: vi in busybox always writes files with length 0

bugs at busybox.net bugs at busybox.net
Thu Sep 25 02:20:56 UTC 2008


A NOTE has been added to this issue. 
====================================================================== 
http://busybox.net/bugs/view.php?id=5124 
====================================================================== 
Reported By:                DanLiang
Assigned To:                BusyBox
====================================================================== 
Project:                    BusyBox
Issue ID:                   5124
Category:                   Documentation
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     assigned
====================================================================== 
Date Submitted:             09-23-2008 20:43 PDT
Last Modified:              09-24-2008 19:20 PDT
====================================================================== 
Summary:                    vi in busybox always writes files with length 0
Description: 
I use buildroot to create a rootfs and test it.

My configuration is
uclibc-0.9.29
gcc-4.2.4
busybox-1.12.0

When I try to modify a existing file or create a new one with vi, after I
save the contents and exit from vi, the file length is always 0 and all
the contents are lost.

In file vi.c, I find if I comment out the line "ftruncate(fd, charcnt);"
in function "static int file_write(char *fn, char *first, char *last)",
everything is OK.
====================================================================== 

---------------------------------------------------------------------- 
 vda - 09-24-08 04:14  
---------------------------------------------------------------------- 
Please add this debugging code:

        charcnt = full_write(fd, first, cnt);
bb_error_msg("file_write: cnt:%d charcnt:%d", cnt, charcnt);
sleep(5);
        ftruncate(fd, charcnt);

and let me know what do you see when you try to save a file. 

---------------------------------------------------------------------- 
 DanLiang - 09-24-08 19:20  
---------------------------------------------------------------------- 
Hi vda

when I try to save a file, a message is printed out like this:
vi: file_write: cnt:10 charcnt:10. 
Variable 'cnt' always has the same value with 'charcnt'.
which means no matter what value I pass to ftruncate(), it will truncate
the file length to 0.

But it's very strange when I wrote a small program:
---------------------------------------------------
#include <unistd.h>
#include <fcntl.h>

int main()
{
        char buf[] = "test";
        int fd, cnt, charcnt;

        fd = open("test.txt", (O_RDWR | O_CREAT), 0666);
        if (fd < 0)
                return -1;
        cnt = sizeof(buf);
        buf[cnt-1] = 0x0A;
        charcnt = write(fd, buf, cnt);
        ftruncate(fd, charcnt);
        if (charcnt == cnt) {
        // good write
        //file_modified = FALSE;
        } else {
                charcnt = 0;
        }
        close(fd);
        return charcnt;
}
---------------------------------------------------
I tested it on my ARM board, and it's ok with string "test" in that file. 

Issue History 
Date Modified   Username       Field                    Change               
====================================================================== 
09-23-08 20:43  DanLiang       New Issue                                    
09-23-08 20:43  DanLiang       Status                   new => assigned     
09-23-08 20:43  DanLiang       Assigned To               => BusyBox         
09-24-08 01:14  DanLiang       Issue Monitored: DanLiang                    
09-24-08 04:14  vda            Note Added: 0011854                          
09-24-08 19:20  DanLiang       Note Added: 0011934                          
======================================================================




More information about the busybox-cvs mailing list