From 7cab5883ffd643916d0322a1d3360a79ccf6f653 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 20 Dec 2006 17:37:07 +0100 Subject: 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 Signed-off-by: Junio C Hamano --- xdiff-interface.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'xdiff-interface.c') diff --git a/xdiff-interface.c b/xdiff-interface.c index 08602f5221..6c1f99b149 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -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; +} + + -- cgit v1.2.1