X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=xdiff-interface.c;h=10816e95a07c23dda7554c102c306d7e9beca606;hb=93d496a560cdcd4f72c8dee1b0b2efa324e1c3bb;hp=08602f522183dc43787616f37cba9b8af4e3dade;hpb=7f0f4fa4374edfe2050b3ab636f43ee80daa63f2;p=thirdparty%2Fgit.git diff --git a/xdiff-interface.c b/xdiff-interface.c index 08602f5221..10816e95a0 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -102,3 +102,24 @@ 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; + size_t sz; + + if (stat(filename, &st)) + return error("Could not stat %s", filename); + if ((f = fopen(filename, "rb")) == NULL) + return error("Could not open %s", filename); + sz = xsize_t(st.st_size); + ptr->ptr = xmalloc(sz); + if (fread(ptr->ptr, sz, 1, f) != 1) + return error("Could not read %s", filename); + fclose(f); + ptr->size = sz; + return 0; +} + +