aboutsummaryrefslogtreecommitdiffstats
path: root/modules/fd_unix
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-05-18 18:33:19 +0000
committerlloyd <[email protected]>2006-05-18 18:33:19 +0000
commita2c99d3270eb73ef2db5704fc54356c6b75096f8 (patch)
treead3d6c4fcc8dd0f403f8105598943616246fe172 /modules/fd_unix
Initial checkin1.5.6
Diffstat (limited to 'modules/fd_unix')
-rw-r--r--modules/fd_unix/fd_unix.cpp50
-rw-r--r--modules/fd_unix/fd_unix.h21
-rw-r--r--modules/fd_unix/modinfo.txt22
3 files changed, 93 insertions, 0 deletions
diff --git a/modules/fd_unix/fd_unix.cpp b/modules/fd_unix/fd_unix.cpp
new file mode 100644
index 000000000..8b7b2648a
--- /dev/null
+++ b/modules/fd_unix/fd_unix.cpp
@@ -0,0 +1,50 @@
+/*************************************************
+* Pipe I/O for Unix Source File *
+* (C) 1999-2006 The Botan Project *
+*************************************************/
+
+#include <botan/pipe.h>
+#include <unistd.h>
+
+namespace Botan {
+
+/*************************************************
+* Write data from a pipe into a Unix fd *
+*************************************************/
+int operator<<(int fd, Pipe& pipe)
+ {
+ SecureVector<byte> buffer(DEFAULT_BUFFERSIZE);
+ while(pipe.remaining())
+ {
+ u32bit got = pipe.read(buffer, buffer.size());
+ u32bit position = 0;
+ while(got)
+ {
+ ssize_t ret = write(fd, buffer + position, got);
+ if(ret == -1)
+ throw Stream_IO_Error("Pipe output operator (unixfd) has failed");
+ position += ret;
+ got -= ret;
+ }
+ }
+ return fd;
+ }
+
+/*************************************************
+* Read data from a Unix fd into a pipe *
+*************************************************/
+int operator>>(int fd, Pipe& pipe)
+ {
+ SecureVector<byte> buffer(DEFAULT_BUFFERSIZE);
+ while(true)
+ {
+ ssize_t ret = read(fd, buffer, buffer.size());
+ if(ret == 0) break;
+ if(ret == -1)
+ throw Stream_IO_Error("Pipe input operator (unixfd) has failed");
+ pipe.write(buffer, ret);
+ }
+ return fd;
+ }
+
+}
diff --git a/modules/fd_unix/fd_unix.h b/modules/fd_unix/fd_unix.h
new file mode 100644
index 000000000..f00cb8020
--- /dev/null
+++ b/modules/fd_unix/fd_unix.h
@@ -0,0 +1,21 @@
+/*************************************************
+* Pipe I/O for Unix Header File *
+* (C) 1999-2006 The Botan Project *
+*************************************************/
+
+#ifndef BOTAN_EXT_PIPE_UNIXFD_H__
+#define BOTAN_EXT_PIPE_UNIXFD_H__
+
+#include <botan/pipe.h>
+
+namespace Botan {
+
+/*************************************************
+* Unix I/O Operators for Pipe *
+*************************************************/
+int operator<<(int, Pipe&);
+int operator>>(int, Pipe&);
+
+}
+
+#endif
diff --git a/modules/fd_unix/modinfo.txt b/modules/fd_unix/modinfo.txt
new file mode 100644
index 000000000..062b93cca
--- /dev/null
+++ b/modules/fd_unix/modinfo.txt
@@ -0,0 +1,22 @@
+realname "Pipe Unix I/O support"
+
+define PIPE_UNIXFD_IO
+
+add_file fd_unix.h
+add_file fd_unix.cpp
+
+<os>
+aix
+beos
+cygwin
+darwin
+freebsd
+hpux
+irix
+linux
+netbsd
+openbsd
+qnx
+solaris
+tru64
+</os>