blob: e39965fa07be0fd543d8ab687c5b56fe0c7a2c4b [file] [log] [blame]
William A. Kennington IIIeac9d472020-08-03 13:57:14 -07001#include <fcntl.h>
Patrick Williamsd1984dd2023-05-10 16:12:44 -05002#include <sys/socket.h>
3
William A. Kennington IIIeac9d472020-08-03 13:57:14 -07004#include <stdplus/fd/create.hpp>
5#include <stdplus/util/cexec.hpp>
William A. Kennington IIIeac9d472020-08-03 13:57:14 -07006
William A. Kennington III6417c632023-07-17 02:56:52 -07007#include <format>
8
William A. Kennington IIIeac9d472020-08-03 13:57:14 -07009namespace stdplus
10{
11namespace fd
12{
13
William A. Kennington IIIe6fda452023-07-26 15:12:12 -070014DupableFd open(const_zstring pathname, OpenFlags flags, mode_t mode)
William A. Kennington IIIeac9d472020-08-03 13:57:14 -070015{
16 return DupableFd(
William A. Kennington IIIe6fda452023-07-26 15:12:12 -070017 CHECK_ERRNO(::open(pathname.c_str(), static_cast<int>(flags), mode),
18 std::format("open `{}`", pathname.c_str())));
William A. Kennington IIIeac9d472020-08-03 13:57:14 -070019}
20
21DupableFd socket(SocketDomain domain, SocketType type, SocketProto protocol)
22{
23 return DupableFd(
24 CHECK_ERRNO(::socket(static_cast<int>(domain), static_cast<int>(type),
25 static_cast<int>(protocol)),
26 "socket"));
27}
28
29} // namespace fd
30} // namespace stdplus