ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/Common/posix.hpp
Revision: 35
Committed: 2008-03-04T20:37:13-08:00 (14 years, 3 months ago) by douglas
File size: 1825 byte(s)
Log Message:
Woo!

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 #include <signal.h>
16
17 namespace Posix
18 {
19
20 inline int CheckError(int status);
21
22 class Error : public std::exception
23 {
24 int code;
25 char message[1024];
26
27 public:
28 Error();
29 Error(int code);
30 virtual ~Error() throw() {}
31 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 #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_>
54 int SysCall(Function_ function, Arg0_ arg0)
55 {
56 _SysCall(function(arg0));
57 }
58
59 template <typename Function_, typename Arg0_, typename Arg1_>
60 int SysCall(Function_ function, Arg0_ arg0, Arg1_ arg1)
61 {
62 _SysCall(function(arg0, arg1));
63 }
64
65 template <typename Function_, typename Arg0_, typename Arg1_, typename Arg2_>
66 int SysCall(Function_ function, Arg0_ arg0, Arg1_ arg1, Arg2_ arg2)
67 {
68 _SysCall(function(arg0, arg1, arg2));
69 }
70
71 #undef _SysCall
72
73 int Open(const std::string &path, int flags, ::mode_t mode);
74
75 inline int Open(const std::string &path, int flags)
76 {
77 return Open(path, flags, 0);
78 }
79
80 void Close(int fd);
81
82 size_t Read(int fd, void *buffer, size_t bytes);
83 size_t ReadMost(int fd, void *buffer, size_t bytes);
84 size_t Write(int fd, const void *buffer, size_t bytes);
85 int SigAction(int signal, const struct sigaction *action, struct sigaction *old);
86 int SigEmptySet(sigset_t *set);
87 int SigFillSet(sigset_t *set);
88 int SigAddSet(sigset_t *set, int signal);
89 int SigDelSet(sigset_t *set, int signal);
90 int SigIsMember(const sigset_t *set, int signal);
91
92 }
93
94 #endif//_posix_hpp_

Properties

Name Value
svn:keywords Id