From 7856bf3569cc448fe3b360c3fca836593a0c0c7d Mon Sep 17 00:00:00 2001 From: guowenxue <guowenxue@gmail.com> Date: Mon, 06 Nov 2023 17:01:27 +0800 Subject: [PATCH] format c source code --- ch1_fileIO/redirect_stdio.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ch1_fileIO/redirect_stdio.c b/ch1_fileIO/redirect_stdio.c index a73f1ea..f02e031 100644 --- a/ch1_fileIO/redirect_stdio.c +++ b/ch1_fileIO/redirect_stdio.c @@ -1,28 +1,28 @@ -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int main(int argc, char *argv) -{ - int fd = -1; +{ + int fd = -1; fd = open("std.txt", O_RDWR|O_CREAT|O_TRUNC, 0666); if(fd < 0) { printf("Open file failure: %s\n", strerror(errno)); return 1; - } - + } + dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); - printf("fd=%d\n", fd); - + printf("fd=%d\n", fd); + close(fd); return 0; -- Gitblit v1.9.1