This repository has been archived by the owner on Feb 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Achille Roussel <[email protected]>
- Loading branch information
1 parent
4a5fa20
commit 0edf1e2
Showing
12 changed files
with
193 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package sandbox | ||
|
||
import ( | ||
"sort" | ||
"strings" | ||
) | ||
|
||
// OpenFlags is a bitset of flags that can be passed to the Open method of | ||
// File and FileSystem values. | ||
type OpenFlags int | ||
|
||
func makeOpenFlags(sysFlags int) OpenFlags { | ||
return OpenFlags(sysFlags) | ||
} | ||
|
||
func (openFlags OpenFlags) String() string { | ||
var names []string | ||
|
||
switch openFlags & (O_RDWR | O_WRONLY | O_RDONLY) { | ||
case O_RDWR: | ||
names = append(names, "O_RDWR") | ||
case O_WRONLY: | ||
names = append(names, "O_WRONLY") | ||
} | ||
|
||
for _, f := range [...]struct { | ||
flag OpenFlags | ||
name string | ||
}{ | ||
{O_APPEND, "O_APPEND"}, | ||
{O_CREAT, "O_CREAT"}, | ||
{O_EXCL, "O_EXCL"}, | ||
{O_SYNC, "O_SYNC"}, | ||
{O_TRUNC, "O_TRUNC"}, | ||
{O_DIRECTORY, "O_DIRECTORY"}, | ||
{O_NOFOLLOW, "O_NOFOLLOW"}, | ||
{O_NONBLOCK, "O_NONBLOCK"}, | ||
} { | ||
if (openFlags & f.flag) != 0 { | ||
names = append(names, f.name) | ||
} | ||
} | ||
|
||
if len(names) == 0 { | ||
names = append(names, "O_RDONLY") | ||
} | ||
|
||
sort.Strings(names) | ||
return strings.Join(names, "|") | ||
} | ||
|
||
func (openFlags OpenFlags) LookupFlags() LookupFlags { | ||
if (openFlags & O_NOFOLLOW) != 0 { | ||
return AT_SYMLINK_NOFOLLOW | ||
} else { | ||
return 0 | ||
} | ||
} | ||
|
||
func (openFlags OpenFlags) sysFlags() int { | ||
return int(openFlags) | ||
} | ||
|
||
// LookupFlags is a bitset of flags that can be passed to methods of File and | ||
// FileSystem values to customize the behavior of file name lookups. | ||
type LookupFlags int | ||
|
||
func (lookupFlags LookupFlags) String() string { | ||
if (lookupFlags & AT_SYMLINK_NOFOLLOW) != 0 { | ||
return "AT_SYMLINK_NOFOLLOW" | ||
} else { | ||
return "AT_SYMLINK_FOLLOW" | ||
} | ||
} | ||
|
||
func (lookupFlags LookupFlags) OpenFlags() OpenFlags { | ||
if (lookupFlags & AT_SYMLINK_NOFOLLOW) != 0 { | ||
return O_NOFOLLOW | ||
} else { | ||
return 0 | ||
} | ||
} | ||
|
||
func (lookupFlags LookupFlags) sysFlags() int { | ||
return int(lookupFlags) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.