Skip to content

Commit d7ea7ed

Browse files
committed
Add accessors for st_blocks and st_blksize
1 parent af92f9b commit d7ea7ed

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

System/Posix/Files.hsc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ module System.Posix.Files (
6363
isBlockDevice, isCharacterDevice, isNamedPipe, isRegularFile,
6464
isDirectory, isSymbolicLink, isSocket,
6565

66+
#if MIN_VERSION_base(4,10,0)
67+
fileBlockSize,
68+
fileBlocks,
69+
#endif
70+
6671
-- * Creation
6772
createNamedPipe,
6873
createDevice,

System/Posix/Files/ByteString.hsc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ module System.Posix.Files.ByteString (
6363
isBlockDevice, isCharacterDevice, isNamedPipe, isRegularFile,
6464
isDirectory, isSymbolicLink, isSocket,
6565

66+
#if MIN_VERSION_base(4,10,0)
67+
fileBlockSize,
68+
fileBlocks,
69+
#endif
70+
6671
-- * Creation
6772
createNamedPipe,
6873
createDevice,

System/Posix/Files/Common.hsc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ module System.Posix.Files.Common (
5656
isBlockDevice, isCharacterDevice, isNamedPipe, isRegularFile,
5757
isDirectory, isSymbolicLink, isSocket,
5858

59+
#if MIN_VERSION_base(4,10,0)
60+
fileBlockSize,
61+
fileBlocks,
62+
#endif
63+
5964
-- * Setting file sizes
6065
setFdSize,
6166

@@ -255,6 +260,16 @@ specialDeviceID :: FileStatus -> DeviceID
255260
-- | Size of the file in bytes. If this file is a symbolic link the size is
256261
-- the length of the pathname it contains.
257262
fileSize :: FileStatus -> FileOffset
263+
#if MIN_VERSION_base(4,10,0)
264+
-- | Number of blocks allocated for this file, in units of
265+
-- 512-bytes. Returns @Nothing@ if @st_blocks@ is not supported on this
266+
-- platform.
267+
fileBlocks :: FileStatus -> Maybe CBlkCnt
268+
-- | Gives the preferred block size for efficient filesystem I/O in
269+
-- bytes. Returns @Nothing@ if @st_blocksize@ is not supported on this
270+
-- platform.
271+
fileBlockSize :: FileStatus -> Maybe CBlkSize
272+
#endif
258273
-- | Time of last access.
259274
accessTime :: FileStatus -> EpochTime
260275
-- | Time of last access in sub-second resolution. Depends on the timestamp resolution of the
@@ -294,6 +309,21 @@ modificationTime (FileStatus stat) =
294309
statusChangeTime (FileStatus stat) =
295310
unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_ctime)
296311

312+
#if MIN_VERSION_base(4,10,0)
313+
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
314+
fileBlocks (FileStatus stat) =
315+
Just $ unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_blocks)
316+
#else
317+
fileBlocks _ = Nothing
318+
#endif
319+
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
320+
fileBlockSize (FileStatus stat) =
321+
Just $ unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_blksize)
322+
#else
323+
fileBlockSize _ = Nothing
324+
#endif
325+
#endif
326+
297327
accessTimeHiRes (FileStatus stat) =
298328
unsafePerformIO $ withForeignPtr stat $ \stat_ptr -> do
299329
sec <- (#peek struct stat, st_atime) stat_ptr :: IO EpochTime

configure.ac

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ AC_CHECK_MEMBERS([struct stat.st_uatime])
6666
AC_CHECK_MEMBERS([struct stat.st_umtime])
6767
AC_CHECK_MEMBERS([struct stat.st_uctime])
6868

69+
AC_CHECK_MEMBERS([struct stat.st_blocks])
70+
AC_CHECK_MEMBERS([struct stat.st_blksize])
71+
6972
AC_CHECK_MEMBER([struct passwd.pw_gecos], [], [AC_DEFINE([HAVE_NO_PASSWD_PW_GECOS],[],[Ignore the pw_gecos member of passwd where it does not exist])], [[#include <pwd.h>]])
7073

7174
# Functions for changing file timestamps

0 commit comments

Comments
 (0)