Plan 9 from Bell Labs’s /usr/web/sources/contrib/fgb/root/sys/src/cmd/aux/mpage/util.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


/*
 * Utility functions for memory management.  Very primitive.
 * ema@csn.es
 */

static char *pos;
static int maxsize;

#define NULL (void *)0

void memgets_init(memarea, size)
 char *memarea;
 int size;
{
    pos = memarea;
    maxsize = size;
}



char *memgets(output, maxitems)
 char *output;
 int maxitems;
{
    char *retval = output;
    while (maxitems-- &&  maxsize-- >=0 && (*output++=*pos++) != '\n' )
      ;
    *output = '\0';
    if (maxsize >= 0) 
        return retval;
    else
        return NULL;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.