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:
75
shm_open.c
75
shm_open.c
@ -5,47 +5,44 @@
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static void
|
||||
randname(char *buf) {
|
||||
struct timespec ts;
|
||||
long r;
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
r = ts.tv_nsec;
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
buf[i] = 'A' + (r & 15) + (r & 16) * 2;
|
||||
r >>= 5;
|
||||
}
|
||||
static void randname(char *buf) {
|
||||
struct timespec ts;
|
||||
long r;
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
r = ts.tv_nsec;
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
buf[i] = 'A' + (r & 15) + (r & 16) * 2;
|
||||
r >>= 5;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
create_shm_file(void) {
|
||||
int retries = 100;
|
||||
int fd;
|
||||
do {
|
||||
char name[] = "/wl_shm-XXXXXX";
|
||||
randname(name + sizeof(name) - 7);
|
||||
--retries;
|
||||
fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL, 0600);
|
||||
if (fd >= 0) {
|
||||
shm_unlink(name);
|
||||
return fd;
|
||||
}
|
||||
} while (retries > 0 && errno == EEXIST);
|
||||
return -1;
|
||||
static int create_shm_file(void) {
|
||||
int retries = 100;
|
||||
int fd;
|
||||
do {
|
||||
char name[] = "/wl_shm-XXXXXX";
|
||||
randname(name + sizeof(name) - 7);
|
||||
--retries;
|
||||
fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL, 0600);
|
||||
if (fd >= 0) {
|
||||
shm_unlink(name);
|
||||
return fd;
|
||||
}
|
||||
} while (retries > 0 && errno == EEXIST);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
allocate_shm_file(size_t size) {
|
||||
int fd = create_shm_file();
|
||||
int ret;
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
do {
|
||||
ret = ftruncate(fd, size);
|
||||
} while (ret < 0 && errno == EINTR);
|
||||
if (ret < 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
return fd;
|
||||
int allocate_shm_file(size_t size) {
|
||||
int fd = create_shm_file();
|
||||
int ret;
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
do {
|
||||
ret = ftruncate(fd, size);
|
||||
} while (ret < 0 && errno == EINTR);
|
||||
if (ret < 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
Reference in New Issue
Block a user