tfutimesen.pp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. { %target=linux }
  2. uses
  3. ctypes,baseunix,linux;
  4. var
  5. un : utsname;
  6. res : cint;
  7. f1,f2 : text;
  8. err : word;
  9. mystatx1,mystatx2 : statx;
  10. times : tkernel_timespecs;
  11. st,major,minor : string;
  12. i,p,e : longint;
  13. major_release, minor_release : longint;
  14. begin
  15. fpuname(un);
  16. st:=un.release;
  17. for i:=1 to UTSNAME_LENGTH do
  18. if st[i]='.' then
  19. begin
  20. p:=i;
  21. major:=system.copy(st,1,p-1);
  22. system.val(major,major_release,err);
  23. if err<>0 then
  24. begin
  25. writeln('Unable to parse first part of linux version ',st,'(',major,') correctly');
  26. halt(2);
  27. end;
  28. break;
  29. end;
  30. for i:=p+1 to UTSNAME_LENGTH do
  31. if st[i]='.' then
  32. begin
  33. e:=i;
  34. minor:=system.copy(st,p+1,e-p-1);
  35. system.val(minor,minor_release,err);
  36. if err<>0 then
  37. begin
  38. writeln('Unable to second part of parse linux version ',st,'i(',minor,') correctly');
  39. halt(2);
  40. end;
  41. break;
  42. end;
  43. if (major_release<4) or ((major_release=4) and (minor_release<11)) then
  44. begin
  45. writeln('This version of Linux: ',st,' does not have fstatx syscall');
  46. halt(0);
  47. end
  48. else
  49. writeln('This linux version ',st,' should support statx syscall');
  50. assign(f1,'tutimensat1.txt');
  51. rewrite(f1);
  52. write(f1,'ccccc');
  53. assign(f2,'tutimensat2.txt');
  54. rewrite(f2);
  55. write(f2,'ccccc');
  56. res:=fpstatx(AT_FDCWD,'tutimensat1.txt',AT_SYMLINK_NOFOLLOW,STATX_ALL,mystatx1);
  57. if res<>0 then
  58. halt(1);
  59. times[0].tv_sec:=mystatx1.stx_atime.tv_sec;
  60. times[0].tv_nsec:=mystatx1.stx_atime.tv_nsec;
  61. times[1].tv_sec:=mystatx1.stx_mtime.tv_sec;
  62. times[1].tv_nsec:=mystatx1.stx_mtime.tv_nsec;
  63. res:=fpfutimens(textrec(f2).handle,times);
  64. if res<>0 then
  65. halt(1);
  66. res:=fpstatx(AT_FDCWD,'tutimensat2.txt',AT_SYMLINK_NOFOLLOW,STATX_ALL,mystatx2);
  67. if res<>0 then
  68. halt(1);
  69. close(f1);
  70. close(f2);
  71. erase(f1);
  72. erase(f2);
  73. if (mystatx1.stx_atime.tv_sec<>mystatx2.stx_atime.tv_sec) or (mystatx1.stx_atime.tv_nsec<>mystatx2.stx_atime.tv_nsec) or
  74. (mystatx1.stx_mtime.tv_sec<>mystatx2.stx_mtime.tv_sec) or (mystatx1.stx_mtime.tv_nsec<>mystatx2.stx_mtime.tv_nsec) then
  75. halt(1);
  76. writeln('ok');
  77. end.