Merge pull request #1357 from emersion/xopen-source

Use _POSIX_C_SOURCE, use shm_open
This commit is contained in:
Drew DeVault 2018-11-06 12:46:29 +01:00 committed by GitHub
commit 2bf482e90f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 42 additions and 74 deletions

View File

@ -1,4 +1,3 @@
#define _XOPEN_SOURCE 700
#define _POSIX_C_SOURCE 199309L #define _POSIX_C_SOURCE 199309L
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
#include <libavutil/display.h> #include <libavutil/display.h>

View File

@ -1,12 +1,12 @@
#include <getopt.h> #include <getopt.h>
#include <pthread.h> #include <pthread.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <wayland-client-protocol.h> #include <wayland-client-protocol.h>
#include <wayland-client.h> #include <wayland-client.h>
#include <wlr/util/log.h>
#include "idle-client-protocol.h" #include "idle-client-protocol.h"
static struct org_kde_kwin_idle *idle_manager = NULL; static struct org_kde_kwin_idle *idle_manager = NULL;
@ -109,8 +109,6 @@ void *main_loop(void *data) {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
wlr_log_init(WLR_DEBUG, NULL);
if (parse_args(argc, argv) != 0) { if (parse_args(argc, argv) != 0) {
return -1; return -1;
} }

View File

@ -1,6 +1,7 @@
#define _POSIX_C_SOURCE 200809L #define _POSIX_C_SOURCE 200809L
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -9,7 +10,6 @@
#include <unistd.h> #include <unistd.h>
#include <wayland-client.h> #include <wayland-client.h>
#include <wayland-egl.h> #include <wayland-egl.h>
#include <wlr/render/egl.h>
#include "input-method-unstable-v2-client-protocol.h" #include "input-method-unstable-v2-client-protocol.h"
#include "text-input-unstable-v3-client-protocol.h" #include "text-input-unstable-v3-client-protocol.h"
#include "xdg-shell-client-protocol.h" #include "xdg-shell-client-protocol.h"

View File

@ -55,11 +55,11 @@ examples = {
}, },
'screenshot': { 'screenshot': {
'src': 'screenshot.c', 'src': 'screenshot.c',
'dep': [wayland_client, wlr_protos, wlroots], 'dep': [wayland_client, wlr_protos, rt],
}, },
'idle': { 'idle': {
'src': 'idle.c', 'src': 'idle.c',
'dep': [wayland_client, wlr_protos, wlroots, threads], 'dep': [wayland_client, wlr_protos, threads],
}, },
'idle-inhibit': { 'idle-inhibit': {
'src': 'idle-inhibit.c', 'src': 'idle-inhibit.c',
@ -75,7 +75,7 @@ examples = {
}, },
'gamma-control': { 'gamma-control': {
'src': 'gamma-control.c', 'src': 'gamma-control.c',
'dep': [wayland_client, wayland_cursor, wlr_protos, wlroots], 'dep': [wayland_client, wayland_cursor, wlr_protos, math],
}, },
'pointer-constraints': { 'pointer-constraints': {
'src': 'pointer-constraints.c', 'src': 'pointer-constraints.c',
@ -91,12 +91,11 @@ examples = {
threads, threads,
wayland_client, wayland_client,
wlr_protos, wlr_protos,
wlroots,
], ],
}, },
'screencopy': { 'screencopy': {
'src': 'screencopy.c', 'src': 'screencopy.c',
'dep': [libpng, wayland_client, wlr_protos, wlroots], 'dep': [libpng, wayland_client, wlr_protos, rt],
}, },
'toplevel-decoration': { 'toplevel-decoration': {
'src': 'toplevel-decoration.c', 'src': 'toplevel-decoration.c',
@ -104,7 +103,7 @@ examples = {
}, },
'input-method': { 'input-method': {
'src': 'input-method.c', 'src': 'input-method.c',
'dep': [wayland_client, wlr_protos, wlroots] + libepoll, 'dep': [wayland_client, wlr_protos] + libepoll,
}, },
'text-input': { 'text-input': {
'src': 'text-input.c', 'src': 'text-input.c',

View File

@ -1,5 +1,4 @@
#define _POSIX_C_SOURCE 200112L #define _POSIX_C_SOURCE 200112L
#define _XOPEN_SOURCE 700
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
#include <limits.h> #include <limits.h>
#include <math.h> #include <math.h>

View File

@ -21,8 +21,7 @@
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*/ */
#define _XOPEN_SOURCE 700 #define _POSIX_C_SOURCE 200112L
#define _POSIX_C_SOURCE 199309L
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <limits.h> #include <limits.h>
@ -65,12 +64,17 @@ static const struct format formats[] = {
{WL_SHM_FORMAT_ABGR8888, false}, {WL_SHM_FORMAT_ABGR8888, false},
}; };
static int backingfile(off_t size) { static struct wl_buffer *create_shm_buffer(enum wl_shm_format fmt,
char template[] = "/tmp/wlroots-shared-XXXXXX"; int width, int height, int stride, void **data_out) {
int fd = mkstemp(template); 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) { if (fd < 0) {
return -1; fprintf(stderr, "shm_open failed\n");
return NULL;
} }
shm_unlink(shm_name);
int ret; int ret;
while ((ret = ftruncate(fd, size)) == EINTR) { while ((ret = ftruncate(fd, size)) == EINTR) {
@ -78,20 +82,7 @@ static int backingfile(off_t size) {
} }
if (ret < 0) { if (ret < 0) {
close(fd); close(fd);
return -1; fprintf(stderr, "ftruncate failed\n");
}
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);
return NULL; return NULL;
} }

View File

@ -21,8 +21,7 @@
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*/ */
#define _XOPEN_SOURCE 700 #define _POSIX_C_SOURCE 200112L
#define _POSIX_C_SOURCE 199309L
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <limits.h> #include <limits.h>
@ -35,7 +34,6 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#include <wayland-client.h> #include <wayland-client.h>
#include <wlr/util/log.h>
#include "screenshooter-client-protocol.h" #include "screenshooter-client-protocol.h"
static struct wl_shm *shm = NULL; static struct wl_shm *shm = NULL;
@ -111,12 +109,18 @@ static const struct wl_registry_listener registry_listener = {
.global_remove = handle_global_remove, .global_remove = handle_global_remove,
}; };
static int backingfile(off_t size) { static struct wl_buffer *create_shm_buffer(int width, int height,
char template[] = "/tmp/wlroots-shared-XXXXXX"; void **data_out) {
int fd = mkstemp(template); 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) { if (fd < 0) {
return -1; fprintf(stderr, "shm_open failed\n");
return NULL;
} }
shm_unlink(shm_name);
int ret; int ret;
while ((ret = ftruncate(fd, size)) == EINTR) { while ((ret = ftruncate(fd, size)) == EINTR) {
@ -124,21 +128,7 @@ static int backingfile(off_t size) {
} }
if (ret < 0) { if (ret < 0) {
close(fd); close(fd);
return -1; fprintf(stderr, "ftruncate failed\n");
}
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);
return NULL; return NULL;
} }
@ -200,8 +190,6 @@ static void write_image(const char *filename, int width, int height,
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
wlr_log_init(WLR_DEBUG, NULL);
struct wl_display * display = wl_display_connect(NULL); struct wl_display * display = wl_display_connect(NULL);
if (display == NULL) { if (display == NULL) {
fprintf(stderr, "failed to create display: %m\n"); fprintf(stderr, "failed to create display: %m\n");

View File

@ -1,4 +1,3 @@
#define _XOPEN_SOURCE 700
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

View File

@ -1,4 +1,3 @@
#define _XOPEN_SOURCE 700
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <strings.h> #include <strings.h>

View File

@ -1,4 +1,4 @@
#define _XOPEN_SOURCE 700 #define _POSIX_C_SOURCE 200809L
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

View File

@ -1,4 +1,3 @@
#define _XOPEN_SOURCE 700
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

View File

@ -1,4 +1,4 @@
#define _XOPEN_SOURCE 500 #define _POSIX_C_SOURCE 200809L
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <wayland-server.h> #include <wayland-server.h>

View File

@ -1,4 +1,4 @@
#define _XOPEN_SOURCE 700 #define _POSIX_C_SOURCE 200809L
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

View File

@ -23,7 +23,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
#define _XOPEN_SOURCE 500 #define _POSIX_C_SOURCE 200809L
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>

View File

@ -1,4 +1,3 @@
#define _XOPEN_SOURCE 700
#include <assert.h> #include <assert.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdlib.h> #include <stdlib.h>

View File

@ -1,4 +1,4 @@
#define _XOPEN_SOURCE 700 #define _POSIX_C_SOURCE 200809L
#include <assert.h> #include <assert.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdlib.h> #include <stdlib.h>

View File

@ -1,4 +1,3 @@
#define _XOPEN_SOURCE 700
#include <assert.h> #include <assert.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdlib.h> #include <stdlib.h>

View File

@ -1,4 +1,4 @@
#define _XOPEN_SOURCE 700 #define _POSIX_C_SOURCE 200809L
#include <assert.h> #include <assert.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdlib.h> #include <stdlib.h>

View File

@ -1,4 +1,4 @@
#define _XOPEN_SOURCE 700 #define _POSIX_C_SOURCE 200809L
#ifdef __FreeBSD__ #ifdef __FreeBSD__
// for SOCK_CLOEXEC // for SOCK_CLOEXEC
#define __BSD_VISIBLE 1 #define __BSD_VISIBLE 1

View File

@ -1,4 +1,3 @@
#define _XOPEN_SOURCE 700
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#ifdef __FreeBSD__ #ifdef __FreeBSD__
// for SOCK_CLOEXEC // for SOCK_CLOEXEC