File: util.c

package info (click to toggle)
mpage 2.5.6-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 528 kB
  • ctags: 332
  • sloc: ansic: 3,630; makefile: 85; sh: 69
file content (33 lines) | stat: -rw-r--r-- 521 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
 * 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;
}