added usbreset.lsp
[rrq/newlisp-ftw.git] / usbreset.lsp
1 #!/usr/bin/newlisp
2
3 # libc6 library
4 (constant 'LIB "/lib/x86_64-linux-gnu/libc.so.6")
5
6 (import LIB "ioctl" "int"
7         "int" ; fd
8         "unsigned long" ; request
9         "void*" ; data [optional]
10         )
11
12 (constant
13  'USBDEVFS_RESET 21780  ; _IO('U', 20)
14  )
15
16 (define (die)
17   (write-line 2 (join (map string (args)) " "))
18   (exit 0))
19
20 (unless (setf FD (open (main-args -1) "write"))
21   (die "cannot open" (main-args -1)))
22
23 (println (ioctl FD USBDEVFS_RESET 0))
24 (exit 0)