B
Brice Rebsamen
Reading the code from showkey.c (from package kbd) I found this type
of code:
char *m;
m = "RAW";
See below for the complete code. How can this work? I would have used
strdup, or allocation of the memory for m (static or dynamic) then
strncpy.
Thanks
Brice
static void
get_mode(void) {
char *m;
if (ioctl(fd, KDGKBMODE, &oldkbmode)) {
perror("KDGKBMODE");
exit(1);
}
switch(oldkbmode) {
case K_RAW:
m = "RAW"; break;
case K_XLATE:
m = "XLATE"; break;
case K_MEDIUMRAW:
m = "MEDIUMRAW"; break;
case K_UNICODE:
m = "UNICODE"; break;
default:
m = _("?UNKNOWN?"); break;
}
printf(_("kb mode was %s\n"), m);
if (oldkbmode != K_XLATE) {
printf(_("[ if you are trying this under X, it might not work\n"
"since the X server is also reading /dev/console ]\n"));
}
printf("\n");
}
of code:
char *m;
m = "RAW";
See below for the complete code. How can this work? I would have used
strdup, or allocation of the memory for m (static or dynamic) then
strncpy.
Thanks
Brice
static void
get_mode(void) {
char *m;
if (ioctl(fd, KDGKBMODE, &oldkbmode)) {
perror("KDGKBMODE");
exit(1);
}
switch(oldkbmode) {
case K_RAW:
m = "RAW"; break;
case K_XLATE:
m = "XLATE"; break;
case K_MEDIUMRAW:
m = "MEDIUMRAW"; break;
case K_UNICODE:
m = "UNICODE"; break;
default:
m = _("?UNKNOWN?"); break;
}
printf(_("kb mode was %s\n"), m);
if (oldkbmode != K_XLATE) {
printf(_("[ if you are trying this under X, it might not work\n"
"since the X server is also reading /dev/console ]\n"));
}
printf("\n");
}