aboutsummaryrefslogtreecommitdiffstats
path: root/src/io
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-28 19:29:24 +0000
committerlloyd <[email protected]>2008-09-28 19:29:24 +0000
commit9bcfe627321ddc81691b835dffaa6324ac4684a4 (patch)
treefe5e8ae9813b853549558b59833022e87e83981b /src/io
parent9822a701516396b7de4e41339faecd48ff8dc8ff (diff)
Move all modules into src/ directory
Diffstat (limited to 'src/io')
-rw-r--r--src/io/fd_unix/fd_unix.cpp50
-rw-r--r--src/io/fd_unix/fd_unix.h21
-rw-r--r--src/io/fd_unix/modinfo.txt27
3 files changed, 98 insertions, 0 deletions
diff --git a/src/io/fd_unix/fd_unix.cpp b/src/io/fd_unix/fd_unix.cpp
new file mode 100644
index 000000000..ac88ac391
--- /dev/null
+++ b/src/io/fd_unix/fd_unix.cpp
@@ -0,0 +1,50 @@
+/*************************************************
+* Pipe I/O for Unix Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#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/src/io/fd_unix/fd_unix.h b/src/io/fd_unix/fd_unix.h
new file mode 100644
index 000000000..cbe93dfe0
--- /dev/null
+++ b/src/io/fd_unix/fd_unix.h
@@ -0,0 +1,21 @@
+/*************************************************
+* Pipe I/O for Unix Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_PIPE_UNIXFD_H__
+#define BOTAN_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/src/io/fd_unix/modinfo.txt b/src/io/fd_unix/modinfo.txt
new file mode 100644
index 000000000..e1f30ea28
--- /dev/null
+++ b/src/io/fd_unix/modinfo.txt
@@ -0,0 +1,27 @@
+realname "Unix I/O support for Pipe"
+
+define PIPE_UNIXFD_IO
+modset unix,beos
+
+load_on auto
+
+<add>
+fd_unix.h
+fd_unix.cpp
+</add>
+
+<os>
+aix
+beos
+cygwin
+darwin
+freebsd
+hpux
+irix
+linux
+netbsd
+openbsd
+qnx
+solaris
+tru64
+</os>