Mercurial > hg > mlmmj
changeset 156:81b1c9ea0b3e
dumpfd2fd
author | mmj |
---|---|
date | Thu, 03 Jun 2004 08:47:20 +1000 |
parents | f844a6213c62 |
children | af54da533809 |
files | src/dumpfd2fd.c |
diffstat | 1 files changed, 36 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dumpfd2fd.c Thu Jun 03 08:47:20 2004 +1000 @@ -0,0 +1,36 @@ +/* Copyright (C) 2004 Mads Martin Joergensen <mmj at mmj dot dk> + * + * $Id$ + * + * This file is redistributable under version 2 of the GNU General + * Public License as described at http://www.gnu.org/licenses/gpl.txt + */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> + +#include "wrappers.h" + +#define DUMPBUF 1024 + +int dumpfd2fd(int infd, int outfd) +{ + size_t n; + char buf[DUMPBUF]; + + while((n = read(infd, &buf, sizeof(buf))) != 0) { + if(n < 0) { + if(errno == EINTR) + continue; + else + return errno; + } + if(writen(outfd, &buf, n) < 0) + return errno; + } + + return 0; +}