From 53dfb21d6c227ee940fd20fdce321f19f8c656b9 Mon Sep 17 00:00:00 2001 From: Charles Blake Date: Tue, 7 Feb 2017 09:00:19 -0500 Subject: Move Timespec up, use in Stat for st_?tim and define accessors for the seconds portion of the Timespec. --- lib/posix/posix.nim | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/posix/posix.nim b/lib/posix/posix.nim index 716f625e7..9338fcd99 100644 --- a/lib/posix/posix.nim +++ b/lib/posix/posix.nim @@ -101,6 +101,11 @@ type {.deprecated: [TSocketHandle: SocketHandle].} type + Timespec* {.importc: "struct timespec", + header: "", final, pure.} = object ## struct timespec + tv_sec*: Time ## Seconds. + tv_nsec*: int ## Nanoseconds. + Dirent* {.importc: "struct dirent", header: "", final, pure.} = object ## dirent_t struct d_ino*: Ino ## File serial number. @@ -270,9 +275,9 @@ type ## For a typed memory object, the length in bytes. ## For other file types, the use of this field is ## unspecified. - st_atime*: Time ## Time of last access. - st_mtime*: Time ## Time of last data modification. - st_ctime*: Time ## Time of last status change. + st_atim*: Timespec ## Time of last access. + st_mtim*: Timespec ## Time of last data modification. + st_ctim*: Timespec ## Time of last status change. st_blksize*: Blksize ## A file system-specific preferred I/O block size ## for this object. In some file system types, this ## may vary from file to file. @@ -311,10 +316,6 @@ type tm_wday*: cint ## Day of week [0,6] (Sunday =0). tm_yday*: cint ## Day of year [0,365]. tm_isdst*: cint ## Daylight Savings flag. - Timespec* {.importc: "struct timespec", - header: "", final, pure.} = object ## struct timespec - tv_sec*: Time ## Seconds. - tv_nsec*: int ## Nanoseconds. Itimerspec* {.importc: "struct itimerspec", header: "", final, pure.} = object ## struct itimerspec it_interval*: Timespec ## Timer period. @@ -1609,6 +1610,16 @@ var MSG_OOB* {.importc, header: "".}: cint ## Out-of-band data. +proc st_atime*(s: Stat): Time {.inline.} = + ## Second-granularity time of last access + result = s.st_atim.tv_sec +proc st_mtime*(s: Stat): Time {.inline.} = + ## Second-granularity time of last data modification. + result = s.st_mtim.tv_sec +proc st_ctime*(s: Stat): Time {.inline.} = + ## Second-granularity time of last status change. + result = s.st_ctim.tv_sec + proc WIFCONTINUED*(s:cint) : bool {.importc, header: "".} ## True if child has been continued. proc WIFEXITED*(s:cint) : bool {.importc, header: "".} -- cgit 1.4.1-2-gfad0 From 3680cbaf25a1b25fa14c82be249ef0eca235f0de Mon Sep 17 00:00:00 2001 From: Charles Blake Date: Tue, 7 Feb 2017 09:39:41 -0500 Subject: Use old approach for Mac OSX which, as of 2016, does not yet support POSIX high-resolution file times. --- lib/posix/posix.nim | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/posix/posix.nim b/lib/posix/posix.nim index 9338fcd99..a08da2dfa 100644 --- a/lib/posix/posix.nim +++ b/lib/posix/posix.nim @@ -275,9 +275,14 @@ type ## For a typed memory object, the length in bytes. ## For other file types, the use of this field is ## unspecified. - st_atim*: Timespec ## Time of last access. - st_mtim*: Timespec ## Time of last data modification. - st_ctim*: Timespec ## Time of last status change. + when defined(macosx): + st_atime*: Time ## Time of last access. + st_mtime*: Time ## Time of last data modification. + st_ctime*: Time ## Time of last status change. + else: + st_atim*: Timespec ## Time of last access. + st_mtim*: Timespec ## Time of last data modification. + st_ctim*: Timespec ## Time of last status change. st_blksize*: Blksize ## A file system-specific preferred I/O block size ## for this object. In some file system types, this ## may vary from file to file. @@ -1610,15 +1615,16 @@ var MSG_OOB* {.importc, header: "".}: cint ## Out-of-band data. -proc st_atime*(s: Stat): Time {.inline.} = - ## Second-granularity time of last access - result = s.st_atim.tv_sec -proc st_mtime*(s: Stat): Time {.inline.} = - ## Second-granularity time of last data modification. - result = s.st_mtim.tv_sec -proc st_ctime*(s: Stat): Time {.inline.} = - ## Second-granularity time of last status change. - result = s.st_ctim.tv_sec +when not defined(macosx): + proc st_atime*(s: Stat): Time {.inline.} = + ## Second-granularity time of last access + result = s.st_atim.tv_sec + proc st_mtime*(s: Stat): Time {.inline.} = + ## Second-granularity time of last data modification. + result = s.st_mtim.tv_sec + proc st_ctime*(s: Stat): Time {.inline.} = + ## Second-granularity time of last status change. + result = s.st_ctim.tv_sec proc WIFCONTINUED*(s:cint) : bool {.importc, header: "".} ## True if child has been continued. -- cgit 1.4.1-2-gfad0