Moved os-compatibility and added header

* Moved os-compatibility.c to util
* Added header under util
* Removed static since it isn't needed (i think so)
* Adjusted meson.build to include lib_wlr

Improved some codestyle

* Added guard to os-compatibility.h
* Fixed typo in include statment

Adjusted Guard

* Changed guard to _WLR_UTIL_OS_COMPATIBILITY
This commit is contained in:
Moritz 2017-11-30 15:00:36 +01:00
parent 5d7eb438d9
commit cef6d75491
6 changed files with 21 additions and 14 deletions

View File

@ -21,7 +21,6 @@ backend_files = files(
'wayland/output.c', 'wayland/output.c',
'wayland/registry.c', 'wayland/registry.c',
'wayland/wl_seat.c', 'wayland/wl_seat.c',
'wayland/os-compatibility.c',
'x11/backend.c', 'x11/backend.c',
) )

View File

@ -29,5 +29,6 @@ executable(
executable( executable(
'screenshot', 'screenshot',
'screenshot.c', 'screenshot.c',
dependencies: [wayland_client, wlr_protos], dependencies: [wayland_client, wlr_protos, wlroots],
link_with: lib_shared,
) )

View File

@ -35,7 +35,7 @@
#include <limits.h> #include <limits.h>
#include <sys/param.h> #include <sys/param.h>
#include <screenshooter-client-protocol.h> #include <screenshooter-client-protocol.h>
#include "../backend/wayland/os-compatibility.c" #include "util/os-compatibility.h"
static struct wl_shm *shm = NULL; static struct wl_shm *shm = NULL;
static struct orbital_screenshooter *screenshooter = NULL; static struct orbital_screenshooter *screenshooter = NULL;

View File

@ -0,0 +1,12 @@
#ifndef _WLR_UTIL_OS_COMPATIBILITY_H
#define _WLR_UTIL_OS_COMPATIBILITY_H
int os_fd_set_cloexec(int fd);
int set_cloexec_or_close(int fd);
int create_tmpfile_cloexec(char *tmpname);
int os_create_anonymous_file(off_t size);
#endif

View File

@ -2,6 +2,7 @@ lib_wlr_util = static_library(
'wlr_util', 'wlr_util',
files( files(
'log.c', 'log.c',
'os-compatibility.c',
), ),
include_directories: wlr_inc, include_directories: wlr_inc,
) )

View File

@ -31,10 +31,9 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "util/os-compatibility.h"
int int os_fd_set_cloexec(int fd) {
os_fd_set_cloexec(int fd)
{
long flags; long flags;
if (fd == -1) if (fd == -1)
@ -50,9 +49,7 @@ os_fd_set_cloexec(int fd)
return 0; return 0;
} }
static int int set_cloexec_or_close(int fd) {
set_cloexec_or_close(int fd)
{
if (os_fd_set_cloexec(fd) != 0) { if (os_fd_set_cloexec(fd) != 0) {
close(fd); close(fd);
return -1; return -1;
@ -60,8 +57,7 @@ set_cloexec_or_close(int fd)
return fd; return fd;
} }
static int int create_tmpfile_cloexec(char *tmpname)
create_tmpfile_cloexec(char *tmpname)
{ {
int fd; int fd;
@ -101,9 +97,7 @@ create_tmpfile_cloexec(char *tmpname)
* If posix_fallocate() is not supported, program may receive * If posix_fallocate() is not supported, program may receive
* SIGBUS on accessing mmap()'ed file contents instead. * SIGBUS on accessing mmap()'ed file contents instead.
*/ */
int int os_create_anonymous_file(off_t size) {
os_create_anonymous_file(off_t size)
{
static const char template[] = "/wlroots-shared-XXXXXX"; static const char template[] = "/wlroots-shared-XXXXXX";
const char *path; const char *path;
char *name; char *name;