scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

_allocbuf.c (303B)


      1 #include <errno.h>
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 #include "../libc.h"
      5 
      6 int
      7 _allocbuf(FILE *fp)
      8 {
      9 	char *bp;
     10 
     11 	if ((bp = malloc(BUFSIZ)) == NULL) {
     12 		fp->flags |= _IOERR;
     13 		errno = ENOMEM;
     14 		return EOF;
     15 	}
     16 	fp->len = BUFSIZ;
     17 	fp->rp = fp->wp = fp->buf = bp;
     18 	fp->lp = bp + BUFSIZ;
     19 
     20 	return 0;
     21 }