[commit: packages/Win32] ghc-head: add support from GetFileAttributesEx (low level only) (66437bf)
git at git.haskell.org
git at git.haskell.org
Tue Mar 18 10:16:01 UTC 2014
Repository : ssh://git@git.haskell.org/Win32
On branch : ghc-head
Link : http://git.haskell.org/packages/Win32.git/commitdiff/66437bfa67a6e63e092f9dc8b96c586311c5c58b
>---------------------------------------------------------------
commit 66437bfa67a6e63e092f9dc8b96c586311c5c58b
Author: Marios Titas <redneb at gmx.com>
Date: Thu Jun 6 19:48:09 2013 -0400
add support from GetFileAttributesEx (low level only)
>---------------------------------------------------------------
66437bfa67a6e63e092f9dc8b96c586311c5c58b
System/Win32/File.hsc | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/System/Win32/File.hsc b/System/Win32/File.hsc
index b0e0ad2..b419875 100644
--- a/System/Win32/File.hsc
+++ b/System/Win32/File.hsc
@@ -207,6 +207,16 @@ type FileType = DWORD
----------------------------------------------------------------
+newtype GET_FILEEX_INFO_LEVELS = GET_FILEEX_INFO_LEVELS (#type GET_FILEEX_INFO_LEVELS)
+ deriving (Eq, Ord)
+
+#{enum GET_FILEEX_INFO_LEVELS, GET_FILEEX_INFO_LEVELS
+ , getFileExInfoStandard = GetFileExInfoStandard
+ , getFileExMaxInfoLevel = GetFileExMaxInfoLevel
+ }
+
+----------------------------------------------------------------
+
type LPSECURITY_ATTRIBUTES = Ptr ()
type MbLPSECURITY_ATTRIBUTES = Maybe LPSECURITY_ATTRIBUTES
@@ -256,6 +266,37 @@ instance Storable BY_HANDLE_FILE_INFORMATION where
(dwordsToDdword (fshi,fslo)) link (dwordsToDdword (idhi,idlo))
----------------------------------------------------------------
+
+data WIN32_FILE_ATTRIBUTE_DATA = WIN32_FILE_ATTRIBUTE_DATA
+ { fadFileAttributes :: DWORD
+ , fadCreationTime , fadLastAccessTime , fadLastWriteTime :: FILETIME
+ , fadFileSize :: DDWORD
+ } deriving (Show)
+
+instance Storable WIN32_FILE_ATTRIBUTE_DATA where
+ sizeOf = const (#size WIN32_FILE_ATTRIBUTE_DATA)
+ alignment = sizeOf
+ poke buf ad = do
+ (#poke WIN32_FILE_ATTRIBUTE_DATA, dwFileAttributes) buf (fadFileAttributes ad)
+ (#poke WIN32_FILE_ATTRIBUTE_DATA, ftCreationTime) buf (fadCreationTime ad)
+ (#poke WIN32_FILE_ATTRIBUTE_DATA, ftLastAccessTime) buf (fadLastAccessTime ad)
+ (#poke WIN32_FILE_ATTRIBUTE_DATA, ftLastWriteTime) buf (fadLastWriteTime ad)
+ (#poke WIN32_FILE_ATTRIBUTE_DATA, nFileSizeHigh) buf sizeHi
+ (#poke WIN32_FILE_ATTRIBUTE_DATA, nFileSizeLow) buf sizeLo
+ where
+ (sizeHi,sizeLo) = ddwordToDwords $ fadFileSize ad
+
+ peek buf = do
+ attr <- (#peek WIN32_FILE_ATTRIBUTE_DATA, dwFileAttributes) buf
+ ctim <- (#peek WIN32_FILE_ATTRIBUTE_DATA, ftCreationTime) buf
+ lati <- (#peek WIN32_FILE_ATTRIBUTE_DATA, ftLastAccessTime) buf
+ lwti <- (#peek WIN32_FILE_ATTRIBUTE_DATA, ftLastWriteTime) buf
+ fshi <- (#peek WIN32_FILE_ATTRIBUTE_DATA, nFileSizeHigh) buf
+ fslo <- (#peek WIN32_FILE_ATTRIBUTE_DATA, nFileSizeLow) buf
+ return $ WIN32_FILE_ATTRIBUTE_DATA attr ctim lati lwti
+ (dwordsToDdword (fshi,fslo))
+
+----------------------------------------------------------------
-- File operations
----------------------------------------------------------------
@@ -421,6 +462,9 @@ getFileAttributes name =
foreign import WINDOWS_CCONV unsafe "windows.h GetFileAttributesW"
c_GetFileAttributes :: LPCTSTR -> IO FileAttributeOrFlag
+foreign import WINDOWS_CCONV unsafe "windows.h GetFileAttributesExW"
+ c_GetFileAttributesEx :: LPCTSTR -> GET_FILEEX_INFO_LEVELS -> Ptr a -> IO BOOL
+
getFileInformationByHandle :: HANDLE -> IO BY_HANDLE_FILE_INFORMATION
getFileInformationByHandle h = alloca $ \res -> do
failIfFalseWithRetry_ "GetFileInformationByHandle" $ c_GetFileInformationByHandle h res
More information about the ghc-commits
mailing list