Add epoll and do more release readiness changes

This change also pays off some of the remaining technical debt with
stdio, file descriptors, and memory managemnt polyfills.
This commit is contained in:
Justine Tunney 2020-11-28 12:01:51 -08:00
parent a9ea949df8
commit 3e4fd4b0ad
271 changed files with 5706 additions and 1365 deletions

View file

@ -17,17 +17,8 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/assert.h"
#include "libc/bits/weaken.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/iovec.h"
#include "libc/dce.h"
#include "libc/macros.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/internal.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.h"
#include "libc/sock/sock.h"
/**
* Reads data from file descriptor.
@ -41,24 +32,5 @@
* @asyncsignalsafe
*/
ssize_t read(int fd, void *buf, size_t size) {
ssize_t rc;
if (fd == -1) return einval();
if (isfdkind(fd, kFdZip)) {
rc =
weaken(__zipos_read)((struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle,
(struct iovec[]){{buf, size}}, 1, -1);
} else if (!IsWindows()) {
rc = read$sysv(fd, buf, size);
} else if (isfdkind(fd, kFdFile) || isfdkind(fd, kFdConsole)) {
rc = read$nt(&g_fds.p[fd], (struct iovec[]){{buf, size}}, 1, -1);
} else if (isfdkind(fd, kFdSocket)) {
rc = weaken(recvfrom$nt)(&g_fds.p[fd], (struct iovec[]){{buf, size}}, 1, 0,
NULL, NULL);
} else {
rc = ebadf();
}
if (!IsTrustworthy() && rc != -1) {
if ((size_t)rc > size) abort();
}
return rc;
return readv(fd, &(struct iovec){buf, size}, 1);
}