-
Notifications
You must be signed in to change notification settings - Fork 9
Allow unix 2.8.6 #805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jasagredo
wants to merge
1
commit into
main
Choose a base branch
from
js/older-unix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+75
−7
Open
Allow unix 2.8.6 #805
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,38 @@ | ||
| {-# LANGUAGE CPP #-} | ||
| -- | Compatibility layer for the @unix@ package to provide a @fileSetCaching@ function. | ||
| -- | ||
| -- @unix >= 2.8.7@ defines a @fileSetCaching@ function, but @unix < 2.8.7@ does not. This module defines the function for @unix@ versions @< 2.8.7@. The implementation is adapted from https://github.com/haskell/unix/blob/v2.8.8.0/System/Posix/Fcntl.hsc#L116-L182. | ||
| -- | ||
| -- NOTE: in the future if we no longer support @unix@ versions @< 2.8.7@, then this module can be removed. | ||
| module System.FS.BlockIO.Internal.Fcntl (fileSetCaching) where | ||
|
|
||
| #if MIN_VERSION_unix(2,8,7) | ||
|
|
||
| import System.Posix.Fcntl (fileSetCaching) | ||
|
|
||
| #else | ||
|
|
||
| -- hsc2hs does not define _GNU_SOURCE, so a .hsc file must define it explicitly | ||
| -- or O_DIRECT stays hidden. The unix package doesn’t define it in source, but | ||
| -- its configure script calls AC_USE_SYSTEM_EXTENSIONS, which adds -D_GNU_SOURCE | ||
| -- to the build CFLAGS, and those flags are passed on to hsc2hs through the | ||
| -- generated `config.mk`. | ||
| #define _GNU_SOURCE | ||
jasagredo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #include <fcntl.h> | ||
|
|
||
| import Data.Bits (complement, (.&.), (.|.)) | ||
| import Foreign.C (throwErrnoIfMinus1, throwErrnoIfMinus1_) | ||
| import System.Posix.Internals | ||
| import System.Posix.Types (Fd (Fd)) | ||
|
|
||
| -- | For simplification, we considered that Linux !HAS_F_NOCACHE and HAS_O_DIRECT | ||
| fileSetCaching :: Fd -> Bool -> IO () | ||
| fileSetCaching (Fd fd) val = do | ||
| r <- throwErrnoIfMinus1 "fileSetCaching" (c_fcntl_read fd #{const F_GETFL}) | ||
| let r' | val = fromIntegral r .&. complement opt_val | ||
| | otherwise = fromIntegral r .|. opt_val | ||
| throwErrnoIfMinus1_ "fileSetCaching" (c_fcntl_write fd #{const F_SETFL} r') | ||
| where | ||
| opt_val = #{const O_DIRECT} | ||
| #endif | ||
This file contains hidden or 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 hidden or 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,25 @@ | ||
| {-# LANGUAGE CPP #-} | ||
| -- | Compatibility layer for the @unix@ package to provide a @fileSetCaching@ function. | ||
| -- | ||
| -- @unix >= 2.8.7@ defines a @fileSetCaching@ function, but @unix < 2.8.7@ does not. This module defines the function for @unix@ versions @< 2.8.7@. The implementation is adapted from https://github.com/haskell/unix/blob/v2.8.8.0/System/Posix/Fcntl.hsc#L116-L182. | ||
| -- | ||
| -- NOTE: in the future if we no longer support @unix@ versions @< 2.8.7@, then this module can be removed. | ||
| module System.FS.BlockIO.Internal.Fcntl (fileSetCaching) where | ||
jasagredo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #if MIN_VERSION_unix(2,8,7) | ||
|
|
||
| import System.Posix.Fcntl (fileSetCaching) | ||
|
|
||
| #else | ||
|
|
||
| #include <fcntl.h> | ||
|
|
||
| import Foreign.C (throwErrnoIfMinus1_) | ||
| import System.Posix.Internals | ||
| import System.Posix.Types (Fd (Fd)) | ||
|
|
||
| -- | For simplification, we considered that MacOS HAS_F_NOCACHE and !HAS_O_DIRECT | ||
| fileSetCaching :: Fd -> Bool -> IO () | ||
| fileSetCaching (Fd fd) val = do | ||
| throwErrnoIfMinus1_ "fileSetCaching" (c_fcntl_write fd #{const F_NOCACHE} (if val then 0 else 1)) | ||
| #endif | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.