ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/Common/posix.hpp
Revision: 14
Committed: 2007-05-14T18:24:34-07:00 (15 years, 4 months ago) by douglas
File size: 1415 byte(s)
Log Message:
Switch back from Menes C++ to stl and hacks.

File Contents

# User Rev Content
1 douglas 2 // Truck Computer Dooom!
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     #ifndef _posix_hpp_
8     #define _posix_hpp_
9    
10     #include <cerrno>
11     #include <cstring>
12     #include <exception>
13 douglas 14 #include <string>
14 douglas 2
15     namespace Posix
16     {
17    
18     inline int CheckError(int status);
19    
20     class Error : public std::exception
21     {
22     int code;
23     char message[1024];
24    
25     public:
26     Error();
27     virtual ~Error() throw() {}
28    
29     virtual int GetCode() const { return code; }
30 douglas 14 virtual std::string GetMessage() const { return message; }
31 douglas 2 virtual const char *what() const throw() { return message; }
32     };
33    
34     inline int CheckError(int status)
35     {
36     if (status == -1)
37     throw Error();
38    
39     return status;
40     }
41    
42 douglas 14 #define _SysCall(call) \
43     int status; \
44     \
45     while ((status = call) == -1) \
46     if (errno != EINTR) \
47     throw Error(); \
48     else \
49     continue; \
50     \
51     return status
52    
53     template <typename Function_, typename Arg0_, typename Arg1_>
54     int SysCall(Function_ function, Arg0_ arg0, Arg1_ arg1)
55     {
56     _SysCall(function(arg0, arg1));
57 douglas 2 }
58    
59 douglas 14 template <typename Function_, typename Arg0_, typename Arg1_, typename Arg2_>
60     int SysCall(Function_ function, Arg0_ arg0, Arg1_ arg1, Arg2_ arg2)
61     {
62     _SysCall(function(arg0, arg1, arg2));
63     }
64    
65     #undef _SysCall
66    
67     int Open(const std::string &path, int flags, ::mode_t mode);
68    
69     inline int Open(const std::string &path, int flags)
70     {
71     return Open(path, flags, 0);
72     }
73    
74     size_t Read(int fd, void *buffer, size_t bytes);
75     size_t ReadMost(int fd, void *buffer, size_t bytes);
76    
77     }
78    
79 douglas 2 #endif//_posix_hpp_

Properties

Name Value
svn:keywords Id