Cthulhu  0.2.10
Cthulhu compiler collection
os_common.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-only
2 
3 #include "os/os.h" // IWYU pragma: keep
4 
5 #include "base/panic.h"
6 
7 static const char *const kDirentNames[eOsNodeCount] = {
8 #define OS_DIRENT(ID, STR) [ID] = (STR),
9 #include "os/os.inc"
10 };
11 
13 const char *os_dirent_string(os_dirent_t type)
14 {
15  CT_ASSERT_RANGE(type, 0, eOsNodeCount - 1);
16 
17  return kDirentNames[type];
18 }
19 
20 static const char *const kAccessNames[] = {
21  [eOsAccessNone] = "none",
22  [eOsAccessRead] = "read",
23  [eOsAccessWrite] = "write",
24  [eOsAccessRead | eOsAccessWrite] = "read/write",
25  [eOsAccessTruncate] = "truncate",
26  [eOsAccessRead | eOsAccessTruncate] = "read (truncate)",
27  [eOsAccessWrite | eOsAccessTruncate] = "write (truncate)",
28  [eOsAccessRead | eOsAccessWrite | eOsAccessTruncate] = "read/write (truncate)",
29 };
30 
32 const char *os_access_string(os_access_t access)
33 {
34  CTASSERTF(!(access & ~eOsAccessMask), "invalid access flags 0x%x", access);
35  return kAccessNames[access];
36 }
37 
38 static const char *const kProtectNames[] = {
39  [eOsProtectNone] = "none",
40  [eOsProtectRead] = "read",
41  [eOsProtectWrite] = "write",
42  [eOsProtectExecute] = "execute",
43  [eOsProtectRead | eOsProtectWrite] = "read/write",
44  [eOsProtectRead | eOsProtectExecute] = "read/execute",
45  [eOsProtectWrite | eOsProtectExecute] = "write/execute",
46  [eOsProtectRead | eOsProtectWrite | eOsProtectExecute] = "read/write/execute",
47 };
48 
50 const char *os_protect_string(os_protect_t protect)
51 {
52  CTASSERTF(!(protect & ~eOsProtectMask), "invalid protect flags 0x%x", protect);
53  return kProtectNames[protect];
54 }
os_dirent_t
directory entry type
Definition: core.h:56
@ eOsNodeCount
Definition: core.h:60
os_protect_t
file mapping memory protection
Definition: core.h:47
@ eOsProtectMask
Definition: core.h:51
os_access_t
file access mode
Definition: core.h:38
@ eOsAccessMask
Definition: core.h:42
#define STA_DECL
sal2 annotation on function implementations to copy annotations from the declaration
#define CT_ASSERT_RANGE(value, min, max)
assert that a value is in a range inclusive bounds check
Definition: panic.h:148
#define CTASSERTF(expr,...)
assert a condition with a message and optional format arguments
Definition: panic.h:116
STA_DECL const char * os_access_string(os_access_t access)
get the string representation of a file access mode
Definition: os_common.c:32
STA_DECL const char * os_protect_string(os_protect_t protect)
get the string representation of a file mapping memory protection
Definition: os_common.c:50
STA_DECL const char * os_dirent_string(os_dirent_t type)
get the string representation of a directory entry type
Definition: os_common.c:13