00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PALUDIS_GUARD_PALUDIS_UTIL_SAFE_IFSTREAM_HH
00021 #define PALUDIS_GUARD_PALUDIS_UTIL_SAFE_IFSTREAM_HH 1
00022
00023 #include <paludis/util/attributes.hh>
00024 #include <paludis/util/exception.hh>
00025 #include <paludis/util/fs_entry-fwd.hh>
00026 #include <istream>
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 namespace paludis
00039 {
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 class PALUDIS_VISIBLE SafeIFStreamBuf :
00051 public std::streambuf
00052 {
00053 protected:
00054 static const int lookbehind_size = 16;
00055 static const int buffer_size = 512 + lookbehind_size;
00056 char buffer[buffer_size];
00057
00058 virtual int_type underflow();
00059 virtual pos_type seekoff(off_type, std::ios_base::seekdir, std::ios_base::openmode);
00060 virtual pos_type seekpos(pos_type, std::ios_base::openmode);
00061
00062 public:
00063
00064
00065
00066 SafeIFStreamBuf(const int f);
00067
00068
00069
00070
00071 int fd;
00072 };
00073
00074
00075
00076
00077
00078
00079
00080 class PALUDIS_VISIBLE SafeIFStreamBase
00081 {
00082 protected:
00083
00084 SafeIFStreamBuf buf;
00085
00086 public:
00087
00088
00089
00090 SafeIFStreamBase(const int fd);
00091
00092
00093 };
00094
00095
00096
00097
00098
00099
00100
00101
00102 class PALUDIS_VISIBLE SafeIFStream :
00103 protected SafeIFStreamBase,
00104 public std::istream
00105 {
00106 private:
00107 const bool _close;
00108
00109 public:
00110
00111
00112
00113 SafeIFStream(const int fd);
00114 SafeIFStream(const FSEntry &);
00115 ~SafeIFStream();
00116
00117
00118 };
00119
00120
00121
00122
00123
00124
00125
00126 class PALUDIS_VISIBLE SafeIFStreamError :
00127 public Exception
00128 {
00129 public:
00130 SafeIFStreamError(const std::string &) throw ();
00131 };
00132 }
00133
00134 #endif