move read_mmfile() into xdiff-interface

read_file() was a useful function if you want to work with the xdiff stuff,
so it was renamed and put into a more central place.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Johannes Schindelin
2006-12-20 17:37:07 +01:00
committed by Junio C Hamano
parent fa39b6b5b1
commit 7cab5883ff
3 changed files with 22 additions and 18 deletions

View File

@ -102,3 +102,22 @@ int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf)
}
return 0;
}
int read_mmfile(mmfile_t *ptr, const char *filename)
{
struct stat st;
FILE *f;
if (stat(filename, &st))
return error("Could not stat %s", filename);
if ((f = fopen(filename, "rb")) == NULL)
return error("Could not open %s", filename);
ptr->ptr = xmalloc(st.st_size);
if (fread(ptr->ptr, st.st_size, 1, f) != 1)
return error("Could not read %s", filename);
fclose(f);
ptr->size = st.st_size;
return 0;
}