aboutsummaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/utils.c b/utils.c
index 5976f74..bf0c148 100644
--- a/utils.c
+++ b/utils.c
@@ -95,3 +95,41 @@ out_free:
free(rpath);
return ret;
}
+
+int file_open(FILE **fp, const char *path, const char *name, const char *format)
+{
+ int ret;
+ char *rpath;
+
+ ret = asprintf(&rpath, "%s/%s", path, name);
+ if (ret < 0)
+ return ret;
+
+ ret = 0;
+ *fp = fopen(rpath, format);
+ if (!(*fp))
+ ret = -1;
+
+ free(rpath);
+ return ret;
+}
+
+int file_read_line(FILE **fp, char *line, int size)
+{
+ if (!(*fp))
+ return -1;
+
+ if (fgets(line, size, *fp) != NULL)
+ return 0;
+ else
+ return -1;
+}
+
+int file_close(FILE **fp)
+{
+ if (!(*fp))
+ return -1;
+
+ fclose(*fp);
+ return 0;
+}