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 26 by douglas, 2008-02-23T13:35:09-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_>
51 + int SysCall(Function_ function, Arg0_ arg0)
52 + {
53 +        _SysCall(function(arg0));
54 + }
55 +
56 + template <typename Function_, typename Arg0_, typename Arg1_>
57 + int SysCall(Function_ function, Arg0_ arg0, Arg1_ arg1)
58 + {
59 +        _SysCall(function(arg0, arg1));
60 + }
61 +
62 + template <typename Function_, typename Arg0_, typename Arg1_, typename Arg2_>
63 + int SysCall(Function_ function, Arg0_ arg0, Arg1_ arg1, Arg2_ arg2)
64 + {
65 +        _SysCall(function(arg0, arg1, arg2));
66 + }
67 +
68 + #undef _SysCall
69 +
70 + int Open(const std::string &path, int flags, ::mode_t mode);
71 +
72 + inline int Open(const std::string &path, int flags)
73 + {
74 +        return Open(path, flags, 0);
75 + }
76 +
77 + void Close(int fd);
78 +
79 + size_t Read(int fd, void *buffer, size_t bytes);
80 + size_t ReadMost(int fd, void *buffer, size_t bytes);
81 + size_t Write(int fd, const void *buffer, size_t bytes);
82 +
83   }
84  
85   #endif//_posix_hpp_

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines