ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/Common/posix.hpp
Revision: 25
Committed: 2008-02-09T01:39:22-08:00 (14 years, 9 months ago) by douglas
File size: 1308 byte(s)
Log Message:
All kinds of changes!

File Contents

# Content
1 // 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 #include <string>
14
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 virtual const char *what() const throw() { return message; }
29 };
30
31 inline int CheckError(int status)
32 {
33 if (status == -1)
34 throw Error();
35
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_

Properties

Name Value
svn:keywords Id