wlroots-hyprland/render/dmabuf.c
Simon Ser 842093bb84 Define _POSIX_C_SOURCE globally
Stop trying to maintain a per-file _POSIX_C_SOURCE. Instead,
require POSIX.1-2008 globally. A lot of core source files depend
on that already.

Some care must be taken on a few select files where we need a bit
more than POSIX. Some files need XSI extensions (_XOPEN_SOURCE) and
some files need BSD extensions (_DEFAULT_SOURCE). In both cases,
these feature test macros imply _POSIX_C_SOURCE. Make sure to not
define both these macros and _POSIX_C_SOURCE explicitly to avoid
POSIX requirement conflicts (e.g. _POSIX_C_SOURCE says POSIX.1-2001
but _XOPEN_SOURCE says POSIX.1-2008).

Additionally, there is one special case in render/vulkan/vulkan.c.
That file needs major()/minor(), and these are system-specific.
On FreeBSD, _POSIX_C_SOURCE hides system-specific symbols so we need
to make sure it's not defined for this file. On Linux, we can
explicitly include <sys/sysmacros.h> and ensure that apart from
symbols defined there the file only uses POSIX toys.
2024-02-15 15:41:12 +01:00

37 lines
794 B
C

#include <fcntl.h>
#include <unistd.h>
#include <wlr/render/dmabuf.h>
#include <wlr/util/log.h>
#include "render/dmabuf.h"
void wlr_dmabuf_attributes_finish(struct wlr_dmabuf_attributes *attribs) {
for (int i = 0; i < attribs->n_planes; ++i) {
close(attribs->fd[i]);
attribs->fd[i] = -1;
}
attribs->n_planes = 0;
}
bool wlr_dmabuf_attributes_copy(struct wlr_dmabuf_attributes *dst,
const struct wlr_dmabuf_attributes *src) {
*dst = *src;
int i;
for (i = 0; i < src->n_planes; ++i) {
dst->fd[i] = fcntl(src->fd[i], F_DUPFD_CLOEXEC, 0);
if (dst->fd[i] < 0) {
wlr_log_errno(WLR_ERROR, "fcntl(F_DUPFD_CLOEXEC) failed");
goto error;
}
}
return true;
error:
for (int j = 0; j < i; j++) {
close(dst->fd[j]);
dst->fd[j] = -1;
}
dst->n_planes = 0;
return false;
}