diff options
author | stevel@tonic-gate <none@none> | 2005-06-14 00:00:00 -0700 |
---|---|---|
committer | stevel@tonic-gate <none@none> | 2005-06-14 00:00:00 -0700 |
commit | 7c478bd95313f5f23a4c958a745db2134aa03244 (patch) | |
tree | c871e58545497667cbb4b0a4f2daf204743e1fe7 /usr/src/cmd/ssh/libssh/common/proxy-io.c | |
download | illumos-joyent-7c478bd95313f5f23a4c958a745db2134aa03244.tar.gz |
OpenSolaris Launch
Diffstat (limited to 'usr/src/cmd/ssh/libssh/common/proxy-io.c')
-rw-r--r-- | usr/src/cmd/ssh/libssh/common/proxy-io.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/usr/src/cmd/ssh/libssh/common/proxy-io.c b/usr/src/cmd/ssh/libssh/common/proxy-io.c new file mode 100644 index 0000000000..c025f28f0a --- /dev/null +++ b/usr/src/cmd/ssh/libssh/common/proxy-io.c @@ -0,0 +1,38 @@ +/* + * Copyright 2003 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <unistd.h> +#include "proxy-io.h" + +int +proxy_read_write_loop(int readfd, int writefd) +{ + int rbytes, bytes_to_write, bytes_written; + char readbuf[BUFFER_SIZ]; + char *ptr; + + rbytes = read(readfd, readbuf, sizeof (readbuf)); + + if (rbytes > 0) { + bytes_to_write = rbytes; + ptr = readbuf; + while (bytes_to_write > 0) { + if ((bytes_written = + write(writefd, ptr, bytes_to_write)) < 0) { + perror("write"); + return (0); + } + bytes_to_write -= bytes_written; + ptr += bytes_written; + } + } else if (rbytes <= 0) { + return (0); + } + /* Read and write successful */ + return (1); +} |