From 249866e3d1e11dc72eaa1305f4bb479ded92ef38 Mon Sep 17 00:00:00 2001 From: Jannis Hoffmann Date: Tue, 9 Jul 2024 13:58:20 +0200 Subject: reorganized file structure Moved c files into src/. Corrected VERSION file. Removed BUILD and FILES. --- src/fd.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/fd.c (limited to 'src/fd.c') diff --git a/src/fd.c b/src/fd.c new file mode 100644 index 0000000..776575c --- /dev/null +++ b/src/fd.c @@ -0,0 +1,30 @@ +#include +#include "fd.h" + +/** + @file fd.c + @autor djb + @source qmail + @brief file descriptor manipulation +*/ + +int close(int __fd); /* we won't use unistd.h here */ + +int fd_copy(int to,int from) +{ + if (to == from) return 0; + if (fcntl(from,F_GETFL,0) == -1) return -1; + close(to); + if (fcntl(from,F_DUPFD,to) == -1) return -1; + return 0; +} + +int fd_move(int to,int from) +{ + if (to == from) return 0; + if (fd_copy(to,from) == -1) return -1; + close(from); + return 0; +} + +int fd_coe(int fd) {return fcntl(fd,F_SETFD,1); } -- cgit v1.2.3