Build on API 21 headers

This commit is contained in:
topjohnwu
2021-10-20 03:17:42 -07:00
parent 62e464f706
commit 770b28ca30
38 changed files with 115 additions and 142 deletions

View File

@@ -8,6 +8,7 @@
#include <sys/mman.h>
#include <sys/sendfile.h>
#include <sys/ptrace.h>
#include <sys/inotify.h>
#include <utils.hpp>
@@ -198,26 +199,9 @@ int xlisten(int sockfd, int backlog) {
return ret;
}
static int accept4_compat(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
int fd = accept(sockfd, addr, addrlen);
if (fd < 0) {
PLOGE("accept");
} else {
if (flags & SOCK_CLOEXEC)
fcntl(fd, F_SETFD, FD_CLOEXEC);
if (flags & SOCK_NONBLOCK) {
int i = fcntl(fd, F_GETFL);
fcntl(fd, F_SETFL, i | O_NONBLOCK);
}
}
return fd;
}
int xaccept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
int fd = accept4(sockfd, addr, addrlen, flags);
if (fd < 0) {
if (errno == ENOSYS)
return accept4_compat(sockfd, addr, addrlen, flags);
PLOGE("accept4");
}
return fd;