static int OpenRestricted(IntPtr path, int flags, IntPtr userData) { var fd = NativeUnsafeMethods.open(Marshal.PtrToStringAnsi(path), flags, 0); if (fd == -1) { return(-Marshal.GetLastWin32Error()); } return(fd); }
public static EvDevDevice Open(string device) { var fd = NativeUnsafeMethods.open(device, 2048, 0); if (fd <= 0) { throw new Exception($"Unable to open {device} code {Marshal.GetLastWin32Error()}"); } IntPtr dev; var rc = NativeUnsafeMethods.libevdev_new_from_fd(fd, out dev); if (rc < 0) { NativeUnsafeMethods.close(fd); throw new Exception($"Unable to initialize evdev for {device} code {Marshal.GetLastWin32Error()}"); } return(new EvDevDevice(fd, dev)); }