replaced sbrk() uses with malloc() - 9base - revived minimalist port of Plan 9 userland to Unix
 (HTM) git clone git://git.suckless.org/9base
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 09e95a2d6f8dbafc6601147b2f5f150355813be6
 (DIR) parent bdca47727a2618c3cbb85a43fadcf9298ebec424
 (HTM) Author: Anselm R Garbe <anselm@garbe.us>
       Date:   Sun,  6 Aug 2017 09:30:30 +0200
       
       replaced sbrk() uses with malloc()
       
       Diffstat:
         M dd/dd.c                             |       7 +++----
         M grep/sub.c                          |      17 ++++++++++-------
         M lib9/libc.h                         |       1 -
       
       3 files changed, 13 insertions(+), 12 deletions(-)
       ---
 (DIR) diff --git a/dd/dd.c b/dd/dd.c
       @@ -203,13 +203,12 @@ main(int argc, char *argv[])
                        fprint(2, "dd: counts: cannot be zero\n");
                        exits("counts");
                }
       -        ibuf = sbrk(ibs);
       +        ibuf = malloc(ibs);
                if(fflag)
                        obuf = ibuf;
                else
       -                obuf = sbrk(obs);
       -        sbrk(64);        /* For good measure */
       -        if(ibuf == (char *)-1 || obuf == (char *)-1) {
       +                obuf = malloc(obs);
       +        if(ibuf == NULL || obuf == NULL) {
                        fprint(2, "dd: not enough memory: %r\n");
                        exits("memory");
                }
 (DIR) diff --git a/grep/sub.c b/grep/sub.c
       @@ -3,24 +3,27 @@
        void*
        mal(int n)
        {
       -        static char *s;
       +        static char *s = NULL;
                static int m = 0;
       -        void *v;
       +        void *v = NULL;
        
                n = (n+3) & ~3;
                if(m < n) {
                        if(n > Nhunk) {
       -                        v = sbrk(n);
       -                        memset(v, 0, n);
       +                        v = malloc(n);
       +                        if(v != NULL)
       +                                memset(v, 0, n);
                                return v;
                        }
       -                s = sbrk(Nhunk);
       +                s = malloc(Nhunk);
                        m = Nhunk;
                }
                v = s;
       -        s += n;
       +        if(s != NULL)
       +                s += n;
                m -= n;
       -        memset(v, 0, n);
       +        if(v != NULL)
       +                memset(v, 0, n);
                return v;
        }
        
 (DIR) diff --git a/lib9/libc.h b/lib9/libc.h
       @@ -782,7 +782,6 @@ extern        long        read(int, void*, long);
        extern        long        readn(int, void*, long);
        /* extern        long        readv(int, IOchunk*, int); <unistd.h> */
        extern        int        remove(const char*);
       -/* extern        void*        sbrk(ulong); <unistd.h> */
        /* extern        long        oseek(int, long, int); */
        extern        vlong        p9seek(int, vlong, int);
        /* give up