ed

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

util.c (366B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <string.h>
      4 
      5 char *
      6 drain_file(FILE *f) {
      7 	char *contents;
      8 	int len;
      9 
     10 	fseek(f, 0, SEEK_END);
     11 	len = ftell(f);
     12 	rewind(f);
     13 
     14 	contents = malloc(len + 1);
     15 	contents[len] = 0;
     16 
     17 	fread(contents, 1, len, f);
     18 	return contents;
     19 }
     20 
     21 void *
     22 zmalloc(size_t size) {
     23 	void *ptr = malloc(size);
     24 	memset(ptr, 0, size);
     25 	return ptr;
     26 }