numbers#= segmentation violation added by zilti on Fri Nov 18 13:44:21 2016

(import foreign)
;; (import foreigners)
(require-extension posix)
(require-extension ioctl)
(require-extension srfi-99)
#>
#include <errno.h>
#include <libv4l2.h>
#include <linux/videodev2.h>
#include <interface.h>
<#

(define fd (file-open "/dev/video0" open/rdwr))

(when (= -1 fd)
  (let ((errno (foreign-value "errno" int)))
    (case errno
      (((foreign-value "EACCES" int)) (error "ERROR: No permission to access the device." errno))
      (((foreign-value "EBUSY" int)) (error "ERROR: Device driver does not support multiple opens, and the device is already in use." errno))
      (((foreign-value "ENXIO" int)) (error "ERROR: No device corresponding to this device special file exists." errno))
      (((foreign-value "ENOMEM" int)) (error "ERROR: Not enough kernel memory to complete the request." errno))
      (((foreign-value "EMFILE" int)) (error "ERROR: The process already has the maximum number of files open." errno))
      (((foreign-value "ENFILE" int)) (error "ERROR: The limit on the total number of files open on the system has been reached." errno)))))