start with c codegen
[ccc.git] / util.c
diff --git a/util.c b/util.c
index 5103745..a3d8bcf 100644 (file)
--- a/util.c
+++ b/util.c
@@ -204,3 +204,17 @@ void *safe_strdup(const char *c)
                pdie("strdup");
        return res;
 }
+
+FILE *safe_fopen(const char *path, const char *mode)
+{
+       FILE *res = fopen(path, mode);
+       if (res == NULL)
+               pdie("fopen");
+       return res;
+}
+
+void safe_fclose(FILE *file)
+{
+       if (fclose(file) == -1)
+               pdie("fclose");
+}