Skip to content

Commit

Permalink
Define feature test macros in common.h
Browse files Browse the repository at this point in the history
This enables necessary functions once for all.

As a consequence, define common.h before any other header.
  • Loading branch information
rom1v committed Jan 17, 2021
1 parent 59feb2a commit ab912c2
Show file tree
Hide file tree
Showing 37 changed files with 77 additions and 53 deletions.
4 changes: 2 additions & 2 deletions app/src/adb.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef SC_ADB_H
#define SC_ADB_H

#include "common.h"

#include <stdbool.h>
#include <inttypes.h>

#include "common.h"

#include "util/process.h"

process_t
Expand Down
3 changes: 2 additions & 1 deletion app/src/cli.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#ifndef SCRCPY_CLI_H
#define SCRCPY_CLI_H

#include "common.h"

#include <stdbool.h>

#include "common.h"
#include "scrcpy.h"

struct scrcpy_cli_args {
Expand Down
7 changes: 7 additions & 0 deletions app/src/compat.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#ifndef 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 <libavformat/version.h>
#include <SDL2/SDL_version.h>
Expand Down
3 changes: 2 additions & 1 deletion app/src/control_msg.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#ifndef CONTROLMSG_H
#define CONTROLMSG_H

#include "common.h"

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#include "common.h"
#include "android/input.h"
#include "android/keycodes.h"
#include "coords.h"
Expand Down
3 changes: 2 additions & 1 deletion app/src/controller.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#ifndef CONTROLLER_H
#define CONTROLLER_H

#include "common.h"

#include <stdbool.h>
#include <SDL2/SDL_mutex.h>
#include <SDL2/SDL_thread.h>

#include "common.h"
#include "control_msg.h"
#include "receiver.h"
#include "util/cbuf.h"
Expand Down
4 changes: 2 additions & 2 deletions app/src/decoder.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef DECODER_H
#define DECODER_H

#include "common.h"

#include <stdbool.h>
#include <libavformat/avformat.h>

#include "common.h"

struct video_buffer;

struct decoder {
Expand Down
3 changes: 2 additions & 1 deletion app/src/device.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#ifndef DEVICE_H
#define DEVICE_H

#include "common.h"

#include <stdbool.h>

#include "common.h"
#include "coords.h"
#include "util/net.h"

Expand Down
4 changes: 2 additions & 2 deletions app/src/device_msg.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef DEVICEMSG_H
#define DEVICEMSG_H

#include "common.h"

#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>

#include "common.h"

#define DEVICE_MSG_MAX_SIZE (1 << 18) // 256k
// type: 1 byte; length: 4 bytes
#define DEVICE_MSG_TEXT_MAX_LENGTH (DEVICE_MSG_MAX_SIZE - 5)
Expand Down
3 changes: 2 additions & 1 deletion app/src/event_converter.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#ifndef CONVERT_H
#define CONVERT_H

#include "common.h"

#include <stdbool.h>
#include <SDL2/SDL_events.h>

#include "common.h"
#include "control_msg.h"

bool
Expand Down
3 changes: 2 additions & 1 deletion app/src/file_handler.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#ifndef FILE_HANDLER_H
#define FILE_HANDLER_H

#include "common.h"

#include <stdbool.h>
#include <SDL2/SDL_mutex.h>
#include <SDL2/SDL_thread.h>

#include "common.h"
#include "adb.h"
#include "util/cbuf.h"

Expand Down
4 changes: 2 additions & 2 deletions app/src/fps_counter.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#ifndef FPSCOUNTER_H
#define FPSCOUNTER_H

#include "common.h"

#include <stdatomic.h>
#include <stdbool.h>
#include <stdint.h>
#include <SDL2/SDL_mutex.h>
#include <SDL2/SDL_thread.h>

#include "common.h"

struct fps_counter {
SDL_Thread *thread;
SDL_mutex *mutex;
Expand Down
3 changes: 2 additions & 1 deletion app/src/input_manager.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#ifndef INPUTMANAGER_H
#define INPUTMANAGER_H

#include "common.h"

#include <stdbool.h>

#include <SDL2/SDL.h>

#include "common.h"
#include "controller.h"
#include "fps_counter.h"
#include "scrcpy.h"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include "scrcpy.h"

#include "common.h"

#include <assert.h>
#include <stdbool.h>
#include <unistd.h>
#include <libavformat/avformat.h>
#define SDL_MAIN_HANDLED // avoid link error on Linux Windows Subsystem
#include <SDL2/SDL.h>

#include "common.h"
#include "cli.h"
#include "util/log.h"

Expand Down
4 changes: 2 additions & 2 deletions app/src/opengl.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef SC_OPENGL_H
#define SC_OPENGL_H

#include "common.h"

#include <stdbool.h>
#include <SDL2/SDL_opengl.h>

#include "common.h"

struct sc_opengl {
const char *version;
bool is_opengles;
Expand Down
3 changes: 2 additions & 1 deletion app/src/receiver.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#ifndef RECEIVER_H
#define RECEIVER_H

#include "common.h"

#include <stdbool.h>
#include <SDL2/SDL_mutex.h>
#include <SDL2/SDL_thread.h>

#include "common.h"
#include "util/net.h"

// receive events from the device
Expand Down
3 changes: 2 additions & 1 deletion app/src/recorder.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#ifndef RECORDER_H
#define RECORDER_H

#include "common.h"

#include <stdbool.h>
#include <libavformat/avformat.h>
#include <SDL2/SDL_mutex.h>
#include <SDL2/SDL_thread.h>

#include "common.h"
#include "coords.h"
#include "scrcpy.h"
#include "util/queue.h"
Expand Down
4 changes: 2 additions & 2 deletions app/src/scrcpy.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef SCRCPY_H
#define SCRCPY_H

#include "common.h"

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#include "common.h"

enum sc_log_level {
SC_LOG_LEVEL_DEBUG,
SC_LOG_LEVEL_INFO,
Expand Down
3 changes: 2 additions & 1 deletion app/src/screen.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#ifndef SCREEN_H
#define SCREEN_H

#include "common.h"

#include <stdbool.h>
#include <SDL2/SDL.h>
#include <libavformat/avformat.h>

#include "common.h"
#include "coords.h"
#include "opengl.h"

Expand Down
3 changes: 2 additions & 1 deletion app/src/server.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#ifndef SERVER_H
#define SERVER_H

#include "common.h"

#include <stdatomic.h>
#include <stdbool.h>
#include <stdint.h>
#include <SDL2/SDL_thread.h>

#include "common.h"
#include "adb.h"
#include "scrcpy.h"
#include "util/log.h"
Expand Down
3 changes: 2 additions & 1 deletion app/src/stream.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#ifndef STREAM_H
#define STREAM_H

#include "common.h"

#include <stdbool.h>
#include <stdint.h>
#include <libavformat/avformat.h>
#include <SDL2/SDL_atomic.h>
#include <SDL2/SDL_thread.h>

#include "common.h"
#include "util/net.h"

struct video_buffer;
Expand Down
11 changes: 0 additions & 11 deletions app/src/sys/unix/process.c
Original file line number Diff line number Diff line change
@@ -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 <errno.h>
Expand Down
4 changes: 2 additions & 2 deletions app/src/tiny_xpm.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef TINYXPM_H
#define TINYXPM_H

#include <SDL2/SDL.h>

#include "common.h"

#include <SDL2/SDL.h>

SDL_Surface *
read_xpm(char *xpm[]);

Expand Down
4 changes: 2 additions & 2 deletions app/src/util/buffer_util.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef BUFFER_UTIL_H
#define BUFFER_UTIL_H

#include "common.h"

#include <stdbool.h>
#include <stdint.h>

#include "common.h"

static inline void
buffer_write16be(uint8_t *buf, uint16_t value) {
buf[0] = value >> 8;
Expand Down
4 changes: 2 additions & 2 deletions app/src/util/cbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#ifndef CBUF_H
#define CBUF_H

#include "common.h"

#include <stdbool.h>
#include <unistd.h>

#include "common.h"

// To define a circular buffer type of 20 ints:
// struct cbuf_int CBUF(int, 20);
//
Expand Down
3 changes: 2 additions & 1 deletion app/src/util/lock.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#ifndef LOCK_H
#define LOCK_H

#include "common.h"

#include <stdint.h>
#include <SDL2/SDL_mutex.h>

#include "common.h"
#include "log.h"

static inline void
Expand Down
4 changes: 2 additions & 2 deletions app/src/util/net.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef NET_H
#define NET_H

#include "common.h"

#include <stdbool.h>
#include <stdint.h>
#include <SDL2/SDL_platform.h>
Expand All @@ -17,8 +19,6 @@
typedef int socket_t;
#endif

#include "common.h"

bool
net_init(void);

Expand Down
4 changes: 2 additions & 2 deletions app/src/util/process.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef SC_PROCESS_H
#define SC_PROCESS_H

#include <stdbool.h>

#include "common.h"

#include <stdbool.h>

#ifdef _WIN32

// not needed here, but winsock2.h must never be included AFTER windows.h
Expand Down
Loading

0 comments on commit ab912c2

Please sign in to comment.