summaryrefslogtreecommitdiffstats
path: root/test/interactive-helper/test_fileutl.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 09:59:37 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 09:59:37 +0000
commit76e2632459410dec81337edb6a9fee33c9a660f3 (patch)
treea73345df208eede4a4daad340515c9328f34625c /test/interactive-helper/test_fileutl.cc
parentInitial commit. (diff)
downloadapt-76e2632459410dec81337edb6a9fee33c9a660f3.tar.xz
apt-76e2632459410dec81337edb6a9fee33c9a660f3.zip
Adding upstream version 2.7.12.upstream/2.7.12
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/interactive-helper/test_fileutl.cc')
-rw-r--r--test/interactive-helper/test_fileutl.cc46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/interactive-helper/test_fileutl.cc b/test/interactive-helper/test_fileutl.cc
new file mode 100644
index 0000000..edc699e
--- /dev/null
+++ b/test/interactive-helper/test_fileutl.cc
@@ -0,0 +1,46 @@
+#include <config.h>
+
+#include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/strutl.h>
+
+#include <cstdlib>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#include <iostream>
+#include <string>
+
+static void callsystem(std::string const &call)
+{
+ auto ret = system(call.c_str());
+ if (WIFEXITED(ret) == false || WEXITSTATUS(ret) != 0)
+ _error->Error("Calling %s failed!", call.c_str());
+}
+
+int main(int, char ** argv)
+{
+ auto const pid = getpid();
+ std::string ls;
+ strprintf(ls, "ls -l /proc/%d/fd", pid);
+ callsystem(ls);
+ FileFd t;
+ t.Open(argv[1], FileFd::ReadOnly, FileFd::Extension);
+ callsystem(ls);
+ char buf[1024];
+ unsigned long long act;
+ while (t.Read(buf, sizeof(buf), &act))
+ if (act == 0)
+ break;
+ callsystem(ls);
+ t.Seek(5);
+ callsystem(ls);
+ t.Close();
+ callsystem(ls);
+ auto const ret = _error->PendingError();
+ _error->DumpErrors();
+ return ret;
+}