1 // This program is free software; you can redistribute it and/or modify
2 // it under the terms of the GNU General Public License as published by
3 // the Free Software Foundation; either version 2 of the License, or
4 // (at your option) any later version.
5 //
6 // This program is distributed in the hope that it will be useful,
7 // but WITHOUT ANY WARRANTY; without even the implied warranty of
8 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9 // GNU General Public License for more details.
10 //
11 // You should have received a copy of the GNU General Public License
12 // along with this program; if not, write to the Free Software
13 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit
14 // http://www.gnu.org/copyleft/gpl.html .
15 //
16 // Linking Avisynth statically or dynamically with other modules is making a
17 // combined work based on Avisynth.  Thus, the terms and conditions of the GNU
18 // General Public License cover the whole combination.
19 //
20 // As a special exception, the copyright holders of Avisynth give you
21 // permission to link Avisynth with independent modules that communicate with
22 // Avisynth solely through the interfaces defined in avisynth.h, regardless of the license
23 // terms of these independent modules, and to copy and distribute the
24 // resulting combined work under terms of your choice, provided that
25 // every copy of the combined work is accompanied by a complete copy of
26 // the source code of Avisynth (the version of Avisynth used to produce the
27 // combined work), being distributed under the terms of the GNU General
28 // Public License plus this exception.  An independent module is a module
29 // which is not derived from or based on Avisynth, such as 3rd-party filters,
30 // import and export plugins, or graphical user interfaces.
31 
32 #ifdef AVS_POSIX
33 #ifndef AVSCORE_POSIX_H
34 #define AVSCORE_POSIX_H
35 
36 #ifdef __cplusplus
37 #include <cstring>
38 #endif
39 #include <strings.h>
40 #include <unistd.h>
41 
42 // Define these MSVC-extension used in Avisynth
43 #define __single_inheritance
44 
45 // These things don't exist in Linux
46 #if defined(AVS_HAIKU)
47 #undef __declspec
48 #endif
49 #define __declspec(x)
50 #define lstrlen strlen
51 #define lstrcmp strcmp
52 #define lstrcmpi strcasecmp
53 #define _stricmp strcasecmp
54 #define _strnicmp strncasecmp
55 #define _strdup strdup
56 #define SetCurrentDirectory(x) chdir(x)
57 #define SetCurrentDirectoryW(x) chdir(x)
58 #define GetCurrentDirectoryW(x) getcwd(x)
59 #define _putenv putenv
60 #define _alloca alloca
61 
62 // Borrowing some compatibility macros from AvxSynth, slightly modified
63 #define UInt32x32To64(a, b) ((uint64_t)(((uint64_t)((uint32_t)(a))) * ((uint32_t)(b))))
64 #define Int64ShrlMod32(a, b) ((uint64_t)((uint64_t)(a) >> (b)))
65 #define Int32x32To64(a, b)  ((int64_t)(((int64_t)((long)(a))) * ((long)(b))))
66 
67 #define InterlockedIncrement(x) __sync_add_and_fetch((x), 1)
68 #define InterlockedDecrement(x) __sync_sub_and_fetch((x), 1)
69 #define MulDiv(nNumber, nNumerator, nDenominator)   (int32_t) (((int64_t) (nNumber) * (int64_t) (nNumerator) + (int64_t) ((nDenominator)/2)) / (int64_t) (nDenominator))
70 
71 #ifndef TRUE
72 #define TRUE  true
73 #endif
74 
75 #ifndef FALSE
76 #define FALSE false
77 #endif
78 
79 #define S_FALSE       (0x00000001)
80 #define E_FAIL        (0x80004005)
81 #define FAILED(hr)    ((hr) & 0x80000000)
82 #define SUCCEEDED(hr) (!FAILED(hr))
83 
84 // Statuses copied from comments in exception.cpp
85 #define STATUS_GUARD_PAGE_VIOLATION 0x80000001
86 #define STATUS_DATATYPE_MISALIGNMENT 0x80000002
87 #define STATUS_BREAKPOINT 0x80000003
88 #define STATUS_SINGLE_STEP 0x80000004
89 #define STATUS_ACCESS_VIOLATION 0xc0000005
90 #define STATUS_IN_PAGE_ERROR 0xc0000006
91 #define STATUS_INVALID_HANDLE 0xc0000008
92 #define STATUS_NO_MEMORY 0xc0000017
93 #define STATUS_ILLEGAL_INSTRUCTION 0xc000001d
94 #define STATUS_NONCONTINUABLE_EXCEPTION 0xc0000025
95 #define STATUS_INVALID_DISPOSITION 0xc0000026
96 #define STATUS_ARRAY_BOUNDS_EXCEEDED 0xc000008c
97 #define STATUS_FLOAT_DENORMAL_OPERAND 0xc000008d
98 #define STATUS_FLOAT_DIVIDE_BY_ZERO 0xc000008e
99 #define STATUS_FLOAT_INEXACT_RESULT 0xc000008f
100 #define STATUS_FLOAT_INVALID_OPERATION 0xc0000090
101 #define STATUS_FLOAT_OVERFLOW 0xc0000091
102 #define STATUS_FLOAT_STACK_CHECK 0xc0000092
103 #define STATUS_FLOAT_UNDERFLOW 0xc0000093
104 #define STATUS_INTEGER_DIVIDE_BY_ZERO 0xc0000094
105 #define STATUS_INTEGER_OVERFLOW 0xc0000095
106 #define STATUS_PRIVILEGED_INSTRUCTION 0xc0000096
107 #define STATUS_STACK_OVERFLOW 0xc00000fd
108 
109 // Calling convension
110 #ifndef AVS_HAIKU
111 #define __stdcall
112 #define __cdecl
113 #endif
114 
115 // PowerPC OS X is really niche these days, but this painless equivocation
116 // of the function/macro names used in posix_get_available_memory()
117 // is all it takes to let it work.  The G5 was 64-bit, and if 10.5 Leopard
118 // can run in native 64-bit, it probably uses the names in that block as-is.
119 #ifdef AVS_MACOS
120 #ifdef PPC32
121 #define vm_statistics64_data_t vm_statistics_data_t
122 #define HOST_VM_INFO64_COUNT HOST_VM_INFO_COUNT
123 #define HOST_VM_INFO64 HOST_VM_INFO
124 #define host_statistics64 host_statistics
125 #endif // PPC32
126 #endif // AVS_MACOS
127 
128 #endif // AVSCORE_POSIX_H
129 #endif // AVS_POSIX
130