From 2d0c5ec78eb975981b1d194fa9d4bc80b894748d Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 5 Nov 2018 22:51:23 +0100 Subject: Use _POSIX_C_SOURCE, use shm_open --- examples/dmabuf-capture.c | 1 - examples/meson.build | 4 ++-- examples/output-layout.c | 1 - examples/screencopy.c | 31 +++++++++++-------------------- examples/screenshot.c | 36 ++++++++++++------------------------ types/data_device/wlr_data_device.c | 1 - types/data_device/wlr_data_offer.c | 1 - types/data_device/wlr_data_source.c | 2 +- types/data_device/wlr_drag.c | 1 - types/wlr_input_device.c | 2 +- types/wlr_primary_selection.c | 2 +- xcursor/wlr_xcursor.c | 2 +- xwayland/selection/dnd.c | 1 - xwayland/selection/incoming.c | 2 +- xwayland/selection/outgoing.c | 1 - xwayland/selection/selection.c | 2 +- xwayland/sockets.c | 2 +- xwayland/xwayland.c | 1 - 18 files changed, 32 insertions(+), 61 deletions(-) diff --git a/examples/dmabuf-capture.c b/examples/dmabuf-capture.c index abdb146a..ebbe0a70 100644 --- a/examples/dmabuf-capture.c +++ b/examples/dmabuf-capture.c @@ -1,4 +1,3 @@ -#define _XOPEN_SOURCE 700 #define _POSIX_C_SOURCE 199309L #include #include diff --git a/examples/meson.build b/examples/meson.build index 369c7049..90dbeca8 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -55,7 +55,7 @@ examples = { }, 'screenshot': { 'src': 'screenshot.c', - 'dep': [wayland_client, wlr_protos, wlroots], + 'dep': [wayland_client, wlr_protos, rt], }, 'idle': { 'src': 'idle.c', @@ -96,7 +96,7 @@ examples = { }, 'screencopy': { 'src': 'screencopy.c', - 'dep': [libpng, wayland_client, wlr_protos, wlroots], + 'dep': [libpng, wayland_client, wlr_protos, rt], }, 'toplevel-decoration': { 'src': 'toplevel-decoration.c', diff --git a/examples/output-layout.c b/examples/output-layout.c index 2d1bc58b..440b3188 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -1,5 +1,4 @@ #define _POSIX_C_SOURCE 200112L -#define _XOPEN_SOURCE 700 #include #include #include diff --git a/examples/screencopy.c b/examples/screencopy.c index 4e58cd3b..82edcb9c 100644 --- a/examples/screencopy.c +++ b/examples/screencopy.c @@ -21,8 +21,7 @@ * DEALINGS IN THE SOFTWARE. */ -#define _XOPEN_SOURCE 700 -#define _POSIX_C_SOURCE 199309L +#define _POSIX_C_SOURCE 200112L #include #include #include @@ -65,12 +64,17 @@ static const struct format formats[] = { {WL_SHM_FORMAT_ABGR8888, false}, }; -static int backingfile(off_t size) { - char template[] = "/tmp/wlroots-shared-XXXXXX"; - int fd = mkstemp(template); +static struct wl_buffer *create_shm_buffer(enum wl_shm_format fmt, + int width, int height, int stride, void **data_out) { + int size = stride * height; + + const char shm_name[] = "/wlroots-screencopy"; + int fd = shm_open(shm_name, O_RDWR | O_CREAT | O_EXCL, 0); if (fd < 0) { - return -1; + fprintf(stderr, "shm_open failed\n"); + return NULL; } + shm_unlink(shm_name); int ret; while ((ret = ftruncate(fd, size)) == EINTR) { @@ -78,20 +82,7 @@ static int backingfile(off_t size) { } if (ret < 0) { close(fd); - return -1; - } - - unlink(template); - return fd; -} - -static struct wl_buffer *create_shm_buffer(enum wl_shm_format fmt, - int width, int height, int stride, void **data_out) { - int size = stride * height; - - int fd = backingfile(size); - if (fd < 0) { - fprintf(stderr, "creating a buffer file for %d B failed: %m\n", size); + fprintf(stderr, "ftruncate failed\n"); return NULL; } diff --git a/examples/screenshot.c b/examples/screenshot.c index aa4dcaa0..914f3994 100644 --- a/examples/screenshot.c +++ b/examples/screenshot.c @@ -21,8 +21,7 @@ * DEALINGS IN THE SOFTWARE. */ -#define _XOPEN_SOURCE 700 -#define _POSIX_C_SOURCE 199309L +#define _POSIX_C_SOURCE 200112L #include #include #include @@ -35,7 +34,6 @@ #include #include #include -#include #include "screenshooter-client-protocol.h" static struct wl_shm *shm = NULL; @@ -111,12 +109,18 @@ static const struct wl_registry_listener registry_listener = { .global_remove = handle_global_remove, }; -static int backingfile(off_t size) { - char template[] = "/tmp/wlroots-shared-XXXXXX"; - int fd = mkstemp(template); +static struct wl_buffer *create_shm_buffer(int width, int height, + void **data_out) { + int stride = width * 4; + int size = stride * height; + + const char shm_name[] = "/wlroots-screenshot"; + int fd = shm_open(shm_name, O_RDWR | O_CREAT | O_EXCL, 0); if (fd < 0) { - return -1; + fprintf(stderr, "shm_open failed\n"); + return NULL; } + shm_unlink(shm_name); int ret; while ((ret = ftruncate(fd, size)) == EINTR) { @@ -124,21 +128,7 @@ static int backingfile(off_t size) { } 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 = backingfile(size); - if (fd < 0) { - fprintf(stderr, "creating a buffer file for %d B failed: %m\n", size); + fprintf(stderr, "ftruncate failed\n"); return NULL; } @@ -200,8 +190,6 @@ static void write_image(const char *filename, int width, int height, } int main(int argc, char *argv[]) { - wlr_log_init(WLR_DEBUG, NULL); - struct wl_display * display = wl_display_connect(NULL); if (display == NULL) { fprintf(stderr, "failed to create display: %m\n"); diff --git a/types/data_device/wlr_data_device.c b/types/data_device/wlr_data_device.c index 111c2de0..a50f0b4a 100644 --- a/types/data_device/wlr_data_device.c +++ b/types/data_device/wlr_data_device.c @@ -1,4 +1,3 @@ -#define _XOPEN_SOURCE 700 #include #include #include diff --git a/types/data_device/wlr_data_offer.c b/types/data_device/wlr_data_offer.c index 9847e07c..c8fb9b3b 100644 --- a/types/data_device/wlr_data_offer.c +++ b/types/data_device/wlr_data_offer.c @@ -1,4 +1,3 @@ -#define _XOPEN_SOURCE 700 #include #include #include diff --git a/types/data_device/wlr_data_source.c b/types/data_device/wlr_data_source.c index 59650170..64db3a70 100644 --- a/types/data_device/wlr_data_source.c +++ b/types/data_device/wlr_data_source.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 700 +#define _POSIX_C_SOURCE 200809L #include #include #include diff --git a/types/data_device/wlr_drag.c b/types/data_device/wlr_drag.c index fcde7b3e..8ed6e034 100644 --- a/types/data_device/wlr_drag.c +++ b/types/data_device/wlr_drag.c @@ -1,4 +1,3 @@ -#define _XOPEN_SOURCE 700 #include #include #include diff --git a/types/wlr_input_device.c b/types/wlr_input_device.c index 89ca13cb..e10e34f5 100644 --- a/types/wlr_input_device.c +++ b/types/wlr_input_device.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 500 +#define _POSIX_C_SOURCE 200809L #include #include #include diff --git a/types/wlr_primary_selection.c b/types/wlr_primary_selection.c index e561852f..3fed0f64 100644 --- a/types/wlr_primary_selection.c +++ b/types/wlr_primary_selection.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 700 +#define _POSIX_C_SOURCE 200809L #include #include #include diff --git a/xcursor/wlr_xcursor.c b/xcursor/wlr_xcursor.c index 2391a49a..d651497b 100644 --- a/xcursor/wlr_xcursor.c +++ b/xcursor/wlr_xcursor.c @@ -23,7 +23,7 @@ * SOFTWARE. */ -#define _XOPEN_SOURCE 500 +#define _POSIX_C_SOURCE 200809L #include #include #include diff --git a/xwayland/selection/dnd.c b/xwayland/selection/dnd.c index 4c687172..534d056c 100644 --- a/xwayland/selection/dnd.c +++ b/xwayland/selection/dnd.c @@ -1,4 +1,3 @@ -#define _XOPEN_SOURCE 700 #include #include #include diff --git a/xwayland/selection/incoming.c b/xwayland/selection/incoming.c index 4e88bbe4..5b253b5d 100644 --- a/xwayland/selection/incoming.c +++ b/xwayland/selection/incoming.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 700 +#define _POSIX_C_SOURCE 200809L #include #include #include diff --git a/xwayland/selection/outgoing.c b/xwayland/selection/outgoing.c index 156f0ad5..0c095d25 100644 --- a/xwayland/selection/outgoing.c +++ b/xwayland/selection/outgoing.c @@ -1,4 +1,3 @@ -#define _XOPEN_SOURCE 700 #include #include #include diff --git a/xwayland/selection/selection.c b/xwayland/selection/selection.c index e16ad111..d9de5643 100644 --- a/xwayland/selection/selection.c +++ b/xwayland/selection/selection.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 700 +#define _POSIX_C_SOURCE 200809L #include #include #include diff --git a/xwayland/sockets.c b/xwayland/sockets.c index 2b0b5ced..112a8bb0 100644 --- a/xwayland/sockets.c +++ b/xwayland/sockets.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 700 +#define _POSIX_C_SOURCE 200809L #ifdef __FreeBSD__ // for SOCK_CLOEXEC #define __BSD_VISIBLE 1 diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c index d92d58fb..e6d3502c 100644 --- a/xwayland/xwayland.c +++ b/xwayland/xwayland.c @@ -1,4 +1,3 @@ -#define _XOPEN_SOURCE 700 #define _DEFAULT_SOURCE #ifdef __FreeBSD__ // for SOCK_CLOEXEC -- cgit v1.2.3