diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2023-02-10 15:27:06 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2023-02-10 15:27:06 +0100 |
commit | 7501bff8432444b7ae8e7f3d9289c0d61f3f0b64 (patch) | |
tree | bd53603f464c3747e897a8996158a0fef7b41bc3 /src/tc-io.c | |
parent | 0f124df68d87c9073f76efeff1a901a69b1f3e13 (diff) | |
parent | 9e9336185f86bd97ff22f54e4d561c2cccccecf5 (diff) |
Merge branch 'release/debian/4.10-1'debian/4.10-1
Diffstat (limited to 'src/tc-io.c')
-rw-r--r-- | src/tc-io.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/tc-io.c b/src/tc-io.c new file mode 100644 index 0000000..639ebcc --- /dev/null +++ b/src/tc-io.c @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: MIT +#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; +} |