more OsPath conversion

Sponsored-by: Leon Schuermann
This commit is contained in:
Joey Hess 2025-02-04 16:09:47 -04:00
parent 54f0710fd2
commit 4dc904bbad
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
8 changed files with 69 additions and 66 deletions

View file

@ -25,6 +25,7 @@ module Utility.OsPath (
import Utility.FileSystemEncoding
import Data.ByteString.Short (ShortByteString)
import qualified Data.ByteString.Short as S
import qualified Data.ByteString.Lazy as L
#ifdef WITH_OSPATH
import System.OsPath as X hiding (OsPath, OsString, unsafeFromChar)
import System.OsPath
@ -70,6 +71,10 @@ instance OsPathConv ShortByteString where
fromOsPath = bytesFromOsPath
#endif
instance OsPathConv L.ByteString where
toOsPath = toOsPath . L.toStrict
fromOsPath = L.fromStrict . fromOsPath
#if defined(mingw32_HOST_OS)
-- On Windows, OsString contains a ShortByteString that is
-- utf-16 encoded. But the input RawFilePath is assumed to
@ -115,6 +120,10 @@ instance OsPathConv ShortByteString where
toOsPath = S.fromShort
fromOsPath = S.toShort
instance OsPathConv L.ByteString where
toOsPath = L.toStrict
fromOsPath = L.fromStrict
unsafeFromChar :: Char -> Word8
unsafeFromChar = fromIntegral . ord