Skip to content

Commit

Permalink
std/os: minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Dec 9, 2024
1 parent 3dba7b2 commit fab596a
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions std/os/file.jule
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,21 @@ enum Seek: int {
End: 2, // Seek relative to the end
}

// Enum wrapper for type-safe o-flags.
enum oFlag: int {
Rdonly: sys::O_RDONLY,
Wronly: sys::O_WRONLY,
Rdwr: sys::O_RDWR,
Append: sys::O_APPEND,
Create: sys::O_CREAT,
Excl: sys::O_EXCL,
Sync: sys::O_SYNC,
Trunc: sys::O_TRUNC,
}

// Flags to open wrapping those of the underlying system.
// Not all flags may be implemented on a given system.
// Exactly one of O_RDONLY, O_WRONLY, or O_RDWR must be specified.
//
// All flags have the underlying enum type for type safety.
const O_RDONLY = oFlag.Rdonly // Open the file read-only
const O_WRONLY = oFlag.Wronly // Open the file write-only
const O_RDWR = oFlag.Rdwr // Open the file read-write
const O_APPEND = oFlag.Append // Append data to the file when writing
const O_CREATE = oFlag.Create // Create a new file if none exists
const O_EXCL = oFlag.Excl // Used with O_CREATE, file must not exist
const O_SYNC = oFlag.Sync // Open for synchronous I/O
const O_TRUNC = oFlag.Trunc // Truncate regular writable file when opened
type oFlag: int

const O_RDONLY = sys::O_RDONLY // Open the file read-only
const O_WRONLY = sys::O_WRONLY // Open the file write-only
const O_RDWR = sys::O_RDWR // Open the file read-write
const O_APPEND = sys::O_APPEND // Append data to the file when writing
const O_CREATE = sys::O_CREAT // Create a new file if none exists
const O_EXCL = sys::O_EXCL // Used with O_CREATE, file must not exist
const O_SYNC = sys::O_SYNC // Open for synchronous I/O
const O_TRUNC = sys::O_TRUNC // Truncate regular writable file when opened

// The file stream handle.
//
Expand Down

0 comments on commit fab596a

Please sign in to comment.