aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/io/src/std.c2
-rw-r--r--lib/sqfs/src/unix/istream.c23
-rw-r--r--lib/sqfs/src/unix/ostream.c8
-rw-r--r--lib/sqfs/src/win32/istream.c23
-rw-r--r--lib/sqfs/src/win32/ostream.c17
-rw-r--r--lib/tar/test/tar_big_file.c3
-rw-r--r--lib/tar/test/tar_fuzz.c2
-rw-r--r--lib/tar/test/tar_iterator.c6
-rw-r--r--lib/tar/test/tar_iterator2.c3
-rw-r--r--lib/tar/test/tar_iterator3.c3
-rw-r--r--lib/tar/test/tar_simple.c3
-rw-r--r--lib/tar/test/tar_sparse.c2
-rw-r--r--lib/tar/test/tar_sparse_gnu.c2
-rw-r--r--lib/tar/test/tar_target_filled.c3
-rw-r--r--lib/tar/test/tar_write_simple.c3
-rw-r--r--lib/tar/test/tar_xattr.c3
-rw-r--r--lib/tar/test/tar_xattr_bin.c3
-rw-r--r--lib/util/test/str_table.c2
18 files changed, 78 insertions, 33 deletions
diff --git a/lib/io/src/std.c b/lib/io/src/std.c
index c52b4c5..62635ec 100644
--- a/lib/io/src/std.c
+++ b/lib/io/src/std.c
@@ -23,7 +23,7 @@ int istream_open_stdin(sqfs_istream_t **out)
{
sqfs_file_handle_t hnd = GetStdHandle(STD_INPUT_HANDLE);
- return sqfs_istream_open_handle(out, "stdin", hnd);
+ return sqfs_istream_open_handle(out, "stdin", hnd, 0);
}
int ostream_open_stdout(sqfs_ostream_t **out)
diff --git a/lib/sqfs/src/unix/istream.c b/lib/sqfs/src/unix/istream.c
index fd2f120..a0a3469 100644
--- a/lib/sqfs/src/unix/istream.c
+++ b/lib/sqfs/src/unix/istream.c
@@ -113,11 +113,16 @@ static void file_destroy(sqfs_object_t *obj)
}
int sqfs_istream_open_handle(sqfs_istream_t **out, const char *path,
- sqfs_file_handle_t fd)
+ sqfs_file_handle_t fd, sqfs_u32 flags)
{
- file_istream_t *file = calloc(1, sizeof(*file));
- sqfs_istream_t *strm = (sqfs_istream_t *)file;
+ file_istream_t *file;
+ sqfs_istream_t *strm;
+ if (flags & ~(SQFS_FILE_OPEN_ALL_FLAGS))
+ return SQFS_ERROR_UNSUPPORTED;
+
+ file = calloc(1, sizeof(*file));
+ strm = (sqfs_istream_t *)file;
if (file == NULL)
return SQFS_ERROR_ALLOC;
@@ -149,16 +154,22 @@ int sqfs_istream_open_handle(sqfs_istream_t **out, const char *path,
return 0;
}
-int sqfs_istream_open_file(sqfs_istream_t **out, const char *path)
+int sqfs_istream_open_file(sqfs_istream_t **out, const char *path,
+ sqfs_u32 flags)
{
sqfs_file_handle_t fd;
int ret;
- ret = sqfs_open_native_file(&fd, path, SQFS_FILE_OPEN_READ_ONLY);
+ flags |= SQFS_FILE_OPEN_READ_ONLY;
+
+ if (flags & (SQFS_FILE_OPEN_OVERWRITE | SQFS_FILE_OPEN_NO_SPARSE))
+ return SQFS_ERROR_ARG_INVALID;
+
+ ret = sqfs_open_native_file(&fd, path, flags);
if (ret)
return ret;
- ret = sqfs_istream_open_handle(out, path, fd);
+ ret = sqfs_istream_open_handle(out, path, fd, flags);
if (ret != 0) {
int temp = errno;
close(fd);
diff --git a/lib/sqfs/src/unix/ostream.c b/lib/sqfs/src/unix/ostream.c
index 89982c1..efdc3cd 100644
--- a/lib/sqfs/src/unix/ostream.c
+++ b/lib/sqfs/src/unix/ostream.c
@@ -144,7 +144,7 @@ static const char *file_get_filename(sqfs_ostream_t *strm)
}
int sqfs_ostream_open_handle(sqfs_ostream_t **out, const char *path,
- sqfs_file_handle_t fd, int flags)
+ sqfs_file_handle_t fd, sqfs_u32 flags)
{
file_ostream_t *file = calloc(1, sizeof(*file));
sqfs_ostream_t *strm = (sqfs_ostream_t *)file;
@@ -183,12 +183,16 @@ int sqfs_ostream_open_handle(sqfs_ostream_t **out, const char *path,
return 0;
}
-int sqfs_ostream_open_file(sqfs_ostream_t **out, const char *path, int flags)
+int sqfs_ostream_open_file(sqfs_ostream_t **out, const char *path,
+ sqfs_u32 flags)
{
sqfs_file_handle_t fd;
int ret;
*out = NULL;
+ if (flags & SQFS_FILE_OPEN_READ_ONLY)
+ return SQFS_ERROR_ARG_INVALID;
+
ret = sqfs_open_native_file(&fd, path, flags);
if (ret)
return ret;
diff --git a/lib/sqfs/src/win32/istream.c b/lib/sqfs/src/win32/istream.c
index ba44c0b..3f7eb83 100644
--- a/lib/sqfs/src/win32/istream.c
+++ b/lib/sqfs/src/win32/istream.c
@@ -118,12 +118,17 @@ static void file_destroy(sqfs_object_t *obj)
}
int sqfs_istream_open_handle(sqfs_istream_t **out, const char *path,
- sqfs_file_handle_t hnd)
+ sqfs_file_handle_t hnd, sqfs_u32 flags)
{
- file_istream_t *file = calloc(1, sizeof(*file));
- sqfs_istream_t *strm = (sqfs_istream_t *)file;
+ file_istream_t *file;
+ sqfs_istream_t *strm;
BOOL ret;
+ if (flags & ~(SQFS_FILE_OPEN_ALL_FLAGS))
+ return SQFS_ERROR_UNSUPPORTED;
+
+ file = calloc(1, sizeof(*file));
+ strm = (sqfs_istream_t *)file;
if (file == NULL)
return SQFS_ERROR_ALLOC;
@@ -158,16 +163,22 @@ int sqfs_istream_open_handle(sqfs_istream_t **out, const char *path,
return 0;
}
-int sqfs_istream_open_file(sqfs_istream_t **out, const char *path)
+int sqfs_istream_open_file(sqfs_istream_t **out, const char *path,
+ sqfs_u32 flags)
{
sqfs_file_handle_t hnd;
int ret;
- ret = sqfs_open_native_file(&hnd, path, SQFS_FILE_OPEN_READ_ONLY);
+ flags |= SQFS_FILE_OPEN_READ_ONLY;
+
+ if (flags & (SQFS_FILE_OPEN_OVERWRITE | SQFS_FILE_OPEN_NO_SPARSE))
+ return SQFS_ERROR_ARG_INVALID;
+
+ ret = sqfs_open_native_file(&hnd, path, flags);
if (ret)
return ret;
- ret = sqfs_istream_open_handle(out, path, hnd);
+ ret = sqfs_istream_open_handle(out, path, hnd, flags);
if (ret) {
DWORD temp = GetLastError();
CloseHandle(hnd);
diff --git a/lib/sqfs/src/win32/ostream.c b/lib/sqfs/src/win32/ostream.c
index 3e6a8a7..3ebeb8b 100644
--- a/lib/sqfs/src/win32/ostream.c
+++ b/lib/sqfs/src/win32/ostream.c
@@ -131,12 +131,17 @@ static const char *file_get_filename(sqfs_ostream_t *strm)
}
int sqfs_ostream_open_handle(sqfs_ostream_t **out, const char *path,
- sqfs_file_handle_t hnd, int flags)
+ sqfs_file_handle_t hnd, sqfs_u32 flags)
{
- file_ostream_t *file = calloc(1, sizeof(*file));
- sqfs_ostream_t *strm = (sqfs_ostream_t *)file;
+ file_ostream_t *file;
+ sqfs_ostream_t *strm;
BOOL ret;
+ if (flags & ~(SQFS_FILE_OPEN_ALL_FLAGS))
+ return SQFS_ERROR_UNSUPPORTED;
+
+ file = calloc(1, sizeof(*file));
+ strm = (sqfs_ostream_t *)file;
if (file == NULL)
return SQFS_ERROR_ALLOC;
@@ -170,12 +175,16 @@ int sqfs_ostream_open_handle(sqfs_ostream_t **out, const char *path,
return 0;
}
-int sqfs_ostream_open_file(sqfs_ostream_t **out, const char *path, int flags)
+int sqfs_ostream_open_file(sqfs_ostream_t **out, const char *path,
+ sqfs_u32 flags)
{
sqfs_file_handle_t hnd;
int ret;
*out = NULL;
+ if (flags & SQFS_FILE_OPEN_READ_ONLY)
+ return SQFS_ERROR_ARG_INVALID;
+
ret = sqfs_open_native_file(&hnd, path, flags);
if (ret)
return ret;
diff --git a/lib/tar/test/tar_big_file.c b/lib/tar/test/tar_big_file.c
index 2c8a176..654b6ff 100644
--- a/lib/tar/test/tar_big_file.c
+++ b/lib/tar/test/tar_big_file.c
@@ -17,7 +17,8 @@ int main(int argc, char **argv)
(void)argc; (void)argv;
ret = sqfs_istream_open_file(&fp,
- STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
+ STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE),
+ 0);
TEST_EQUAL_I(ret, 0);
TEST_NOT_NULL(fp);
TEST_ASSERT(read_header(fp, &hdr) == 0);
diff --git a/lib/tar/test/tar_fuzz.c b/lib/tar/test/tar_fuzz.c
index 1c4b52e..c09fd2f 100644
--- a/lib/tar/test/tar_fuzz.c
+++ b/lib/tar/test/tar_fuzz.c
@@ -24,7 +24,7 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- ret = sqfs_istream_open_file(&fp, argv[1]);
+ ret = sqfs_istream_open_file(&fp, argv[1], 0);
if (ret) {
sqfs_perror("stdint", NULL, ret);
return EXIT_FAILURE;
diff --git a/lib/tar/test/tar_iterator.c b/lib/tar/test/tar_iterator.c
index d4c2a35..e59b210 100644
--- a/lib/tar/test/tar_iterator.c
+++ b/lib/tar/test/tar_iterator.c
@@ -41,7 +41,8 @@ int main(int argc, char **argv)
/* Open the file, create an iterator */
iret = sqfs_istream_open_file(&fp,
- STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
+ STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE),
+ 0);
TEST_EQUAL_I(iret, 0);
TEST_NOT_NULL(fp);
TEST_EQUAL_UI(((sqfs_object_t *)fp)->refcount, 1);
@@ -110,7 +111,8 @@ int main(int argc, char **argv)
/* re-open the tar iterator */
iret = sqfs_istream_open_file(&fp,
- STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
+ STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE),
+ 0);
TEST_EQUAL_I(iret, 0);
TEST_NOT_NULL(fp);
it = tar_open_stream(fp);
diff --git a/lib/tar/test/tar_iterator2.c b/lib/tar/test/tar_iterator2.c
index 8bbaf62..ac041fe 100644
--- a/lib/tar/test/tar_iterator2.c
+++ b/lib/tar/test/tar_iterator2.c
@@ -53,7 +53,8 @@ int main(int argc, char **argv)
(void)argc; (void)argv;
iret = sqfs_istream_open_file(&fp,
- STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
+ STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE),
+ 0);
TEST_EQUAL_I(iret, 0);
TEST_NOT_NULL(fp);
it = tar_open_stream(fp);
diff --git a/lib/tar/test/tar_iterator3.c b/lib/tar/test/tar_iterator3.c
index 9fd5f59..214fe9c 100644
--- a/lib/tar/test/tar_iterator3.c
+++ b/lib/tar/test/tar_iterator3.c
@@ -23,7 +23,8 @@ int main(int argc, char **argv)
TEST_ASSERT(chdir(TEST_PATH) == 0);
- ret = sqfs_istream_open_file(&fp, "format-acceptance/link_filled.tar");
+ ret = sqfs_istream_open_file(&fp, "format-acceptance/link_filled.tar",
+ 0);
TEST_EQUAL_I(ret, 0);
TEST_NOT_NULL(fp);
TEST_EQUAL_UI(((sqfs_object_t *)fp)->refcount, 1);
diff --git a/lib/tar/test/tar_simple.c b/lib/tar/test/tar_simple.c
index ad9fdde..21ab109 100644
--- a/lib/tar/test/tar_simple.c
+++ b/lib/tar/test/tar_simple.c
@@ -44,7 +44,8 @@ int main(int argc, char **argv)
(void)argc; (void)argv;
ret = sqfs_istream_open_file(&fp,
- STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
+ STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE),
+ 0);
TEST_EQUAL_I(ret, 0);
TEST_NOT_NULL(fp);
TEST_ASSERT(read_header(fp, &hdr) == 0);
diff --git a/lib/tar/test/tar_sparse.c b/lib/tar/test/tar_sparse.c
index 49b2064..702db58 100644
--- a/lib/tar/test/tar_sparse.c
+++ b/lib/tar/test/tar_sparse.c
@@ -16,7 +16,7 @@ static void test_case_sparse(const char *path)
sqfs_istream_t *fp;
int ret;
- ret = sqfs_istream_open_file(&fp, path);
+ ret = sqfs_istream_open_file(&fp, path, 0);
TEST_EQUAL_I(ret, 0);
TEST_NOT_NULL(fp);
TEST_ASSERT(read_header(fp, &hdr) == 0);
diff --git a/lib/tar/test/tar_sparse_gnu.c b/lib/tar/test/tar_sparse_gnu.c
index a2f8332..1f928bd 100644
--- a/lib/tar/test/tar_sparse_gnu.c
+++ b/lib/tar/test/tar_sparse_gnu.c
@@ -19,7 +19,7 @@ int main(int argc, char **argv)
TEST_ASSERT(chdir(TEST_PATH) == 0);
- ret = sqfs_istream_open_file(&fp, "sparse-files/gnu-small.tar");
+ ret = sqfs_istream_open_file(&fp, "sparse-files/gnu-small.tar", 0);
TEST_EQUAL_I(ret, 0);
TEST_NOT_NULL(fp);
TEST_ASSERT(read_header(fp, &hdr) == 0);
diff --git a/lib/tar/test/tar_target_filled.c b/lib/tar/test/tar_target_filled.c
index 93c3b02..1279edf 100644
--- a/lib/tar/test/tar_target_filled.c
+++ b/lib/tar/test/tar_target_filled.c
@@ -19,7 +19,8 @@ int main(int argc, char **argv)
TEST_ASSERT(chdir(TEST_PATH) == 0);
- ret = sqfs_istream_open_file(&fp, "format-acceptance/link_filled.tar");
+ ret = sqfs_istream_open_file(&fp, "format-acceptance/link_filled.tar",
+ 0);
TEST_EQUAL_I(ret, 0);
TEST_NOT_NULL(fp);
diff --git a/lib/tar/test/tar_write_simple.c b/lib/tar/test/tar_write_simple.c
index bc1b93e..438ea37 100644
--- a/lib/tar/test/tar_write_simple.c
+++ b/lib/tar/test/tar_write_simple.c
@@ -188,7 +188,8 @@ int main(int argc, char **argv)
TEST_EQUAL_UI(sizeof(rd_buffer), sizeof(wr_buffer));
ret = sqfs_istream_open_file(&fp,
- STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
+ STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE),
+ 0);
TEST_EQUAL_I(ret, 0);
TEST_NOT_NULL(fp);
diff --git a/lib/tar/test/tar_xattr.c b/lib/tar/test/tar_xattr.c
index d074e31..ca15c66 100644
--- a/lib/tar/test/tar_xattr.c
+++ b/lib/tar/test/tar_xattr.c
@@ -19,7 +19,8 @@ int main(int argc, char **argv)
(void)argc; (void)argv;
ret = sqfs_istream_open_file(&fp,
- STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
+ STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE),
+ 0);
TEST_EQUAL_I(ret, 0);
TEST_NOT_NULL(fp);
TEST_ASSERT(read_header(fp, &hdr) == 0);
diff --git a/lib/tar/test/tar_xattr_bin.c b/lib/tar/test/tar_xattr_bin.c
index 68f23fe..901b657 100644
--- a/lib/tar/test/tar_xattr_bin.c
+++ b/lib/tar/test/tar_xattr_bin.c
@@ -27,7 +27,8 @@ int main(int argc, char **argv)
(void)argc; (void)argv;
ret = sqfs_istream_open_file(&fp,
- STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
+ STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE),
+ 0);
TEST_EQUAL_I(ret, 0);
TEST_NOT_NULL(fp);
TEST_ASSERT(read_header(fp, &hdr) == 0);
diff --git a/lib/util/test/str_table.c b/lib/util/test/str_table.c
index 02e5e67..b146773 100644
--- a/lib/util/test/str_table.c
+++ b/lib/util/test/str_table.c
@@ -21,7 +21,7 @@ static int read_strings(void)
char *line;
int i;
- i = sqfs_istream_open_file(&fp, "words.txt");
+ i = sqfs_istream_open_file(&fp, "words.txt", 0);
TEST_EQUAL_I(i, 0);
TEST_NOT_NULL(fp);