Cover V02, I02
Article
Listing 1

mar93.tar


Listing 1: numlock.c

/*  NUMLOCK.C
*
*  Turns on the keypad numlock key for the named tty device.  The tty
*  device must be either a virtual terminal (contain "vt" in the name)
*  or be the console, otherwise there is no support for the KDSETLED
*  ioctl() call.
*
*  Copyright 1992 by Lawrence S Reznick
*/

#include    <stdio.h>
#include    <string.h>
#include    <fcntl.h>
#include    <sys/types.h>
#include    <sys/at_ansi.h>
#include    <sys/kd.h>

main(int argc, char **argv)
{
int fd;

if (argc < 2) {
fputs("Usage:\t", stderr);
fputs(argv[0], stderr);
fputs(" `tty`\n\nTurns on numlock for the tty named\n\n",
stderr);
exit(1);
}

if (strstr(argv[1], "vt") == NULL && strstr(argv[1], "console") == NULL) {
fputs(argv[1], stderr);
fputs(" is neither a virtual terminal nor the console.\n", stderr);
exit(1);
}

if ((fd = open(argv[1], O_WRONLY)) == -1) {
fputs(argv[0], stderr);
fputs(": Error opening ", stderr);
perror(argv[1]);
exit(2);
}

if (ioctl(fd, KDSETLED, LED_NUM) == -1) {
perror("ioctl error");
exit(3);
}

return(0);
}