Exemplo n.º 1
0
 @Test
 public void filestatInt() throws Throwable {
   // Windows does not store fd in FileDescriptor so this test wll not work
   if (jnr.ffi.Platform.getNativePlatform().isUnix()) {
     File f = File.createTempFile("stat", null);
     try {
       FileInputStream fis = new FileInputStream(f);
       FileDescriptor desc = fis.getFD();
       int fd = -1;
       try {
         Field fdField = FieldAccess.getProtectedField(FileDescriptor.class, "fd");
         fd = fdField.getInt(desc);
       } catch (SecurityException e) {
       } catch (IllegalArgumentException e) {
       } catch (IllegalAccessException e) {
       }
       FileStat stat = posix.allocateStat();
       int result = posix.fstat(fd, stat);
       assertTrue(fd > 2); // should not be stdin, stdout, stderr
       assertEquals(0, result);
     } finally {
       f.delete();
     }
   } else {
     FileStat stat = posix.fstat(0);
     assertTrue(stat != null);
   }
 }
Exemplo n.º 2
0
  @Test
  public void filestatDescriptor() throws Throwable {
    File f = File.createTempFile("stat", null);

    try {
      FileInputStream fis = new FileInputStream(f);
      FileStat stat = posix.allocateStat();
      int result = posix.fstat(fis.getFD(), stat);
      assertEquals(0, result);
      assertEquals(0, stat.st_size());
    } finally {
      f.delete();
    }
  }