mirror of
https://github.com/jjsullivan5196/wvkbd.git
synced 2025-07-12 22:14:32 +02:00
Simplest clang-format
This commit is contained in:
@ -34,90 +34,85 @@
|
||||
|
||||
#include "os-compatibility.h"
|
||||
|
||||
int
|
||||
os_fd_set_cloexec(int fd) {
|
||||
long flags;
|
||||
int os_fd_set_cloexec(int fd) {
|
||||
long flags;
|
||||
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
|
||||
flags = fcntl(fd, F_GETFD);
|
||||
if (flags == -1)
|
||||
return -1;
|
||||
flags = fcntl(fd, F_GETFD);
|
||||
if (flags == -1)
|
||||
return -1;
|
||||
|
||||
if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1)
|
||||
return -1;
|
||||
if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
set_cloexec_or_close(int fd) {
|
||||
if (os_fd_set_cloexec(fd) != 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
return fd;
|
||||
static int set_cloexec_or_close(int fd) {
|
||||
if (os_fd_set_cloexec(fd) != 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
int
|
||||
os_socketpair_cloexec(int domain, int type, int protocol, int *sv) {
|
||||
int ret;
|
||||
int os_socketpair_cloexec(int domain, int type, int protocol, int *sv) {
|
||||
int ret;
|
||||
|
||||
#ifdef SOCK_CLOEXEC
|
||||
ret = socketpair(domain, type | SOCK_CLOEXEC, protocol, sv);
|
||||
if (ret == 0 || errno != EINVAL)
|
||||
return ret;
|
||||
ret = socketpair(domain, type | SOCK_CLOEXEC, protocol, sv);
|
||||
if (ret == 0 || errno != EINVAL)
|
||||
return ret;
|
||||
#endif
|
||||
|
||||
ret = socketpair(domain, type, protocol, sv);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
ret = socketpair(domain, type, protocol, sv);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
sv[0] = set_cloexec_or_close(sv[0]);
|
||||
sv[1] = set_cloexec_or_close(sv[1]);
|
||||
sv[0] = set_cloexec_or_close(sv[0]);
|
||||
sv[1] = set_cloexec_or_close(sv[1]);
|
||||
|
||||
if (sv[0] != -1 && sv[1] != -1)
|
||||
return 0;
|
||||
if (sv[0] != -1 && sv[1] != -1)
|
||||
return 0;
|
||||
|
||||
close(sv[0]);
|
||||
close(sv[1]);
|
||||
return -1;
|
||||
close(sv[0]);
|
||||
close(sv[1]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
os_epoll_create_cloexec(void) {
|
||||
int fd;
|
||||
int os_epoll_create_cloexec(void) {
|
||||
int fd;
|
||||
|
||||
#ifdef EPOLL_CLOEXEC
|
||||
fd = epoll_create1(EPOLL_CLOEXEC);
|
||||
if (fd >= 0)
|
||||
return fd;
|
||||
if (errno != EINVAL)
|
||||
return -1;
|
||||
fd = epoll_create1(EPOLL_CLOEXEC);
|
||||
if (fd >= 0)
|
||||
return fd;
|
||||
if (errno != EINVAL)
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
fd = epoll_create(1);
|
||||
return set_cloexec_or_close(fd);
|
||||
fd = epoll_create(1);
|
||||
return set_cloexec_or_close(fd);
|
||||
}
|
||||
|
||||
static int
|
||||
create_tmpfile_cloexec(char *tmpname) {
|
||||
int fd;
|
||||
static int create_tmpfile_cloexec(char *tmpname) {
|
||||
int fd;
|
||||
|
||||
#ifdef HAVE_MKOSTEMP
|
||||
fd = mkostemp(tmpname, O_CLOEXEC);
|
||||
if (fd >= 0)
|
||||
unlink(tmpname);
|
||||
fd = mkostemp(tmpname, O_CLOEXEC);
|
||||
if (fd >= 0)
|
||||
unlink(tmpname);
|
||||
#else
|
||||
fd = mkstemp(tmpname);
|
||||
if (fd >= 0) {
|
||||
fd = set_cloexec_or_close(fd);
|
||||
unlink(tmpname);
|
||||
}
|
||||
fd = mkstemp(tmpname);
|
||||
if (fd >= 0) {
|
||||
fd = set_cloexec_or_close(fd);
|
||||
unlink(tmpname);
|
||||
}
|
||||
#endif
|
||||
|
||||
return fd;
|
||||
return fd;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -141,61 +136,59 @@ create_tmpfile_cloexec(char *tmpname) {
|
||||
* If posix_fallocate() is not supported, program may receive
|
||||
* SIGBUS on accessing mmap()'ed file contents instead.
|
||||
*/
|
||||
int
|
||||
os_create_anonymous_file(off_t size) {
|
||||
static const char template[] = "/weston-shared-XXXXXX";
|
||||
const char *path;
|
||||
char *name;
|
||||
int fd;
|
||||
int ret;
|
||||
int os_create_anonymous_file(off_t size) {
|
||||
static const char template[] = "/weston-shared-XXXXXX";
|
||||
const char *path;
|
||||
char *name;
|
||||
int fd;
|
||||
int ret;
|
||||
|
||||
path = getenv("XDG_RUNTIME_DIR");
|
||||
if (!path) {
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
path = getenv("XDG_RUNTIME_DIR");
|
||||
if (!path) {
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
name = malloc(strlen(path) + sizeof(template));
|
||||
if (!name)
|
||||
return -1;
|
||||
name = malloc(strlen(path) + sizeof(template));
|
||||
if (!name)
|
||||
return -1;
|
||||
|
||||
strcpy(name, path);
|
||||
strcat(name, template);
|
||||
strcpy(name, path);
|
||||
strcat(name, template);
|
||||
|
||||
fd = create_tmpfile_cloexec(name);
|
||||
fd = create_tmpfile_cloexec(name);
|
||||
|
||||
free(name);
|
||||
free(name);
|
||||
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
|
||||
#ifdef HAVE_POSIX_FALLOCATE
|
||||
do {
|
||||
ret = posix_fallocate(fd, 0, size);
|
||||
} while (ret == EINTR);
|
||||
if (ret != 0) {
|
||||
close(fd);
|
||||
errno = ret;
|
||||
return -1;
|
||||
}
|
||||
do {
|
||||
ret = posix_fallocate(fd, 0, size);
|
||||
} while (ret == EINTR);
|
||||
if (ret != 0) {
|
||||
close(fd);
|
||||
errno = ret;
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
do {
|
||||
ret = ftruncate(fd, size);
|
||||
} while (ret < 0 && errno == EINTR);
|
||||
if (ret < 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
do {
|
||||
ret = ftruncate(fd, size);
|
||||
} while (ret < 0 && errno == EINTR);
|
||||
if (ret < 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return fd;
|
||||
return fd;
|
||||
}
|
||||
|
||||
#ifndef MISSING_STRCHRNUL
|
||||
char *
|
||||
strchrnul(const char *s, int c) {
|
||||
while (*s && *s != c)
|
||||
s++;
|
||||
return (char *)s;
|
||||
char *strchrnul(const char *s, int c) {
|
||||
while (*s && *s != c)
|
||||
s++;
|
||||
return (char *)s;
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user