Define feature test macros in common.h

This enables necessary functions once for all.

As a consequence, define common.h before any other header.
This commit is contained in:
Romain Vimont 2021-01-08 19:24:51 +01:00
parent 59feb2a15c
commit ab912c23e7
37 changed files with 77 additions and 53 deletions

View file

@ -1,11 +1,11 @@
#ifndef SC_ADB_H #ifndef SC_ADB_H
#define SC_ADB_H #define SC_ADB_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include <inttypes.h> #include <inttypes.h>
#include "common.h"
#include "util/process.h" #include "util/process.h"
process_t process_t

View file

@ -1,9 +1,10 @@
#ifndef SCRCPY_CLI_H #ifndef SCRCPY_CLI_H
#define SCRCPY_CLI_H #define SCRCPY_CLI_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include "common.h"
#include "scrcpy.h" #include "scrcpy.h"
struct scrcpy_cli_args { struct scrcpy_cli_args {

View file

@ -1,6 +1,13 @@
#ifndef COMPAT_H #ifndef COMPAT_H
#define COMPAT_H #define COMPAT_H
#define _POSIX_C_SOURCE 200809L
#define _XOPEN_SOURCE 700
#define _GNU_SOURCE
#ifdef __APPLE__
# define _DARWIN_C_SOURCE
#endif
#include <libavcodec/version.h> #include <libavcodec/version.h>
#include <libavformat/version.h> #include <libavformat/version.h>
#include <SDL2/SDL_version.h> #include <SDL2/SDL_version.h>

View file

@ -1,11 +1,12 @@
#ifndef CONTROLMSG_H #ifndef CONTROLMSG_H
#define CONTROLMSG_H #define CONTROLMSG_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "common.h"
#include "android/input.h" #include "android/input.h"
#include "android/keycodes.h" #include "android/keycodes.h"
#include "coords.h" #include "coords.h"

View file

@ -1,11 +1,12 @@
#ifndef CONTROLLER_H #ifndef CONTROLLER_H
#define CONTROLLER_H #define CONTROLLER_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include <SDL2/SDL_mutex.h> #include <SDL2/SDL_mutex.h>
#include <SDL2/SDL_thread.h> #include <SDL2/SDL_thread.h>
#include "common.h"
#include "control_msg.h" #include "control_msg.h"
#include "receiver.h" #include "receiver.h"
#include "util/cbuf.h" #include "util/cbuf.h"

View file

@ -1,11 +1,11 @@
#ifndef DECODER_H #ifndef DECODER_H
#define DECODER_H #define DECODER_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
#include "common.h"
struct video_buffer; struct video_buffer;
struct decoder { struct decoder {

View file

@ -1,9 +1,10 @@
#ifndef DEVICE_H #ifndef DEVICE_H
#define DEVICE_H #define DEVICE_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include "common.h"
#include "coords.h" #include "coords.h"
#include "util/net.h" #include "util/net.h"

View file

@ -1,12 +1,12 @@
#ifndef DEVICEMSG_H #ifndef DEVICEMSG_H
#define DEVICEMSG_H #define DEVICEMSG_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <unistd.h> #include <unistd.h>
#include "common.h"
#define DEVICE_MSG_MAX_SIZE (1 << 18) // 256k #define DEVICE_MSG_MAX_SIZE (1 << 18) // 256k
// type: 1 byte; length: 4 bytes // type: 1 byte; length: 4 bytes
#define DEVICE_MSG_TEXT_MAX_LENGTH (DEVICE_MSG_MAX_SIZE - 5) #define DEVICE_MSG_TEXT_MAX_LENGTH (DEVICE_MSG_MAX_SIZE - 5)

View file

@ -1,10 +1,11 @@
#ifndef CONVERT_H #ifndef CONVERT_H
#define CONVERT_H #define CONVERT_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include <SDL2/SDL_events.h> #include <SDL2/SDL_events.h>
#include "common.h"
#include "control_msg.h" #include "control_msg.h"
bool bool

View file

@ -1,11 +1,12 @@
#ifndef FILE_HANDLER_H #ifndef FILE_HANDLER_H
#define FILE_HANDLER_H #define FILE_HANDLER_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include <SDL2/SDL_mutex.h> #include <SDL2/SDL_mutex.h>
#include <SDL2/SDL_thread.h> #include <SDL2/SDL_thread.h>
#include "common.h"
#include "adb.h" #include "adb.h"
#include "util/cbuf.h" #include "util/cbuf.h"

View file

@ -1,14 +1,14 @@
#ifndef FPSCOUNTER_H #ifndef FPSCOUNTER_H
#define FPSCOUNTER_H #define FPSCOUNTER_H
#include "common.h"
#include <stdatomic.h> #include <stdatomic.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <SDL2/SDL_mutex.h> #include <SDL2/SDL_mutex.h>
#include <SDL2/SDL_thread.h> #include <SDL2/SDL_thread.h>
#include "common.h"
struct fps_counter { struct fps_counter {
SDL_Thread *thread; SDL_Thread *thread;
SDL_mutex *mutex; SDL_mutex *mutex;

View file

@ -1,11 +1,12 @@
#ifndef INPUTMANAGER_H #ifndef INPUTMANAGER_H
#define INPUTMANAGER_H #define INPUTMANAGER_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "common.h"
#include "controller.h" #include "controller.h"
#include "fps_counter.h" #include "fps_counter.h"
#include "scrcpy.h" #include "scrcpy.h"

View file

@ -1,5 +1,7 @@
#include "scrcpy.h" #include "scrcpy.h"
#include "common.h"
#include <assert.h> #include <assert.h>
#include <stdbool.h> #include <stdbool.h>
#include <unistd.h> #include <unistd.h>
@ -7,7 +9,6 @@
#define SDL_MAIN_HANDLED // avoid link error on Linux Windows Subsystem #define SDL_MAIN_HANDLED // avoid link error on Linux Windows Subsystem
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "common.h"
#include "cli.h" #include "cli.h"
#include "util/log.h" #include "util/log.h"

View file

@ -1,11 +1,11 @@
#ifndef SC_OPENGL_H #ifndef SC_OPENGL_H
#define SC_OPENGL_H #define SC_OPENGL_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include <SDL2/SDL_opengl.h> #include <SDL2/SDL_opengl.h>
#include "common.h"
struct sc_opengl { struct sc_opengl {
const char *version; const char *version;
bool is_opengles; bool is_opengles;

View file

@ -1,11 +1,12 @@
#ifndef RECEIVER_H #ifndef RECEIVER_H
#define RECEIVER_H #define RECEIVER_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include <SDL2/SDL_mutex.h> #include <SDL2/SDL_mutex.h>
#include <SDL2/SDL_thread.h> #include <SDL2/SDL_thread.h>
#include "common.h"
#include "util/net.h" #include "util/net.h"
// receive events from the device // receive events from the device

View file

@ -1,12 +1,13 @@
#ifndef RECORDER_H #ifndef RECORDER_H
#define RECORDER_H #define RECORDER_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
#include <SDL2/SDL_mutex.h> #include <SDL2/SDL_mutex.h>
#include <SDL2/SDL_thread.h> #include <SDL2/SDL_thread.h>
#include "common.h"
#include "coords.h" #include "coords.h"
#include "scrcpy.h" #include "scrcpy.h"
#include "util/queue.h" #include "util/queue.h"

View file

@ -1,12 +1,12 @@
#ifndef SCRCPY_H #ifndef SCRCPY_H
#define SCRCPY_H #define SCRCPY_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "common.h"
enum sc_log_level { enum sc_log_level {
SC_LOG_LEVEL_DEBUG, SC_LOG_LEVEL_DEBUG,
SC_LOG_LEVEL_INFO, SC_LOG_LEVEL_INFO,

View file

@ -1,11 +1,12 @@
#ifndef SCREEN_H #ifndef SCREEN_H
#define SCREEN_H #define SCREEN_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
#include "common.h"
#include "coords.h" #include "coords.h"
#include "opengl.h" #include "opengl.h"

View file

@ -1,12 +1,13 @@
#ifndef SERVER_H #ifndef SERVER_H
#define SERVER_H #define SERVER_H
#include "common.h"
#include <stdatomic.h> #include <stdatomic.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <SDL2/SDL_thread.h> #include <SDL2/SDL_thread.h>
#include "common.h"
#include "adb.h" #include "adb.h"
#include "scrcpy.h" #include "scrcpy.h"
#include "util/log.h" #include "util/log.h"

View file

@ -1,13 +1,14 @@
#ifndef STREAM_H #ifndef STREAM_H
#define STREAM_H #define STREAM_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
#include <SDL2/SDL_atomic.h> #include <SDL2/SDL_atomic.h>
#include <SDL2/SDL_thread.h> #include <SDL2/SDL_thread.h>
#include "common.h"
#include "util/net.h" #include "util/net.h"
struct video_buffer; struct video_buffer;

View file

@ -1,14 +1,3 @@
// for portability (kill, readlink, strdup, strtok_r)
#define _POSIX_C_SOURCE 200809L
#define _BSD_SOURCE
// modern glibc will complain without this
#define _DEFAULT_SOURCE
#ifdef __APPLE__
# define _DARWIN_C_SOURCE // for strdup(), strtok_r(), memset_pattern4()
#endif
#include "util/process.h" #include "util/process.h"
#include <errno.h> #include <errno.h>

View file

@ -1,10 +1,10 @@
#ifndef TINYXPM_H #ifndef TINYXPM_H
#define TINYXPM_H #define TINYXPM_H
#include <SDL2/SDL.h>
#include "common.h" #include "common.h"
#include <SDL2/SDL.h>
SDL_Surface * SDL_Surface *
read_xpm(char *xpm[]); read_xpm(char *xpm[]);

View file

@ -1,11 +1,11 @@
#ifndef BUFFER_UTIL_H #ifndef BUFFER_UTIL_H
#define BUFFER_UTIL_H #define BUFFER_UTIL_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "common.h"
static inline void static inline void
buffer_write16be(uint8_t *buf, uint16_t value) { buffer_write16be(uint8_t *buf, uint16_t value) {
buf[0] = value >> 8; buf[0] = value >> 8;

View file

@ -2,11 +2,11 @@
#ifndef CBUF_H #ifndef CBUF_H
#define CBUF_H #define CBUF_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include <unistd.h> #include <unistd.h>
#include "common.h"
// To define a circular buffer type of 20 ints: // To define a circular buffer type of 20 ints:
// struct cbuf_int CBUF(int, 20); // struct cbuf_int CBUF(int, 20);
// //

View file

@ -1,10 +1,11 @@
#ifndef LOCK_H #ifndef LOCK_H
#define LOCK_H #define LOCK_H
#include "common.h"
#include <stdint.h> #include <stdint.h>
#include <SDL2/SDL_mutex.h> #include <SDL2/SDL_mutex.h>
#include "common.h"
#include "log.h" #include "log.h"
static inline void static inline void

View file

@ -1,6 +1,8 @@
#ifndef NET_H #ifndef NET_H
#define NET_H #define NET_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <SDL2/SDL_platform.h> #include <SDL2/SDL_platform.h>
@ -17,8 +19,6 @@
typedef int socket_t; typedef int socket_t;
#endif #endif
#include "common.h"
bool bool
net_init(void); net_init(void);

View file

@ -1,10 +1,10 @@
#ifndef SC_PROCESS_H #ifndef SC_PROCESS_H
#define SC_PROCESS_H #define SC_PROCESS_H
#include <stdbool.h>
#include "common.h" #include "common.h"
#include <stdbool.h>
#ifdef _WIN32 #ifdef _WIN32
// not needed here, but winsock2.h must never be included AFTER windows.h // not needed here, but winsock2.h must never be included AFTER windows.h

View file

@ -2,12 +2,12 @@
#ifndef QUEUE_H #ifndef QUEUE_H
#define QUEUE_H #define QUEUE_H
#include "common.h"
#include <assert.h> #include <assert.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include "common.h"
// To define a queue type of "struct foo": // To define a queue type of "struct foo":
// struct queue_foo QUEUE(struct foo); // struct queue_foo QUEUE(struct foo);
#define QUEUE(TYPE) { \ #define QUEUE(TYPE) { \

View file

@ -1,11 +1,11 @@
#ifndef STRUTIL_H #ifndef STRUTIL_H
#define STRUTIL_H #define STRUTIL_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include "common.h"
// like strncpy, except: // like strncpy, except:
// - it copies at most n-1 chars // - it copies at most n-1 chars
// - the dest string is nul-terminated // - the dest string is nul-terminated

View file

@ -1,10 +1,11 @@
#ifndef VIDEO_BUFFER_H #ifndef VIDEO_BUFFER_H
#define VIDEO_BUFFER_H #define VIDEO_BUFFER_H
#include "common.h"
#include <stdbool.h> #include <stdbool.h>
#include <SDL2/SDL_mutex.h> #include <SDL2/SDL_mutex.h>
#include "common.h"
#include "fps_counter.h" #include "fps_counter.h"
// forward declarations // forward declarations

View file

@ -1,3 +1,5 @@
#include "common.h"
#include <assert.h> #include <assert.h>
#include "util/buffer_util.h" #include "util/buffer_util.h"

View file

@ -1,3 +1,5 @@
#include "common.h"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>

View file

@ -1,7 +1,8 @@
#include "common.h"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include "common.h"
#include "cli.h" #include "cli.h"
#include "scrcpy.h" #include "scrcpy.h"

View file

@ -1,3 +1,5 @@
#include "common.h"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>

View file

@ -1,3 +1,5 @@
#include "common.h"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>

View file

@ -1,3 +1,5 @@
#include "common.h"
#include <assert.h> #include <assert.h>
#include "util/queue.h" #include "util/queue.h"

View file

@ -1,3 +1,5 @@
#include "common.h"
#include <assert.h> #include <assert.h>
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>