From: Egor Chelak Date: Fri, 6 Nov 2020 19:08:12 +0000 (+0200) Subject: ul_copy_file: add test program X-Git-Tag: v2.37-rc1~393^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7951164c1ff71c86d93458c8b571d1a4b2ad3e59;p=thirdparty%2Futil-linux.git ul_copy_file: add test program Suggested-by: Karel Zak Reviewed-by: Sami Kerola Signed-off-by: Egor Chelak --- diff --git a/lib/fileutils.c b/lib/fileutils.c index a9c0e61c0f..a41830457e 100644 --- a/lib/fileutils.c +++ b/lib/fileutils.c @@ -177,7 +177,7 @@ void close_all_fds(const int exclude[], size_t exsz) int main(int argc, char *argv[]) { if (argc < 2) - errx(EXIT_FAILURE, "Usage %s --{mkstemp,close-fds}", argv[0]); + errx(EXIT_FAILURE, "Usage %s --{mkstemp,close-fds,copy-file}", argv[0]); if (strcmp(argv[1], "--mkstemp") == 0) { FILE *f; @@ -197,6 +197,12 @@ int main(int argc, char *argv[]) ignore_result( dup(STDIN_FILENO) ); close_all_fds(wanted_fds, ARRAY_SIZE(wanted_fds)); + } else if (strcmp(argv[1], "--copy-file") == 0) { + int ret = ul_copy_file(STDIN_FILENO, STDOUT_FILENO); + if (ret == -1) + err(EXIT_FAILURE, "read"); + else if (ret == -2) + err(EXIT_FAILURE, "write"); } return EXIT_SUCCESS; }