Normalize code. - sam - An updated version of the sam text editor.
 (HTM) git clone git://vernunftzentrum.de/sam.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit b35dd50b6d5109038206f309278a4759f582e99e
 (DIR) parent 69c9fdc656233873a00c4281143f2b663f78885b
 (HTM) Author: Rob King <jking@deadpixi.com>
       Date:   Tue,  4 Oct 2016 11:14:09 -0500
       
       Normalize code.
       
       Diffstat:
         include/libc.h                      |       5 -----
         sam/io.c                            |      18 +++++++++---------
         sam/mesg.c                          |       2 +-
         sam/sam.c                           |       2 +-
         sam/shell.c                         |      18 +++++++++---------
         sam/sys.c                           |       2 +-
       
       6 files changed, 21 insertions(+), 26 deletions(-)
       ---
 (DIR) diff --git a/include/libc.h b/include/libc.h
       @@ -10,11 +10,6 @@
        #define runetochar(s, r) (wctomb((s), (r)))
        #define runelen(r)       (wctomb(NULL, (r)))
        
       -#define dup(a,b)            dup2(a,b)
       -#define seek(a,b,c)         lseek(a,b,c)
       -#define create(name, mode, perm)    creat(name, perm)
       -#define exec(a,b)           execv(a,b)
       -
        /*
         * new rune routines
         */
 (DIR) diff --git a/sam/io.c b/sam/io.c
       @@ -47,7 +47,7 @@ writef(File *f)
            if(genc)
                free(genc);
            genc = Strtoc(&genstr);
       -    if((io=create(genc, 1, 0666L)) < 0)
       +    if((io=creat(genc, 0666L)) < 0)
                error_s(Ecreate, genc);
            dprint("%s: ", genc);
            if(statfd(io, 0, 0, 0, &length, &appendonly) > 0 && appendonly && length>0)
       @@ -160,8 +160,8 @@ bootterm(char *machine, char **argv, char **end)
            int ph2t[2], pt2h[2];
        
            if(machine){
       -        dup(remotefd0, 0);
       -        dup(remotefd1, 1);
       +        dup2(remotefd0, 0);
       +        dup2(remotefd1, 1);
                close(remotefd0);
                close(remotefd1);
                argv[0] = "samterm";
       @@ -175,8 +175,8 @@ bootterm(char *machine, char **argv, char **end)
                panic("pipe");
            switch(fork()){
            case 0:
       -        dup(ph2t[0], 0);
       -        dup(pt2h[1], 1);
       +        dup2(ph2t[0], 0);
       +        dup2(pt2h[1], 1);
                close(ph2t[0]);
                close(ph2t[1]);
                close(pt2h[0]);
       @@ -190,8 +190,8 @@ bootterm(char *machine, char **argv, char **end)
            case -1:
                panic("can't fork samterm");
            }
       -    dup(pt2h[0], 0);
       -    dup(ph2t[1], 1);
       +    dup2(pt2h[0], 0);
       +    dup2(ph2t[1], 1);
            close(ph2t[0]);
            close(ph2t[1]);
            close(pt2h[0]);
       @@ -211,8 +211,8 @@ connectto(char *machine)
            remotefd1 = p2[1];
            switch(fork()){
            case 0:
       -        dup(p2[0], 0);
       -        dup(p1[1], 1);
       +        dup2(p2[0], 0);
       +        dup2(p1[1], 1);
                close(p1[0]);
                close(p1[1]);
                close(p2[0]);
 (DIR) diff --git a/sam/mesg.c b/sam/mesg.c
       @@ -80,7 +80,7 @@ journal(int out, char *s)
            static int fd = 0;
        
            if(fd <= 0)
       -        fd = create("/tmp/sam.out", 1, 0666L);
       +        fd = creat("/tmp/sam.out", 0666L);
            dprintf(fd, "%s%s\n", out? "out: " : "in:  ", s);
        }
        
 (DIR) diff --git a/sam/sam.c b/sam/sam.c
       @@ -151,7 +151,7 @@ rescue(void)
                    continue;
                if(io == -1){
                    snprintf(buf, sizeof(buf) - 1, "%s/sam.save", home);
       -            io = create(buf, 1, 0700);
       +            io = creat(buf, 0700);
                    if(io<0)
                        return;
                    dprintf(io, "samsave() {\n"
 (DIR) diff --git a/sam/shell.c b/sam/shell.c
       @@ -36,26 +36,26 @@ plan9(File *f, int type, String *s, int nest)
                remove(errfile);
            if((pid=fork()) == 0){
                if(downloaded){ /* also put nasty fd's into errfile */
       -            fd = create(errfile, 1, 0600L);
       +            fd = creat(errfile, 0600L);
                    if(fd < 0)
       -                fd = create("/dev/null", 1, 0600L);
       -            dup(fd, 2);
       +                fd = creat("/dev/null", 0600L);
       +            dup2(fd, 2);
                    close(fd);
                    /* 2 now points at err file */
                    if(type == '>')
       -                dup(2, 1);
       +                dup2(2, 1);
                    else if(type=='!'){
       -                dup(2, 1);
       +                dup2(2, 1);
                        fd = open("/dev/null", 0);
       -                dup(fd, 0);
       +                dup2(fd, 0);
                        close(fd);
                    }
                }
                if(type != '!') {
                    if(type=='<' || type=='|')
       -                dup(pipe1[1], 1);
       +                dup2(pipe1[1], 1);
                    else if(type == '>')
       -                dup(pipe1[0], 0);
       +                dup2(pipe1[0], 0);
                    close(pipe1[0]);
                    close(pipe1[1]);
                }
       @@ -87,7 +87,7 @@ plan9(File *f, int type, String *s, int nest)
                        fprintf(stderr, "Can't fork?!\n");
                        exit(EXIT_FAILURE);
                    }
       -            dup(pipe2[0], 0);
       +            dup2(pipe2[0], 0);
                    close(pipe2[0]);
                    close(pipe2[1]);
                }
 (DIR) diff --git a/sam/sys.c b/sam/sys.c
       @@ -62,6 +62,6 @@ Write(int f, void *a, int n)
        void
        Seek(int f, int64_t n, int w)
        {
       -    if(seek(f, n, w)==-1)
       +    if(lseek(f, n, w)==-1)
                syserror("seek");
        }