Luna/apps/src/block.c

34 lines
504 B
C

#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
int fd = open("/dev/kbd", O_RDONLY | O_NONBLOCK);
if (fd < 0)
{
perror("open");
return 1;
}
FILE* fp = fdopen(fd, "r");
if (!fp)
{
perror("fdopen");
close(fd);
return 1;
}
char buf[32];
fread(buf, sizeof(buf) - 1, 1, fp);
if (ferror(fp))
{
perror("fread");
fclose(fp);
return 1;
}
fclose(fp);
return 0;
}