ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/Common/posix.cpp
Revision: 14
Committed: 2007-05-14T18:24:34-07:00 (18 years, 1 month ago) by douglas
File size: 788 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     #ifdef _GNU_SOURCE
8     #undef _GNU_SOURCE
9     #endif
10    
11     #define _XOPEN_SOURCE 600
12    
13 douglas 14 #include <fcntl.h>
14    
15 douglas 2 #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 douglas 14 int Open(const std::string &path, int flags, ::mode_t mode)
26     {
27     return SysCall(::open, path.c_str(), flags, mode);
28 douglas 2 }
29 douglas 14
30     size_t Read(int fd, void *buffer, size_t bytes)
31     {
32     return SysCall(::read, fd, buffer, bytes);
33     }
34    
35     size_t ReadMost(int fd, void *buffer, size_t bytes)
36     {
37     size_t rest(bytes);
38     uint8_t *data = reinterpret_cast<uint8_t *>(buffer);
39    
40     while (rest != 0)
41     {
42     size_t read(Read(fd, data, rest));
43    
44     if (read == 0)
45     return bytes - rest;
46    
47     data += read;
48     rest -= read;
49     }
50    
51     return bytes;
52     }
53    
54     }

Properties

Name Value
svn:keywords Id