mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-14 17:25:59 +01:00
c74f89d4f8
We can just use a regular assignment instead. This is more type-safe since there is no need to provide the struct size. The remaining memcpy() calls perform array copies or copies from void pointers (which may be unaligned).
38 lines
826 B
C
38 lines
826 B
C
#define _POSIX_C_SOURCE 200809L
|
|
#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;
|
|
}
|