keyboard: check that write finished writing everything

(Use loop to write until the end)
pull/32/head
Greg V 2020-04-06 23:38:33 +03:00
parent ccc582cd58
commit fa49aca45a
1 changed files with 12 additions and 2 deletions

View File

@ -18,6 +18,7 @@
* interface. * interface.
*/ */
#include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <stdbool.h> #include <stdbool.h>
@ -175,8 +176,15 @@ int keyboard_init(struct keyboard* self, const char* layout)
if (keymap_fd < 0) if (keymap_fd < 0)
goto fd_failure; goto fd_failure;
// TODO: Check that write finished writing everything int written = 0;
write(keymap_fd, keymap_string, keymap_len); while (written < keymap_len) {
ssize_t ret = write(keymap_fd, keymap_string + written, keymap_len - written);
if (ret == -1 && errno == EINTR)
continue;
if (ret == -1)
goto write_failure;
written += ret;
}
free(keymap_string); free(keymap_string);
@ -188,6 +196,8 @@ int keyboard_init(struct keyboard* self, const char* layout)
return 0; return 0;
write_failure:
close(keymap_fd);
fd_failure: fd_failure:
free(keymap_string); free(keymap_string);
keymap_string_failure: keymap_string_failure: