ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/Common/posix.cpp
Revision: 26
Committed: 2008-02-23T13:35:09-08:00 (14 years, 3 months ago) by douglas
File size: 940 byte(s)
Log Message:
Woo! Stuff!

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 int Open(const std::string &path, int flags, ::mode_t mode)
26 {
27 return SysCall(::open, path.c_str(), flags, mode);
28 }
29
30 void Close(int fd)
31 {
32 SysCall(::close, fd);
33 }
34
35 size_t Read(int fd, void *buffer, size_t bytes)
36 {
37 return SysCall(::read, fd, buffer, bytes);
38 }
39
40 size_t ReadMost(int fd, void *buffer, size_t bytes)
41 {
42 size_t rest(bytes);
43 uint8_t *data = reinterpret_cast<uint8_t *>(buffer);
44
45 while (rest != 0)
46 {
47 size_t read(Read(fd, data, rest));
48
49 if (read == 0)
50 return bytes - rest;
51
52 data += read;
53 rest -= read;
54 }
55
56 return bytes;
57 }
58
59 size_t Write(int fd, const void *buffer, size_t bytes)
60 {
61 return SysCall(::write, fd, buffer, bytes);
62 }
63
64 }

Properties

Name Value
svn:keywords Id