PageRenderTime 82ms CodeModel.GetById 78ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/test_util.c

http://ftk.googlecode.com/
C | 22 lines | 20 code | 2 blank | 0 comment | 1 complexity | 887531f2bd7ac744d0225bfc70546f8e MD5 | raw file
 1#include <stdio.h>
 2
 3char* read_file(const char* file_name, int* length)
 4{
 5	struct stat st = {0};
 6	if(stat(file_name, &st))
 7	{
 8		return NULL;
 9	}
10	else
11	{
12		char* buffer = malloc(st.st_size + 1);
13		FILE* fp = fopen(file_name, "rb");
14		int fread_ret = 0;
15		fread_ret = fread(buffer, 1, st.st_size, fp);
16		fclose(fp);
17		buffer[st.st_size] = '\0';
18		*length = st.st_size;
19
20		return buffer;
21	}
22}