aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-15 14:23:47 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-15 14:23:47 +0200
commit8cf84b4995552bad4e77eb795e36c0b1d65a720a (patch)
treed3484d6591851bd4346ba9f2b57053fd105e7cf3
parentfd5c9f1259d0191af57b20f06dda35e62acb6275 (diff)
libio: split stdin/stdout code from the rest of the file streams
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--lib/io/Makemodule.am2
-rw-r--r--lib/io/src/std.c36
-rw-r--r--lib/io/src/unix/istream.c5
-rw-r--r--lib/io/src/unix/ostream.c6
-rw-r--r--lib/io/src/win32/istream.c7
-rw-r--r--lib/io/src/win32/ostream.c8
6 files changed, 37 insertions, 27 deletions
diff --git a/lib/io/Makemodule.am b/lib/io/Makemodule.am
index 9e442be..e128eef 100644
--- a/lib/io/Makemodule.am
+++ b/lib/io/Makemodule.am
@@ -3,7 +3,7 @@ libio_a_SOURCES = include/io/istream.h include/io/xfrm.h \
include/io/dir_iterator.h include/io/mem.h lib/io/src/internal.h \
lib/io/src/get_line.c lib/io/src/xfrm/ostream.c \
lib/io/src/xfrm/istream.c lib/io/src/dir_tree_iterator.c \
- lib/io/src/dir_entry.c lib/io/src/mem.c
+ lib/io/src/dir_entry.c lib/io/src/mem.c lib/io/src/std.c
libio_a_CFLAGS = $(AM_CFLAGS) $(ZLIB_CFLAGS) $(XZ_CFLAGS)
libio_a_CFLAGS += $(ZSTD_CFLAGS) $(BZIP2_CFLAGS)
diff --git a/lib/io/src/std.c b/lib/io/src/std.c
new file mode 100644
index 0000000..212fa6f
--- /dev/null
+++ b/lib/io/src/std.c
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * std.c
+ *
+ * Copyright (C) 2023 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+#include "compat.h"
+#include "io/file.h"
+#include "io/std.h"
+#include "sqfs/io.h"
+
+#if defined(_WIN32) || defined(__WINDOWS__)
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#else
+#include <unistd.h>
+#define STD_INPUT_HANDLE STDIN_FILENO
+#define STD_OUTPUT_HANDLE STDOUT_FILENO
+#define GetStdHandle(hnd) hnd
+#endif
+
+int istream_open_stdin(sqfs_istream_t **out)
+{
+ sqfs_file_handle_t hnd = GetStdHandle(STD_INPUT_HANDLE);
+
+ return istream_open_handle(out, "stdin", hnd);
+}
+
+int ostream_open_stdout(sqfs_ostream_t **out)
+{
+ sqfs_file_handle_t hnd = GetStdHandle(STD_OUTPUT_HANDLE);
+
+ return ostream_open_handle(out, "stdout", hnd,
+ SQFS_FILE_OPEN_NO_SPARSE);
+}
diff --git a/lib/io/src/unix/istream.c b/lib/io/src/unix/istream.c
index 5005a69..55b467e 100644
--- a/lib/io/src/unix/istream.c
+++ b/lib/io/src/unix/istream.c
@@ -153,8 +153,3 @@ int istream_open_file(sqfs_istream_t **out, const char *path)
return ret;
}
-
-int istream_open_stdin(sqfs_istream_t **out)
-{
- return istream_open_handle(out, "stdin", STDIN_FILENO);
-}
diff --git a/lib/io/src/unix/ostream.c b/lib/io/src/unix/ostream.c
index a97d8f3..57467f5 100644
--- a/lib/io/src/unix/ostream.c
+++ b/lib/io/src/unix/ostream.c
@@ -195,9 +195,3 @@ int ostream_open_file(sqfs_ostream_t **out, const char *path, int flags)
return 0;
}
-
-int ostream_open_stdout(sqfs_ostream_t **out)
-{
- return ostream_open_handle(out, "stdout", STDOUT_FILENO,
- SQFS_FILE_OPEN_NO_SPARSE);
-}
diff --git a/lib/io/src/win32/istream.c b/lib/io/src/win32/istream.c
index 1a4f4db..a09f3c3 100644
--- a/lib/io/src/win32/istream.c
+++ b/lib/io/src/win32/istream.c
@@ -171,10 +171,3 @@ int istream_open_file(sqfs_istream_t **out, const char *path)
return 0;
}
-
-int istream_open_stdin(sqfs_istream_t **out)
-{
- HANDLE hnd = GetStdHandle(STD_INPUT_HANDLE);
-
- return istream_open_handle(out, "stdin", hnd);
-}
diff --git a/lib/io/src/win32/ostream.c b/lib/io/src/win32/ostream.c
index b2ba599..b7f0e06 100644
--- a/lib/io/src/win32/ostream.c
+++ b/lib/io/src/win32/ostream.c
@@ -188,11 +188,3 @@ int ostream_open_file(sqfs_ostream_t **out, const char *path, int flags)
return 0;
}
-
-int ostream_open_stdout(sqfs_ostream_t **out)
-{
- HANDLE hnd = GetStdHandle(STD_OUTPUT_HANDLE);
-
- return ostream_open_handle(out, "stdout", hnd,
- SQFS_FILE_OPEN_NO_SPARSE);
-}