|
1 | | -#ifndef PLATFORM_COMPAT_H |
2 | | -#define PLATFORM_COMPAT_H |
3 | | - |
4 | | -#ifndef _GNU_SOURCE |
5 | | -#define _GNU_SOURCE |
6 | | -#endif |
7 | | - |
8 | | -#ifndef _POSIX_C_SOURCE |
9 | | -#define _POSIX_C_SOURCE 200809L |
10 | | -#endif |
| 1 | +#pragma once |
11 | 2 |
|
| 3 | +/* ===================== PLATFORM DETECTION ===================== */ |
12 | 4 | #ifdef _WIN32 |
13 | | -#include <direct.h> |
14 | | -#define strncasecmp _strnicmp |
15 | | -#define strcasecmp _stricmp |
| 5 | +#define PLATFORM_WINDOWS 1 |
| 6 | +#else |
| 7 | +#define PLATFORM_WINDOWS 0 |
16 | 8 | #endif |
17 | 9 |
|
18 | 10 | #ifdef __APPLE__ |
19 | | -#include <strings.h> // for strncasecmp, strcasecmp |
20 | | -#include <sys/types.h> |
21 | | -#include <sys/sysctl.h> |
22 | | -#endif |
23 | | - |
24 | | -#include "mupdf/fitz.h" |
25 | | - |
26 | | -#ifndef FZ_STEXT_CLIP |
27 | | -#define FZ_STEXT_CLIP 1 |
28 | | -#endif |
29 | | - |
30 | | -#ifndef FZ_STEXT_ACCURATE_BBOXES |
31 | | -#define FZ_STEXT_ACCURATE_BBOXES 2 |
32 | | -#endif |
33 | | - |
34 | | -#ifndef FZ_STEXT_COLLECT_STYLES |
35 | | -#define FZ_STEXT_COLLECT_STYLES 32768 |
36 | | -#endif |
37 | | - |
38 | | -#ifndef FZ_STEXT_USE_GID_FOR_UNKNOWN_UNICODE |
39 | | -#define FZ_STEXT_USE_GID_FOR_UNKNOWN_UNICODE 4 |
40 | | -#endif |
41 | | - |
42 | | -#ifndef FZ_STEXT_PRESERVE_LIGATURES |
43 | | -#define FZ_STEXT_PRESERVE_LIGATURES 8 |
44 | | -#endif |
45 | | - |
46 | | -#ifndef FZ_STEXT_PRESERVE_WHITESPACE |
47 | | -#define FZ_STEXT_PRESERVE_WHITESPACE 16 |
48 | | -#endif |
49 | | - |
50 | | -#ifndef FZ_FONT_FLAG_BOLD |
51 | | -#define FZ_FONT_FLAG_BOLD 1 |
| 11 | +#define PLATFORM_MAC 1 |
| 12 | +#include <TargetConditionals.h> |
| 13 | +#else |
| 14 | +#define PLATFORM_MAC 0 |
52 | 15 | #endif |
53 | 16 |
|
54 | | -#ifndef FZ_FONT_FLAG_ITALIC |
55 | | -#define FZ_FONT_FLAG_ITALIC 2 |
| 17 | +#ifdef __linux__ |
| 18 | +#define PLATFORM_LINUX 1 |
| 19 | +#else |
| 20 | +#define PLATFORM_LINUX 0 |
56 | 21 | #endif |
57 | 22 |
|
| 23 | +/* ===================== EXPORT MACRO ===================== */ |
| 24 | +#ifndef EXPORT |
58 | 25 | #ifdef _WIN32 |
59 | 26 | #define EXPORT __declspec(dllexport) |
60 | 27 | #else |
61 | | -#define EXPORT __attribute__((visibility("default"))) |
| 28 | +#define EXPORT |
| 29 | +#endif |
62 | 30 | #endif |
63 | 31 |
|
64 | | -/* --- Added CPU detection helper for multiprocess --- */ |
65 | | -static inline int get_num_cores(void) |
66 | | -{ |
67 | | - int num_cores = 1; |
| 32 | +/* ===================== LEGACY TYPE FIXES FOR MAC ===================== */ |
| 33 | +#if PLATFORM_MAC |
| 34 | +typedef unsigned int u_int; |
| 35 | +typedef unsigned char u_char; |
| 36 | +typedef unsigned short u_short; |
68 | 37 |
|
69 | | -#if defined(_SC_NPROCESSORS_ONLN) |
70 | | - long n = sysconf(_SC_NPROCESSORS_ONLN); |
71 | | - if (n > 0) |
72 | | - num_cores = (int)n; |
73 | | -#elif defined(__APPLE__) |
74 | | - int n; |
75 | | - size_t len = sizeof(n); |
76 | | - int mib[2] = {CTL_HW, HW_AVAILCPU}; |
77 | | - if (sysctl(mib, 2, &n, &len, NULL, 0) == 0 && n > 0) |
78 | | - num_cores = n; |
| 38 | +#include <unistd.h> |
| 39 | +#include <sys/types.h> |
| 40 | +#include <sys/sysctl.h> |
| 41 | +#include <strings.h> |
| 42 | + |
| 43 | +/* get number of CPU cores */ |
| 44 | +static int get_num_cores() { |
| 45 | + int nm[2]; |
| 46 | + size_t len = sizeof(int); |
| 47 | + int count; |
| 48 | + nm[0] = CTL_HW; |
| 49 | + nm[1] = HW_NCPU; |
| 50 | + sysctl(nm, 2, &count, &len, NULL, 0); |
| 51 | + return count; |
| 52 | +} |
79 | 53 | #endif |
80 | 54 |
|
81 | | - return num_cores; |
82 | | -} |
| 55 | +/* ===================== MATH/UTILS ===================== */ |
| 56 | +#include <math.h> |
| 57 | +#include <stdint.h> |
| 58 | +#include <stdbool.h> |
83 | 59 |
|
84 | | -#endif // PLATFORM_COMPAT_H |
| 60 | +#ifndef NAN |
| 61 | +#define NAN (__builtin_nanf("0x7fc00000")) |
| 62 | +#endif |
0 commit comments