extern crate cfg_if;

cfg_if::cfg_if! {
    if #[cfg(windows)] {
        extern crate winapi_util;
        use windows as base;
        mod windows;
    } else if #[cfg(any(unix, target_os="redox"))] {
        use unix as base;
        mod unix;
    } else {
        use unsupported as base;
        mod unsupported;
    }
}

use std::fs::File;
use std::io;

#[derive(Debug, Hash, Eq, PartialEq, Copy, Clone)]
pub struct FileDescriptor {
    file_descriptor: base::FileDescriptor,
    pub device_descriptor: DeviceDescriptor,
}

#[derive(Debug, Hash, Eq, PartialEq, Copy, Clone)]
pub struct DeviceDescriptor(base::DeviceDescriptor);

impl FileDescriptor {
    pub fn from_file(file: &File) -> io::Result<FileDescriptor> {
        let file_descriptor = base::FileDescriptor::from_metadata(file.metadata()?);

        Ok(FileDescriptor {
            file_descriptor,
            device_descriptor: DeviceDescriptor(file_descriptor.dev),
        })
    }
}
