]> git.ipfire.org Git - thirdparty/util-linux.git/blame - historic/lpcntl.c
Imported from util-linux-2.5 tarball.
[thirdparty/util-linux.git] / historic / lpcntl.c
CommitLineData
726f69e2
KZ
1/*
2 * Simple command interface to ioctl(fd, LPSETIRQ, irq).
3 * Nigel Gamble (nigel@gate.net)
4 * e.g.
5 * lpcntl /dev/lp1 7
6 */
7
8#include <stdio.h>
9#include <fcntl.h>
10#include <errno.h>
11#include <linux/lp.h>
12
13int
14main(int argc, char **argv)
15{
16 unsigned int irq;
17 int fd;
18 int ret;
19
20 if (argc < 2) {
21 fprintf(stderr, "usage: %s <lp device> [<irq>]\n", argv[0]);
22 exit(1);
23 }
24
25 fd = open(argv[1], O_RDONLY);
26 if (fd == -1) {
27 perror(argv[1]);
28 exit(1);
29 }
30
31 if (argc == 2) {
32 irq = ioctl(fd, LPGETIRQ);
33 if (irq == -1) {
34 perror(argv[1]);
35 exit(1);
36 }
37 if (irq)
38 printf("%s using IRQ %d\n", argv[1], irq);
39 else
40 printf("%s using polling\n", argv[1]);
41 } else {
42 irq = atoi(argv[2]);
43 ret = ioctl(fd, LPSETIRQ, irq);
44 if (ret == -1) {
45 if (errno == EPERM)
46 fprintf(stderr, "%s: only super-user can change the IRQ\n", argv[0]);
47 else
48 perror(argv[1]);
49 exit(1);
50 }
51 }
52
53 return 0;
54}