mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 12:48:14 +00:00
Resolve bit set differences between linux and other platforms in posix/fcntl
This commit is contained in:
+101
-41
@@ -95,56 +95,116 @@ Lock_Type :: enum c.short {
|
|||||||
// Assertions made to unify this bit set.
|
// Assertions made to unify this bit set.
|
||||||
#assert(O_RDONLY == 0)
|
#assert(O_RDONLY == 0)
|
||||||
|
|
||||||
O_Flag_Bits :: enum c.int {
|
when ODIN_OS == .Linux {
|
||||||
// Sets FD_CLOEXEC on the file descriptor.
|
|
||||||
CLOEXEC = log2(O_CLOEXEC),
|
|
||||||
// If not exists, combined with DIRECTORY will cause creation of a directory, otherwise a regular file.
|
|
||||||
CREAT = log2(O_CREAT),
|
|
||||||
// Fails if the opened descriptor would not be a directory.
|
|
||||||
DIRECTORY = log2(O_DIRECTORY),
|
|
||||||
// If combined with CREAT, causes a failure if the file already exists.
|
|
||||||
EXCL = log2(O_EXCL),
|
|
||||||
// If terminal device, do not make it the controlling terminal for the process.
|
|
||||||
NOCTTY = log2(O_NOCTTY),
|
|
||||||
// Don't follow symbolic links, fail with errno ELOOP.
|
|
||||||
NOFOLLOW = log2(O_NOFOLLOW),
|
|
||||||
// If exists and regular, truncate the length to 0.
|
|
||||||
TRUNC = log2(O_TRUNC),
|
|
||||||
|
|
||||||
// NOTE: use with `posix.O_TTY_INIT + { .OTHER_FLAG, .OTHER_FLAG }`, unfortunately can't be in
|
O_Flag_Bits :: enum c.int {
|
||||||
// this bit set enum because it is 0 on some platforms and a value on others.
|
// Sets FD_CLOEXEC on the file descriptor.
|
||||||
// TTY_INIT = O_TTY_INIT,
|
CLOEXEC = log2(O_CLOEXEC),
|
||||||
|
// If not exists, combined with DIRECTORY will cause creation of a directory, otherwise a regular file.
|
||||||
|
CREAT = log2(O_CREAT),
|
||||||
|
// Fails if the opened descriptor would not be a directory.
|
||||||
|
DIRECTORY = log2(O_DIRECTORY),
|
||||||
|
// If combined with CREAT, causes a failure if the file already exists.
|
||||||
|
EXCL = log2(O_EXCL),
|
||||||
|
// If terminal device, do not make it the controlling terminal for the process.
|
||||||
|
NOCTTY = log2(O_NOCTTY),
|
||||||
|
// Don't follow symbolic links, fail with errno ELOOP.
|
||||||
|
NOFOLLOW = log2(O_NOFOLLOW),
|
||||||
|
// If exists and regular, truncate the length to 0.
|
||||||
|
TRUNC = log2(O_TRUNC),
|
||||||
|
|
||||||
// Set file offset to end of file prior to each write.
|
// NOTE: use with `posix.O_TTY_INIT + { .OTHER_FLAG, .OTHER_FLAG }`, unfortunately can't be in
|
||||||
APPEND = log2(O_APPEND),
|
// this bit set enum because it is 0 on some platforms and a value on others.
|
||||||
// Write I/O shall complete as defined by synchronized I/O data integrity completion.
|
// TTY_INIT = O_TTY_INIT,
|
||||||
DSYNC = log2(O_DSYNC),
|
|
||||||
// Causes nonblocking behaviour in various situations.
|
|
||||||
NONBLOCK = log2(O_NONBLOCK),
|
|
||||||
// Write I/O shall complete as defined by synchronized I/O file integrity completion.
|
|
||||||
SYNC = log2(O_SYNC),
|
|
||||||
|
|
||||||
// NOTE: use with `posix.O_RSYNC + { .OTHER_FLAG, .OTHER_FLAG }`, unfortunately can't be in
|
// Set file offset to end of file prior to each write.
|
||||||
// this bit set enum because it is 0 on some platforms and a value on others.
|
APPEND = log2(O_APPEND),
|
||||||
// RSYNC = O_RSYNC,
|
// Write I/O shall complete as defined by synchronized I/O data integrity completion.
|
||||||
|
DSYNC = log2(O_DSYNC),
|
||||||
|
// Causes nonblocking behaviour in various situations.
|
||||||
|
NONBLOCK = log2(O_NONBLOCK),
|
||||||
|
// Write I/O shall complete as defined by synchronized I/O file integrity completion.
|
||||||
|
SYNC = log2(O_SYNC),
|
||||||
|
|
||||||
// Execute only.
|
// NOTE: use with `posix.O_RSYNC + { .OTHER_FLAG, .OTHER_FLAG }`, unfortunately can't be in
|
||||||
// NOTE: use with `posix.O_ENTER + { .OTHER_FLAG, .OTHER_FLAG }`, unfortunately can't be in
|
// this bit set enum because it is 0 on some platforms and a value on others.
|
||||||
// this bit set enum because it is 0 on some platforms and a value on others.
|
// RSYNC = O_RSYNC,
|
||||||
// EXEC = O_EXEC
|
|
||||||
|
|
||||||
// Reading and writing.
|
// Execute only.
|
||||||
RDWR = log2(O_RDWR),
|
// NOTE: use with `posix.O_ENTER + { .OTHER_FLAG, .OTHER_FLAG }`, unfortunately can't be in
|
||||||
// Writing only.
|
// this bit set enum because it is 0 on some platforms and a value on others.
|
||||||
WRONLY = log2(O_WRONLY),
|
// EXEC = O_EXEC
|
||||||
// Reading only.
|
|
||||||
// RDONLY = 0, // Default
|
// Reading and writing.
|
||||||
|
RDWR = log2(O_RDWR),
|
||||||
|
// Writing only.
|
||||||
|
WRONLY = log2(O_WRONLY),
|
||||||
|
// Reading only.
|
||||||
|
// RDONLY = 0, // Default
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
O_Flag_Bits :: enum c.int {
|
||||||
|
// Sets FD_CLOEXEC on the file descriptor.
|
||||||
|
CLOEXEC = log2(O_CLOEXEC),
|
||||||
|
// If not exists, combined with DIRECTORY will cause creation of a directory, otherwise a regular file.
|
||||||
|
CREAT = log2(O_CREAT),
|
||||||
|
// Fails if the opened descriptor would not be a directory.
|
||||||
|
DIRECTORY = log2(O_DIRECTORY),
|
||||||
|
// If combined with CREAT, causes a failure if the file already exists.
|
||||||
|
EXCL = log2(O_EXCL),
|
||||||
|
// If terminal device, do not make it the controlling terminal for the process.
|
||||||
|
NOCTTY = log2(O_NOCTTY),
|
||||||
|
// Don't follow symbolic links, fail with errno ELOOP.
|
||||||
|
NOFOLLOW = log2(O_NOFOLLOW),
|
||||||
|
// If exists and regular, truncate the length to 0.
|
||||||
|
TRUNC = log2(O_TRUNC),
|
||||||
|
|
||||||
|
// NOTE: use with `posix.O_TTY_INIT + { .OTHER_FLAG, .OTHER_FLAG }`, unfortunately can't be in
|
||||||
|
// this bit set enum because it is 0 on some platforms and a value on others.
|
||||||
|
// TTY_INIT = O_TTY_INIT,
|
||||||
|
|
||||||
|
// Set file offset to end of file prior to each write.
|
||||||
|
APPEND = log2(O_APPEND),
|
||||||
|
// Write I/O shall complete as defined by synchronized I/O data integrity completion.
|
||||||
|
DSYNC = log2(O_DSYNC),
|
||||||
|
// Causes nonblocking behaviour in various situations.
|
||||||
|
NONBLOCK = log2(O_NONBLOCK),
|
||||||
|
// Write I/O shall complete as defined by synchronized I/O file integrity completion.
|
||||||
|
SYNC = log2(O_SYNC),
|
||||||
|
|
||||||
|
// NOTE: use with `posix.O_RSYNC + { .OTHER_FLAG, .OTHER_FLAG }`, unfortunately can't be in
|
||||||
|
// this bit set enum because it is 0 on some platforms and a value on others.
|
||||||
|
// RSYNC = O_RSYNC,
|
||||||
|
|
||||||
|
// Execute only.
|
||||||
|
// NOTE: use with `posix.O_ENTER + { .OTHER_FLAG, .OTHER_FLAG }`, unfortunately can't be in
|
||||||
|
// this bit set enum because it is 0 on some platforms and a value on others.
|
||||||
|
EXEC = O_EXEC,
|
||||||
|
|
||||||
|
// Reading and writing.
|
||||||
|
RDWR = log2(O_RDWR),
|
||||||
|
// Writing only.
|
||||||
|
WRONLY = log2(O_WRONLY),
|
||||||
|
// Reading only.
|
||||||
|
// RDONLY = 0, // Default
|
||||||
|
}
|
||||||
}
|
}
|
||||||
O_Flags :: bit_set[O_Flag_Bits; c.int]
|
O_Flags :: bit_set[O_Flag_Bits; c.int]
|
||||||
|
|
||||||
// A mask of all the access mode bits.
|
// A mask of all the access mode bits.
|
||||||
// NOTE: .EXEC and .RDONLY also belong here, but they are 0 on some platforms.
|
when ODIN_OS == .Linux {
|
||||||
O_ACCMODE :: O_Flags{ .RDWR, .WRONLY }
|
|
||||||
|
// NOTE: .EXEC and .RDONLY also belong here, but they are 0 on some platforms.
|
||||||
|
O_ACCMODE :: O_Flags{ .RDWR, .WRONLY }
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// NOTE: .RDONLY also belong here, but they are 0 on some platforms.
|
||||||
|
O_ACCMODE :: O_Flags{ .EXEC, .RDWR, .WRONLY }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
AT_Flag_Bits :: enum c.int {
|
AT_Flag_Bits :: enum c.int {
|
||||||
EACCESS = log2(AT_EACCESS),
|
EACCESS = log2(AT_EACCESS),
|
||||||
|
|||||||
Reference in New Issue
Block a user