|
|
1.1 ! root 1: /* ! 2: Copyright (c) 2008 TrueCrypt Foundation. All rights reserved. ! 3: ! 4: Governed by the TrueCrypt License 2.4 the full text of which is contained ! 5: in the file License.txt included in TrueCrypt binary and source code ! 6: distribution packages. ! 7: */ ! 8: ! 9: #include <unistd.h> ! 10: #include "Pipe.h" ! 11: #include "Platform/SystemException.h" ! 12: ! 13: namespace TrueCrypt ! 14: { ! 15: Pipe::Pipe () ! 16: { ! 17: int fd[2]; ! 18: throw_sys_if (pipe (fd) == -1); ! 19: ReadFileDescriptor = fd[0]; ! 20: WriteFileDescriptor = fd[1]; ! 21: } ! 22: ! 23: Pipe::~Pipe () ! 24: { ! 25: Close(); ! 26: } ! 27: ! 28: void Pipe::Close () ! 29: { ! 30: if (ReadFileDescriptor != -1) ! 31: close (ReadFileDescriptor); ! 32: if (WriteFileDescriptor != -1) ! 33: close (WriteFileDescriptor); ! 34: } ! 35: ! 36: int Pipe::GetReadFD () ! 37: { ! 38: assert (ReadFileDescriptor != -1); ! 39: ! 40: if (WriteFileDescriptor != -1) ! 41: { ! 42: close (WriteFileDescriptor); ! 43: WriteFileDescriptor = -1; ! 44: } ! 45: ! 46: return ReadFileDescriptor; ! 47: } ! 48: ! 49: int Pipe::GetWriteFD () ! 50: { ! 51: assert (WriteFileDescriptor != -1); ! 52: ! 53: if (ReadFileDescriptor != -1) ! 54: { ! 55: close (ReadFileDescriptor); ! 56: ReadFileDescriptor = -1; ! 57: } ! 58: ! 59: return WriteFileDescriptor; ! 60: } ! 61: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.