mirror of
https://github.com/jjsullivan5196/wvkbd.git
synced 2025-04-15 05:16:47 +02:00
Simplest clang-format
This commit is contained in:
parent
2747980a4e
commit
fbbf563d70
109
.clang-format
109
.clang-format
@ -1,107 +1,2 @@
|
||||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: All
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: false
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterClass: false
|
||||
AfterControlStatement: false
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 2
|
||||
ContinuationIndentWidth: 2
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IndentCaseLabels: false
|
||||
IndentWidth: 2
|
||||
IndentWrappedFunctionNames: false
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
ReflowComments: true
|
||||
SortIncludes: false
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Cpp11
|
||||
TabWidth: 2
|
||||
UseTab: ForIndentation
|
||||
...
|
||||
BasedOnStyle: LLVM
|
||||
IndentWidth: 4
|
||||
|
181
drw.c
181
drw.c
@ -5,131 +5,124 @@
|
||||
#include "drw.h"
|
||||
#include "shm_open.h"
|
||||
|
||||
void
|
||||
drwsurf_resize(struct drwsurf *ds, uint32_t w, uint32_t h, double s) {
|
||||
if (ds->buf) {
|
||||
munmap(ds->pool_data, ds->size);
|
||||
wl_buffer_destroy(ds->buf);
|
||||
ds->buf = NULL;
|
||||
}
|
||||
void drwsurf_resize(struct drwsurf *ds, uint32_t w, uint32_t h, double s) {
|
||||
if (ds->buf) {
|
||||
munmap(ds->pool_data, ds->size);
|
||||
wl_buffer_destroy(ds->buf);
|
||||
ds->buf = NULL;
|
||||
}
|
||||
|
||||
ds->scale = s;
|
||||
ds->width = w * s;
|
||||
ds->height = h * s;
|
||||
ds->scale = s;
|
||||
ds->width = w * s;
|
||||
ds->height = h * s;
|
||||
|
||||
setup_buffer(ds);
|
||||
setup_buffer(ds);
|
||||
}
|
||||
|
||||
void
|
||||
drwsurf_flip(struct drwsurf *ds) {
|
||||
wl_surface_attach(ds->surf, ds->buf, 0, 0);
|
||||
wl_surface_commit(ds->surf);
|
||||
void drwsurf_flip(struct drwsurf *ds) {
|
||||
wl_surface_attach(ds->surf, ds->buf, 0, 0);
|
||||
wl_surface_commit(ds->surf);
|
||||
}
|
||||
|
||||
void
|
||||
drw_draw_text(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
||||
uint32_t w, uint32_t h, uint32_t b, const char *label) {
|
||||
void drw_draw_text(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
||||
uint32_t w, uint32_t h, uint32_t b, const char *label) {
|
||||
|
||||
cairo_save(d->cairo);
|
||||
cairo_save(d->cairo);
|
||||
|
||||
cairo_set_source_rgba(
|
||||
d->cairo, color.bgra[2] / (double)255, color.bgra[1] / (double)255,
|
||||
color.bgra[0] / (double)255, color.bgra[3] / (double)255);
|
||||
cairo_move_to(d->cairo, x + w / 2, y + h / 2);
|
||||
cairo_set_source_rgba(
|
||||
d->cairo, color.bgra[2] / (double)255, color.bgra[1] / (double)255,
|
||||
color.bgra[0] / (double)255, color.bgra[3] / (double)255);
|
||||
cairo_move_to(d->cairo, x + w / 2, y + h / 2);
|
||||
|
||||
pango_layout_set_text(d->layout, label, -1);
|
||||
pango_layout_set_width(d->layout, (w - (b * 2)) * PANGO_SCALE);
|
||||
pango_layout_set_height(d->layout, (h - (b * 2)) * PANGO_SCALE);
|
||||
pango_layout_set_text(d->layout, label, -1);
|
||||
pango_layout_set_width(d->layout, (w - (b * 2)) * PANGO_SCALE);
|
||||
pango_layout_set_height(d->layout, (h - (b * 2)) * PANGO_SCALE);
|
||||
|
||||
int width, height;
|
||||
pango_layout_get_pixel_size(d->layout, &width, &height);
|
||||
int width, height;
|
||||
pango_layout_get_pixel_size(d->layout, &width, &height);
|
||||
|
||||
cairo_rel_move_to(d->cairo, -width / 2, -height / 2);
|
||||
cairo_rel_move_to(d->cairo, -width / 2, -height / 2);
|
||||
|
||||
pango_cairo_show_layout(d->cairo, d->layout);
|
||||
cairo_restore(d->cairo);
|
||||
pango_cairo_show_layout(d->cairo, d->layout);
|
||||
cairo_restore(d->cairo);
|
||||
}
|
||||
|
||||
void
|
||||
drw_do_clear(struct drwsurf *d, uint32_t x, uint32_t y, uint32_t w,
|
||||
uint32_t h) {
|
||||
cairo_save(d->cairo);
|
||||
void drw_do_clear(struct drwsurf *d, uint32_t x, uint32_t y, uint32_t w,
|
||||
uint32_t h) {
|
||||
cairo_save(d->cairo);
|
||||
|
||||
cairo_set_operator(d->cairo, CAIRO_OPERATOR_CLEAR);
|
||||
cairo_rectangle(d->cairo, x, y, w, h);
|
||||
cairo_fill(d->cairo);
|
||||
cairo_set_operator(d->cairo, CAIRO_OPERATOR_CLEAR);
|
||||
cairo_rectangle(d->cairo, x, y, w, h);
|
||||
cairo_fill(d->cairo);
|
||||
|
||||
cairo_restore(d->cairo);
|
||||
cairo_restore(d->cairo);
|
||||
}
|
||||
|
||||
void
|
||||
drw_do_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
||||
uint32_t w, uint32_t h, bool over) {
|
||||
cairo_save(d->cairo);
|
||||
void drw_do_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
||||
uint32_t w, uint32_t h, bool over) {
|
||||
cairo_save(d->cairo);
|
||||
|
||||
if (over) {
|
||||
cairo_set_operator(d->cairo, CAIRO_OPERATOR_OVER);
|
||||
} else {
|
||||
cairo_set_operator(d->cairo, CAIRO_OPERATOR_SOURCE);
|
||||
}
|
||||
if (over) {
|
||||
cairo_set_operator(d->cairo, CAIRO_OPERATOR_OVER);
|
||||
} else {
|
||||
cairo_set_operator(d->cairo, CAIRO_OPERATOR_SOURCE);
|
||||
}
|
||||
|
||||
cairo_rectangle(d->cairo, x, y, w, h);
|
||||
cairo_set_source_rgba(
|
||||
d->cairo, color.bgra[2] / (double)255, color.bgra[1] / (double)255,
|
||||
color.bgra[0] / (double)255, color.bgra[3] / (double)255);
|
||||
cairo_fill(d->cairo);
|
||||
cairo_rectangle(d->cairo, x, y, w, h);
|
||||
cairo_set_source_rgba(
|
||||
d->cairo, color.bgra[2] / (double)255, color.bgra[1] / (double)255,
|
||||
color.bgra[0] / (double)255, color.bgra[3] / (double)255);
|
||||
cairo_fill(d->cairo);
|
||||
|
||||
cairo_restore(d->cairo);
|
||||
cairo_restore(d->cairo);
|
||||
}
|
||||
|
||||
void
|
||||
drw_fill_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
||||
uint32_t w, uint32_t h) {
|
||||
drw_do_rectangle(d, color, x, y, w, h, false);
|
||||
void drw_fill_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
||||
uint32_t w, uint32_t h) {
|
||||
drw_do_rectangle(d, color, x, y, w, h, false);
|
||||
}
|
||||
|
||||
void
|
||||
drw_over_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
||||
uint32_t w, uint32_t h) {
|
||||
drw_do_rectangle(d, color, x, y, w, h, true);
|
||||
void drw_over_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
||||
uint32_t w, uint32_t h) {
|
||||
drw_do_rectangle(d, color, x, y, w, h, true);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
setup_buffer(struct drwsurf *drwsurf) {
|
||||
int stride = drwsurf->width * 4;
|
||||
drwsurf->size = stride * drwsurf->height;
|
||||
uint32_t setup_buffer(struct drwsurf *drwsurf) {
|
||||
int stride = drwsurf->width * 4;
|
||||
drwsurf->size = stride * drwsurf->height;
|
||||
|
||||
int fd = allocate_shm_file(drwsurf->size);
|
||||
if (fd == -1) {
|
||||
return 1;
|
||||
}
|
||||
int fd = allocate_shm_file(drwsurf->size);
|
||||
if (fd == -1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
drwsurf->pool_data =
|
||||
mmap(NULL, drwsurf->size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (drwsurf->pool_data == MAP_FAILED) {
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
drwsurf->pool_data =
|
||||
mmap(NULL, drwsurf->size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (drwsurf->pool_data == MAP_FAILED) {
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct wl_shm_pool *pool =
|
||||
wl_shm_create_pool(drwsurf->ctx->shm, fd, drwsurf->size);
|
||||
drwsurf->buf = wl_shm_pool_create_buffer(
|
||||
pool, 0, drwsurf->width, drwsurf->height, stride, WL_SHM_FORMAT_ARGB8888);
|
||||
wl_shm_pool_destroy(pool);
|
||||
close(fd);
|
||||
struct wl_shm_pool *pool =
|
||||
wl_shm_create_pool(drwsurf->ctx->shm, fd, drwsurf->size);
|
||||
drwsurf->buf =
|
||||
wl_shm_pool_create_buffer(pool, 0, drwsurf->width, drwsurf->height,
|
||||
stride, WL_SHM_FORMAT_ARGB8888);
|
||||
wl_shm_pool_destroy(pool);
|
||||
close(fd);
|
||||
|
||||
cairo_surface_t *s = cairo_image_surface_create_for_data(
|
||||
drwsurf->pool_data, CAIRO_FORMAT_ARGB32, drwsurf->width, drwsurf->height,
|
||||
stride);
|
||||
cairo_surface_t *s = cairo_image_surface_create_for_data(
|
||||
drwsurf->pool_data, CAIRO_FORMAT_ARGB32, drwsurf->width,
|
||||
drwsurf->height, stride);
|
||||
|
||||
drwsurf->cairo = cairo_create(s);
|
||||
cairo_scale(drwsurf->cairo, drwsurf->scale, drwsurf->scale);
|
||||
cairo_set_antialias(drwsurf->cairo, CAIRO_ANTIALIAS_NONE);
|
||||
drwsurf->layout = pango_cairo_create_layout(drwsurf->cairo);
|
||||
pango_layout_set_font_description(drwsurf->layout,
|
||||
drwsurf->ctx->font_description);
|
||||
pango_layout_set_auto_dir(drwsurf->layout, false);
|
||||
cairo_save(drwsurf->cairo);
|
||||
drwsurf->cairo = cairo_create(s);
|
||||
cairo_scale(drwsurf->cairo, drwsurf->scale, drwsurf->scale);
|
||||
cairo_set_antialias(drwsurf->cairo, CAIRO_ANTIALIAS_NONE);
|
||||
drwsurf->layout = pango_cairo_create_layout(drwsurf->cairo);
|
||||
pango_layout_set_font_description(drwsurf->layout,
|
||||
drwsurf->ctx->font_description);
|
||||
pango_layout_set_auto_dir(drwsurf->layout, false);
|
||||
cairo_save(drwsurf->cairo);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
1143
keyboard.c
1143
keyboard.c
File diff suppressed because it is too large
Load Diff
@ -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
|
||||
|
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user