]> git.sesse.net Git - movit/blobdiff - util.cpp
Move slurping of files into its own function.
[movit] / util.cpp
index 592e4d56b47f842a6bb6493e634992bb9cfe0ec5..b427625219964924db9a88a4f9336523abee7ac8 100644 (file)
--- a/util.cpp
+++ b/util.cpp
@@ -42,3 +42,18 @@ void hsv2rgb(float h, float s, float v, float *r, float *g, float *b)
        *g += m;
        *b += m;
 }
+
+std::string read_file(const std::string &filename)
+{
+       static char buf[131072];
+       FILE *fp = fopen(filename.c_str(), "r");
+       if (fp == NULL) {
+               perror(filename.c_str());
+               exit(1);
+       }
+
+       int len = fread(buf, 1, sizeof(buf), fp);
+       fclose(fp);
+
+       return std::string(buf, len);
+}