summaryrefslogtreecommitdiff
path: root/src/io/fd.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/io/fd.hpp')
-rw-r--r--src/io/fd.hpp44
1 files changed, 25 insertions, 19 deletions
diff --git a/src/io/fd.hpp b/src/io/fd.hpp
index 7afb40f..d04d5bf 100644
--- a/src/io/fd.hpp
+++ b/src/io/fd.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_IO_FD_HPP
-#define TMWA_IO_FD_HPP
+#pragma once
// io/fd.hpp - typesafe (but not scopesafe) file descriptors
//
// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,16 +18,18 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-# include "../sanity.hpp"
+#include "fwd.hpp"
-# include <sys/select.h>
-# include <sys/socket.h>
+#include <sys/select.h>
+#include <sys/socket.h>
-# include <unistd.h>
+#include "../strings/fwd.hpp"
-# include "../strings/fwd.hpp"
+#include "../diagnostics.hpp"
+namespace tmwa
+{
namespace io
{
class FD
@@ -55,8 +56,13 @@ namespace io
FD stdout() { return FD(1); }
static
FD stderr() { return FD(2); }
+
+ static const int DEFAULT_MODE = 0666;
+
static
- FD open(ZString path, int flags, int mode=0666);
+ FD open(ZString path, int flags, int mode=DEFAULT_MODE);
+ static
+ FD openat(FD dirfd, ZString path, int flags, int mode=DEFAULT_MODE);
static
FD socket(int domain, int type, int protocol);
FD accept(struct sockaddr *addr, socklen_t *addrlen);
@@ -64,6 +70,7 @@ namespace io
int pipe(FD& r, FD& w);
static
int pipe2(FD& r, FD& w, int flags);
+
static
FD sysconf_SC_OPEN_MAX();
@@ -138,24 +145,24 @@ namespace io
}
void clr(FD fd)
{
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wold-style-cast"
+ DIAG_PUSH();
+ DIAG_I(old_style_cast);
FD_CLR(fd.uncast_dammit(), &fds);
-# pragma GCC diagnostic pop
+ DIAG_POP();
}
bool isset(FD fd)
{
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wold-style-cast"
+ DIAG_PUSH();
+ DIAG_I(old_style_cast);
return FD_ISSET(fd.uncast_dammit(), &fds);
-# pragma GCC diagnostic pop
+ DIAG_POP();
}
void set(FD fd)
{
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wold-style-cast"
+ DIAG_PUSH();
+ DIAG_I(old_style_cast);
FD_SET(fd.uncast_dammit(), &fds);
-# pragma GCC diagnostic pop
+ DIAG_POP();
}
static
@@ -164,5 +171,4 @@ namespace io
int pselect(int nfds, FD_Set *readfds, FD_Set *writefds, FD_Set *exceptfds, const struct timespec *timeout, const sigset_t *sigmask);
};
} // namespace io
-
-#endif // TMWA_IO_FD_HPP
+} // namespace tmwa