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.'
This commit is contained in:
anchao
2018-08-26 13:19:28 -06:00
committed by Gregory Nutt
parent 8530fe0a7c
commit 6361f93fda
+10 -11
View File
@@ -103,7 +103,7 @@
int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds, int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds,
FAR fd_set *exceptfds, FAR struct timeval *timeout) FAR fd_set *exceptfds, FAR struct timeval *timeout)
{ {
struct pollfd *pollset; struct pollfd *pollset = NULL;
int errcode = OK; int errcode = OK;
int fd; int fd;
int npfds; 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() */ /* Allocate the descriptor list for poll() */
pollset = (struct pollfd *)kmm_zalloc(npfds * sizeof(struct pollfd)); if (npfds > 0)
if (!pollset)
{ {
errcode = ENOMEM; pollset = (FAR struct pollfd *)
goto errout; kmm_zalloc(npfds * sizeof(struct pollfd));
if (pollset == NULL)
{
errcode = ENOMEM;
goto errout;
}
} }
/* Initialize the descriptor list for poll() */ /* Initialize the descriptor list for poll() */