RosettaCodeData/Task/File-modification-time/Perl-6/file-modification-time.pl6

22 lines
452 B
Raku
Raw Permalink Normal View History

2013-04-10 22:43:41 -07:00
use NativeCall;
class utimbuf is repr('CStruct') {
has int $.actime;
has int $.modtime;
submethod BUILD(:$atime, :$mtime) {
$!actime = $atime;
2016-12-05 22:15:40 +01:00
$!modtime = $mtime.to-posix[0].round;
2013-04-10 22:43:41 -07:00
}
}
2018-06-22 20:57:24 +00:00
sub sysutime(Str, utimbuf --> int32) is native is symbol('utime') {*}
2013-04-10 22:43:41 -07:00
sub MAIN (Str $file) {
2019-09-12 10:33:56 -07:00
my $mtime = $file.IO.modified orelse .die;
2013-04-10 22:43:41 -07:00
my $ubuff = utimbuf.new(:atime(time),:mtime($mtime));
sysutime($file, $ubuff);
}