Add and use a common readfile() function

This function is used to read the full content of a textfile into a
newly allocated buffer (with zerotermination).

It replaces the earlier readfile() in scan-tree.c (which was rather
error-prone[1]), and is reused by read_agefile() in ui-repolist.c.

1: No checks for EINTR and EAGAIN, fixed-size buffer

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
diff --git a/cgit.h b/cgit.h
index d90ccdc..adb8da4 100644
--- a/cgit.h
+++ b/cgit.h
@@ -283,5 +283,6 @@
 extern int cgit_open_filter(struct cgit_filter *filter);
 extern int cgit_close_filter(struct cgit_filter *filter);
 
+extern int readfile(const char *path, char **buf, size_t *size);
 
 #endif /* CGIT_H */