aboutsummaryrefslogtreecommitdiff
path: root/examples/screenshot.c
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2018-02-22 12:04:32 +0100
committerGuido Günther <agx@sigxcpu.org>2018-02-23 09:51:23 +0100
commitb13f9fcfdee3028e8966a45295c12c818f9bc4f9 (patch)
tree2dddae798dbd223413ae85a3811c517d6780970b /examples/screenshot.c
parent2688f6163f5cce95302bb40ae35ff855ee1ccb1d (diff)
Don't use os_create_anonymous_file outside of wlroots
Use a stripped down version for the backing file in the screenshot example.
Diffstat (limited to 'examples/screenshot.c')
-rw-r--r--examples/screenshot.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/examples/screenshot.c b/examples/screenshot.c
index c163df75..7edb7327 100644
--- a/examples/screenshot.c
+++ b/examples/screenshot.c
@@ -121,12 +121,32 @@ static const struct wl_registry_listener registry_listener = {
.global_remove = handle_global_remove,
};
+static int backingfile(off_t size) {
+ static char template[] = "/tmp/wlroots-shared-XXXXXX";
+ int fd, ret;
+
+ fd = mkstemp(template);
+ if (fd < 0) {
+ return -1;
+ }
+
+ while ((ret = ftruncate(fd, size)) == EINTR) {}
+ if (ret < 0) {
+ close(fd);
+ return -1;
+ }
+
+ unlink(template);
+ return fd;
+}
+
+
static struct wl_buffer *create_shm_buffer(int width, int height,
void **data_out) {
int stride = width * 4;
int size = stride * height;
- int fd = os_create_anonymous_file(size);
+ int fd = backingfile(size);
if (fd < 0) {
fprintf(stderr, "creating a buffer file for %d B failed: %m\n", size);
return NULL;