From 6361f93fdacd59d5e8268d8d317b5ea25dcfe188 Mon Sep 17 00:00:00 2001 From: anchao Date: Sun, 26 Aug 2018 13:19:28 -0600 Subject: [PATCH] fs/vfs/fs_select.c: Make select be more consistent with Linux man page: 'The timeout ... Some code calls select() with all three sets empty, nfds zero, and a non-NULL timeout as a fairly portable way to sleep with subsecond precision.' --- fs/vfs/fs_select.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/fs/vfs/fs_select.c b/fs/vfs/fs_select.c index e7fb11cc4f..f473b57fbb 100644 --- a/fs/vfs/fs_select.c +++ b/fs/vfs/fs_select.c @@ -103,7 +103,7 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds, FAR fd_set *exceptfds, FAR struct timeval *timeout) { - struct pollfd *pollset; + struct pollfd *pollset = NULL; int errcode = OK; int fd; int npfds; @@ -133,19 +133,18 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds, } } - if (npfds <= 0) - { - errcode = EINVAL; - goto errout; - } - /* Allocate the descriptor list for poll() */ - pollset = (struct pollfd *)kmm_zalloc(npfds * sizeof(struct pollfd)); - if (!pollset) + if (npfds > 0) { - errcode = ENOMEM; - goto errout; + pollset = (FAR struct pollfd *) + kmm_zalloc(npfds * sizeof(struct pollfd)); + + if (pollset == NULL) + { + errcode = ENOMEM; + goto errout; + } } /* Initialize the descriptor list for poll() */