tex: fail when overwriting files unless with a bang - neatvi - [fork] simple vi-type editor with UTF-8 support
 (HTM) git clone git://src.adamsgaard.dk/neatvi
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit 2e55bac697aba82a162cd461a6112c82c7eaf871
 (DIR) parent d2e6b8054daf567c687f0cb4b526b4a6f439d7d5
 (HTM) Author: Ali Gholami Rudi <ali@rudi.ir>
       Date:   Mon,  6 Jun 2016 23:43:47 +0430
       
       ex: fail when overwriting files unless with a bang
       
       Diffstat:
         M ex.c                                |       8 ++++++--
       
       1 file changed, 6 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/ex.c b/ex.c
       t@@ -472,12 +472,16 @@ static int ec_write(char *ec)
                        if (!strchr(cmd, '!') && bufs[0].path &&
                                        !strcmp(bufs[0].path, path) &&
                                        mtime(bufs[0].path) > bufs[0].mtime) {
       -                        ex_show("write failed\n");
       +                        ex_show("write failed: file changed\n");
       +                        return 1;
       +                }
       +                if (!strchr(cmd, '!') && arg[0] && mtime(arg) >= 0) {
       +                        ex_show("write failed: file exists\n");
                                return 1;
                        }
                        fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0600);
                        if (fd < 0) {
       -                        ex_show("write failed\n");
       +                        ex_show("write failed: cannot create file\n");
                                return 1;
                        }
                        if (lbuf_wr(xb, fd, beg, end)) {