ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/Common/posix.hpp
(Generate patch)

Comparing Common/posix.hpp (file contents):
Revision 11 by douglas, 2007-05-07T16:55:52-07:00 vs.
Revision 25 by douglas, 2008-02-09T01:39:22-08:00

# Line 10 | Line 10
10   #include <cerrno>
11   #include <cstring>
12   #include <exception>
13 + #include <string>
14  
15   namespace Posix
16   {
# Line 24 | Line 25 | class Error : public std::exception
25   public:
26          Error();
27          virtual ~Error() throw() {}
27
28        virtual int GetCode() const { return code; }
28          virtual const char *what() const throw() { return message; }
29   };
30  
# Line 37 | Line 36 | inline int CheckError(int status)
36          return status;
37   }
38  
39 + #define _SysCall(call) \
40 +        int status; \
41 +        \
42 +        while ((status = call) == -1) \
43 +                if (errno != EINTR) \
44 +                        throw Error(); \
45 +                else \
46 +                        continue; \
47 +        \
48 +        return status
49 +
50 + template <typename Function_, typename Arg0_, typename Arg1_>
51 + int SysCall(Function_ function, Arg0_ arg0, Arg1_ arg1)
52 + {
53 +        _SysCall(function(arg0, arg1));
54 + }
55 +
56 + template <typename Function_, typename Arg0_, typename Arg1_, typename Arg2_>
57 + int SysCall(Function_ function, Arg0_ arg0, Arg1_ arg1, Arg2_ arg2)
58 + {
59 +        _SysCall(function(arg0, arg1, arg2));
60 + }
61 +
62 + #undef _SysCall
63 +
64 + int Open(const std::string &path, int flags, ::mode_t mode);
65 +
66 + inline int Open(const std::string &path, int flags)
67 + {
68 +        return Open(path, flags, 0);
69 + }
70 +
71 + size_t Read(int fd, void *buffer, size_t bytes);
72 + size_t ReadMost(int fd, void *buffer, size_t bytes);
73 +
74   }
75  
76   #endif//_posix_hpp_

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines