Skip to content

Instantly share code, notes, and snippets.

@lantw44
Created August 28, 2018 13:59
Show Gist options
  • Save lantw44/d440f547bdd4085998cad72bec900913 to your computer and use it in GitHub Desktop.
Save lantw44/d440f547bdd4085998cad72bec900913 to your computer and use it in GitHub Desktop.
#include <fcntl.h>
#include <linux/kd.h>
#include <locale.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
int main (int argc, char *argv[]) {
setlocale (LC_ALL, "");
if (argc < 2) {
fprintf (stderr, "Usage: %s <file> <mode>\n", argv[0]);
return 1;
}
int fd = open (argv[1], O_RDWR);
if (fd < 0) {
perror ("open");
return 2;
}
int mode;
if (ioctl (fd, KDGKBMODE, &mode) < 0) {
perror ("ioctl KDGKBMODE");
return 3;
}
printf ("%d\n", mode);
if (argc < 3) {
return 0;
}
if (sscanf (argv[2], "%d", &mode) != 1) {
perror ("sscanf");
return 4;
}
if (ioctl (fd, KDSKBMODE, mode) < 0) {
perror ("ioctl");
return 5;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment