summaryrefslogtreecommitdiff
path: root/src/tc-io.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2022-10-24 21:03:43 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2022-10-24 21:03:43 +0200
commitaab49e5a013c53ae812a143fe41add74e0677a61 (patch)
treef0c6e1ba7db9991f2bd38c9169f9921bfe5e61d8 /src/tc-io.c
parentdf5167db909a88fb8e16dd20b37442495a6ac059 (diff)
parent532d4a24e2013262dfa41fd85c06a9715c99abf7 (diff)
Update upstream source from tag 'upstream/4.7'
Update to upstream version '4.7' with Debian dir d3e11463c915e5c39507206197eb3acd42bb8f5f
Diffstat (limited to 'src/tc-io.c')
-rw-r--r--src/tc-io.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/tc-io.c b/src/tc-io.c
new file mode 100644
index 0000000..1e95e65
--- /dev/null
+++ b/src/tc-io.c
@@ -0,0 +1,55 @@
+#include <errno.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <libHX/io.h>
+#include "internal.h"
+
+static void sf(void)
+{
+ int src = open("tc-io.c", O_RDONLY);
+ if (src < 0)
+ return;
+ int dst = open("/dev/null", O_WRONLY);
+ if (dst < 0) {
+ close(src);
+ return;
+ }
+ ssize_t ret = HX_sendfile(dst, src, SIZE_MAX);
+ printf("sendfile transferred %zd bytes\n", ret);
+ close(dst);
+ close(src);
+}
+
+int main(void)
+{
+ size_t z;
+ char *s = HX_slurp_file("tc-io.c", &z);
+ if (s == nullptr) {
+ fprintf(stderr, "HX_slurp_file: %s\n", strerror(errno));
+ return EXIT_FAILURE;
+ }
+ printf("%s\n", s);
+ printf("Dumped %zu bytes\n", z);
+ free(s);
+ s = HX_slurp_file("/proc/version", &z);
+ if (s == nullptr) {
+ fprintf(stderr, "HX_slurp_file: %s\n", strerror(errno));
+ return EXIT_FAILURE;
+ }
+ printf(">%s<\n", s);
+ free(s);
+
+ sf();
+ int ret = HX_copy_file("tc-io.c", "tciocopy.txt", 0);
+ if (ret <= 0) {
+ fprintf(stderr, "HX_copy_file: %s\n", strerror(errno));
+ } else {
+ fprintf(stderr, "copy_file ok\n");
+ unlink("tciocopy.txt");
+ }
+ return 0;
+}