Example #1
0
  @Test
  public void fileStatNanoTime() throws Throwable {
    // Currently only linux file stat support nano time resolution
    jnr.ffi.Platform nativePlatform = jnr.ffi.Platform.getNativePlatform();
    if (nativePlatform.getOS() == jnr.ffi.Platform.OS.LINUX) {
      File f = File.createTempFile("stat", null);
      try {
        FileStat st = posix.stat(f.getAbsolutePath());
        assertNotNull("posix.stat failed", st);

        FileStat stat = posix.allocateStat();
        int result = posix.stat(f.getAbsolutePath(), stat);
        assertNotNull("posix.stat failed", st);
        assertEquals(0, result);

        if (Platform.IS_32_BIT) {
          LinuxFileStat32 fstat32 = (LinuxFileStat32) stat;
          assertTrue(fstat32.cTimeNanoSecs() > 0);
          assertTrue(fstat32.mTimeNanoSecs() > 0);
          assertTrue(fstat32.aTimeNanoSecs() > 0);
          assertEquals(fstat32.cTimeNanoSecs(), fstat32.mTimeNanoSecs());
        } else {
          LinuxFileStat64 fstat64 = (LinuxFileStat64) stat;
          assertTrue(fstat64.cTimeNanoSecs() > 0);
          assertTrue(fstat64.mTimeNanoSecs() > 0);
          assertTrue(fstat64.aTimeNanoSecs() > 0);

          assertEquals(fstat64.cTimeNanoSecs(), fstat64.mTimeNanoSecs());
        }
      } finally {
        f.delete();
      }
    }
  }