summaryrefslogtreecommitdiff
path: root/lib/fstree
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-11-01 13:06:47 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-03-30 22:31:30 +0200
commitdba5a02426d942fa5a1a8be83a9f198a5f413d4b (patch)
tree31249e1196c8b43f4a84036b550d20b399b9dd8e /lib/fstree
parent2b84065a0f82e71e3f82fcd3148daa29f35a6597 (diff)
Add a rudimentary unit test for sort files
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/fstree')
-rw-r--r--lib/fstree/fstree_from_file.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/fstree/fstree_from_file.c b/lib/fstree/fstree_from_file.c
index d2f0b4a..e77f19a 100644
--- a/lib/fstree/fstree_from_file.c
+++ b/lib/fstree/fstree_from_file.c
@@ -540,16 +540,14 @@ out_desc:
return -1;
}
-int fstree_from_file(fstree_t *fs, const char *filename, const char *basepath)
+int fstree_from_file_stream(fstree_t *fs, istream_t *fp, const char *basepath)
{
+ const char *filename;
size_t line_num = 1;
- istream_t *fp;
char *line;
int ret;
- fp = istream_open_file(filename);
- if (fp == NULL)
- return -1;
+ filename = istream_get_filename(fp);
for (;;) {
ret = istream_get_line(fp, &line, &line_num,
@@ -570,10 +568,23 @@ int fstree_from_file(fstree_t *fs, const char *filename, const char *basepath)
++line_num;
}
- sqfs_destroy(fp);
return 0;
fail_line:
free(line);
- sqfs_destroy(fp);
return -1;
}
+
+int fstree_from_file(fstree_t *fs, const char *filename, const char *basepath)
+{
+ istream_t *fp;
+ int ret;
+
+ fp = istream_open_file(filename);
+ if (fp == NULL)
+ return -1;
+
+ ret = fstree_from_file_stream(fs, fp, basepath);
+
+ sqfs_destroy(fp);
+ return ret;
+}