dius 0.1.0
Loading...
Searching...
No Matches
open_mode_flags.h
Go to the documentation of this file.
1#pragma once
2
3#include "dius/c_definitions.h"
4#include "dius/sync_file.h"
5
6namespace dius::detail {
7inline auto open_mode_flags(OpenMode open_mode, OpenFlags flags) -> int {
8 auto base = O_CLOEXEC;
9 if (!!(flags & OpenFlags::NoControllingTerminal)) {
10 base |= O_NOCTTY;
11 }
12 if (!!(flags & OpenFlags::KeepAfterExec)) {
13 base &= ~O_CLOEXEC;
14 }
15 switch (open_mode) {
17 return base | O_RDONLY;
19 return base | O_WRONLY | O_EXCL | O_CREAT;
21 return base | O_WRONLY | O_TRUNC | O_CREAT;
23 return base | O_RDWR;
25 return base | O_WRONLY | O_APPEND | O_CREAT;
27 return base | O_RDWR | O_TRUNC | O_CREAT;
29 return base | O_RDWR | O_APPEND | O_CREAT;
30 default:
31 di::unreachable();
32 }
33}
34}
Definition print.h:8
auto open_mode_flags(OpenMode open_mode, OpenFlags flags) -> int
Definition open_mode_flags.h:7
OpenFlags
Definition sync_file.h:111
@ KeepAfterExec
Definition sync_file.h:114
@ NoControllingTerminal
Definition sync_file.h:113
OpenMode
Definition sync_file.h:109
@ Readonly
Definition sync_file.h:109
@ WriteNew
Definition sync_file.h:109
@ AppendOnly
Definition sync_file.h:109
@ AppendReadWrite
Definition sync_file.h:109
@ ReadWrite
Definition sync_file.h:109
@ WriteClobber
Definition sync_file.h:109
@ ReadWriteClobber
Definition sync_file.h:109