diff --git a/.gitattributes b/.gitattributes index 8e2711c015..63d80afab1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -16245,6 +16245,7 @@ tests/test/units/sysutils/tfexpand2.pp svneol=native#text/plain tests/test/units/sysutils/tffirst.pp svneol=native#text/plain tests/test/units/sysutils/tfile1.pp svneol=native#text/plain tests/test/units/sysutils/tfile2.pp svneol=native#text/plain +tests/test/units/sysutils/tfileage.pp svneol=native#text/pascal tests/test/units/sysutils/tfilename.pp svneol=native#text/plain tests/test/units/sysutils/tfloattostr.pp svneol=native#text/plain tests/test/units/sysutils/tformat.pp svneol=native#text/plain diff --git a/rtl/unix/sysutils.pp b/rtl/unix/sysutils.pp index 68520a7e99..ee4b500ef1 100644 --- a/rtl/unix/sysutils.pp +++ b/rtl/unix/sysutils.pp @@ -55,6 +55,10 @@ uses {$DEFINE HAVECLOCKGETTIME} {$ENDIF} +{$if defined(LINUX)} +{$DEFINE HAS_STATX} +{$endif} + { Include platform independent interface part } {$i sysutilh.inc} @@ -547,12 +551,26 @@ begin end; end; + Function FileAge (Const FileName : RawByteString): Int64; Var Info : Stat; SystemFileName: RawByteString; +{$ifdef HAS_STATX} + Infox : Statx; +{$endif HAS_STATX} begin SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName); + +{$ifdef HAS_STATX} + { first try statx } + if (Fpstatx(0,pchar(SystemFileName),0,STATX_MTIME or STATX_MODE,Infox)>=0) and not(fpS_ISDIR(Infox.stx_mode)) then + begin + Result:=Infox.stx_mtime.tv_sec; + exit; + end; +{$endif HAS_STATX} + If (fpstat(pchar(SystemFileName),Info)<0) or fpS_ISDIR(info.st_mode) then exit(-1) else diff --git a/tests/test/units/sysutils/tfileage.pp b/tests/test/units/sysutils/tfileage.pp new file mode 100644 index 0000000000..050f75a5d1 --- /dev/null +++ b/tests/test/units/sysutils/tfileage.pp @@ -0,0 +1,10 @@ +uses + sysutils; +begin + if 3600*24*(now()-FileDateToDateTime(FileAge(paramstr(0))))>7200 then + begin + writeln('FileAge returns: ',FileDateToDateTime(FileAge(paramstr(0)))); + writeln('Compilation time and run time differ too much, SysUtils.FileAge buggy?'); + halt(1); + end; +end.