core: code shrink
authorBartosz Golaszewski <bartekgola@gmail.com>
Wed, 8 Feb 2017 10:21:41 +0000 (11:21 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Wed, 8 Feb 2017 10:21:41 +0000 (11:21 +0100)
Use the ternary operator instead of an if-else.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
src/lib/core.c

index 9204210804c4f7fab3f4a1f091e14488ff0b030f..c88697ceb8dd641ba7342dcf7c8cdbbab66beaca 100644 (file)
@@ -342,18 +342,14 @@ static void line_set_state(struct gpiod_line *line, int state)
 
 static int line_get_handle_fd(struct gpiod_line *line)
 {
-       if (line_get_state(line) != LINE_TAKEN)
-               return -1;
-       else
-               return line->handle->request.fd;
+       int state = line_get_state(line);
+
+       return state == LINE_TAKEN ? line->handle->request.fd : -1;
 }
 
 static int line_get_event_fd(struct gpiod_line *line)
 {
-       if (line_get_state(line) != LINE_EVENT)
-               return -1;
-       else
-               return line->event.fd;
+       return line_get_state(line) == LINE_EVENT ? line->event.fd : -1;
 }
 
 static void line_set_handle(struct gpiod_line *line,