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

File Contents

# Content
1 // Truck Computer Dooom!
2 //
3 // Douglas Thrift
4 //
5 // $Id$
6
7 #ifdef _GNU_SOURCE
8 #undef _GNU_SOURCE
9 #endif
10
11 #define _XOPEN_SOURCE 600
12
13 #include <fcntl.h>
14
15 #include "posix.hpp"
16
17 namespace Posix
18 {
19
20 Error::Error() : code(errno)
21 {
22 CheckError(::strerror_r(code, message, sizeof (message)));
23 }
24
25 Error::Error(int code) : code(code)
26 {
27 CheckError(::strerror_r(code, message, sizeof (message)));
28 }
29
30 int Open(const std::string &path, int flags, ::mode_t mode)
31 {
32 return SysCall(::open, path.c_str(), flags, mode);
33 }
34
35 void Close(int fd)
36 {
37 SysCall(::close, fd);
38 }
39
40 size_t Read(int fd, void *buffer, size_t bytes)
41 {
42 return SysCall(::read, fd, buffer, bytes);
43 }
44
45 size_t ReadMost(int fd, void *buffer, size_t bytes)
46 {
47 size_t rest(bytes);
48 uint8_t *data = reinterpret_cast<uint8_t *>(buffer);
49
50 while (rest != 0)
51 {
52 size_t read(Read(fd, data, rest));
53
54 if (read == 0)
55 return bytes - rest;
56
57 data += read;
58 rest -= read;
59 }
60
61 return bytes;
62 }
63
64 size_t Write(int fd, const void *buffer, size_t bytes)
65 {
66 return SysCall(::write, fd, buffer, bytes);
67 }
68
69 int SigAction(int signal, const struct sigaction *action, struct sigaction *old)
70 {
71 return SysCall(::sigaction, signal, action, old);
72 }
73
74 int SigEmptySet(sigset_t *set)
75 {
76 return SysCall(::sigemptyset, set);
77 }
78
79 int SigFillSet(sigset_t *set)
80 {
81 return SysCall(::sigfillset, set);
82 }
83
84 int SigAddSet(sigset_t *set, int signal)
85 {
86 return SysCall(::sigaddset, set, signal);
87 }
88
89 int SigDelSet(sigset_t *set, int signal)
90 {
91 return SysCall(::sigdelset, set, signal);
92 }
93
94 int SigIsMember(const sigset_t *set, int signal)
95 {
96 return SysCall(::sigismember, set, signal);
97 }
98
99 }

Properties

Name Value
svn:keywords Id