changed fopen to open

xkbcommon
Alessandro Mauri 5 years ago
parent 9ee3410975
commit 4f3a2daddf
  1. 1
      .gitignore
  2. BIN
      .macrod.c.swp
  3. 28
      macrod.c

1
.gitignore vendored

@ -1 +1,2 @@
*.out *.out
*.swp

Binary file not shown.

@ -3,9 +3,12 @@
#include <string.h> #include <string.h>
/* Standard errors */ /* Standard errors */
#include <errno.h> #include <errno.h>
/* Directory control */ /* Directory and file control */
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h> #include <dirent.h>
#include <unistd.h>
#ifdef __linux__ #ifdef __linux__
#include <linux/input.h> #include <linux/input.h>
@ -24,18 +27,29 @@ int pressBufferRemove (struct pressed_buffer*, unsigned short);
int main (void) // remember getopt() to automaically parse options int main (void) // remember getopt() to automaically parse options
{ {
FILE *fp; int fd;
fp = fopen("/dev/input/event0", "r"); fd = open("/dev/input/event0", O_RDONLY); // TEST: O_NONBLOCK
if (fp == NULL) { if (!fd) {
fputs(strerror(errno), stderr); fputs(strerror(errno), stderr);
exit(errno); exit(errno);
} }
//int f2 = open("/dev/input/event3", O_RDONLY);
//struct input_event ev;
struct input_event event; struct input_event event;
struct pressed_buffer pb = {NULL, 0}; // Pressed keys buffer struct pressed_buffer pb = {NULL, 0}; // Pressed keys buffer
while (!ferror(fp)) { while (1) {
fread(&event, sizeof(struct input_event), 1, fp); /* Use polling poll(2) to wait por a file dscriptor to become ready for reading.
* NOTE: this could use select(2) but I don't know how */
//fread(&event, sizeof(struct input_event), 1, fp);
ssize_t rb;
rb = read(fd, &event, sizeof(struct input_event));
if (rb != sizeof(struct input_event)) continue;
if (event.type == EV_KEY) { if (event.type == EV_KEY) {
switch (event.value) { switch (event.value) {
@ -54,7 +68,7 @@ int main (void) // remember getopt() to automaically parse options
} }
} }
if (fclose(fp) == EOF) { if (close(fd) == -1) {
fputs(strerror(errno), stderr); fputs(strerror(errno), stderr);
exit(errno); exit(errno);
} }

Loading…
Cancel
Save