X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=xdiff-interface.c;h=e407cf11b1d8ba28be64eda7bcb505d9edb4d253;hb=967506bbbdc38e75263d6e6a90e3b8dbba6cec0f;hp=6c1f99b149f0800a9c9ab1b45033bc1401a84766;hpb=9def2138a17325c68961c3b1e6c967d33f28a4f1;p=git.git diff --git a/xdiff-interface.c b/xdiff-interface.c index 6c1f99b14..e407cf11b 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -107,17 +107,25 @@ 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); - ptr->ptr = xmalloc(st.st_size); - if (fread(ptr->ptr, st.st_size, 1, f) != 1) + 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 = st.st_size; + ptr->size = sz; return 0; } - +#define FIRST_FEW_BYTES 8000 +int buffer_is_binary(const char *ptr, unsigned long size) +{ + if (FIRST_FEW_BYTES < size) + size = FIRST_FEW_BYTES; + return !!memchr(ptr, 0, size); +}