Debian Codegraph @

src/os-dependent.h

raw
1 /*
2 * Copyright (C) 2005-2021 Team Kodi (https://kodi.tv)
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 * See LICENSE.md for more information.
6 */
7
8 #pragma once
9
10 #include <cstdint>
11
12 #if (defined(_WIN32) || defined(_WIN64))
13
14 #include <wchar.h>
15
16 /* Handling of 2-byte Windows wchar strings */
17 #define WcsLen wcslen
18 #define WcsToMbs wcstombs
19 typedef wchar_t Wchar_t; /* sizeof(wchar_t) = 2 bytes on Windows */
20
21 #ifndef _SSIZE_T_DEFINED
22 #ifdef _WIN64
23 typedef __int64 ssize_t;
24 #else
25 typedef _W64 int ssize_t;
26 #endif
27 #define _SSIZE_T_DEFINED
28 #endif
29
30 /* Prevent deprecation warnings */
31 #define strnicmp _strnicmp
32
33 #define PATH_SEPARATOR_CHAR '\\'
34
35 #else
36
37 #if (defined(TARGET_LINUX) || defined(TARGET_DARWIN))
38 #include <sys/types.h>
39 #include <chrono>
40 #include <cstring>
41
42 #define strnicmp(X,Y,N) strncasecmp(X,Y,N)
43
44 inline unsigned long long GetTickCount64(void)
45 {
46 auto now = std::chrono::steady_clock::now();
47 return std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
48 };
49
50 #define PATH_SEPARATOR_CHAR '/'
51
52 #if defined(__APPLE__)
53 // for HRESULT
54 #include <CoreFoundation/CFPlugInCOM.h>
55 #endif
56
57 /* Handling of 2-byte Windows wchar strings on non-Windows targets
58 * Used by The MediaPortal and ForTheRecord pvr addons
59 */
60 typedef uint16_t Wchar_t; /* sizeof(wchar_t) = 4 bytes on Linux, but the MediaPortal buffer files have 2-byte wchars */
61
62 /* This is a replacement of the Windows wcslen() function which assumes that
63 * wchar_t is a 2-byte character.
64 * It is used for processing Windows wchar strings
65 */
66 inline size_t WcsLen(const Wchar_t *str)
67 {
68 const unsigned short *eos = (const unsigned short*)str;
69 while( *eos++ ) ;
70 return( (size_t)(eos - (const unsigned short*)str) -1);
71 };
72
73 /* This is a replacement of the Windows wcstombs() function which assumes that
74 * wchar_t is a 2-byte character.
75 * It is used for processing Windows wchar strings
76 */
77 inline size_t WcsToMbs(char *s, const Wchar_t *w, size_t n)
78 {
79 size_t i = 0;
80 const unsigned short *wc = (const unsigned short*) w;
81 while(wc[i] && (i < n))
82 {
83 s[i] = wc[i];
84 ++i;
85 }
86 if (i < n) s[i] = '\0';
87
88 return (i);
89 };
90
91 #endif /* TARGET_LINUX || TARGET_DARWIN */
92
93 #endif
94
95 typedef long LONG;
96 #if !defined(__APPLE__)
97 typedef LONG HRESULT;
98 #endif
99
100 #ifndef FAILED
101 #define FAILED(Status) ((HRESULT)(Status)<0)
102 #endif
103
104 #ifndef SUCCEEDED
105 #define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
106 #endif
107
108 #define _FILE_OFFSET_BITS 64
109 #define FILE_BEGIN 0
110 #define FILE_CURRENT 1
111 #define FILE_END 2
112
113 #ifndef S_OK
114 #define S_OK 0L
115 #endif
116
117 #ifndef S_FALSE
118 #define S_FALSE 1L
119 #endif
120
121 // Error codes
122 #define ERROR_FILENAME_EXCED_RANGE 206L
123 #define ERROR_INVALID_NAME 123L
124
125 #ifndef E_OUTOFMEMORY
126 #define E_OUTOFMEMORY 0x8007000EL
127 #endif
128
129 #ifndef E_FAIL
130 #define E_FAIL 0x8004005EL
131 #endif
132
133 // Additional typedefs
134 typedef uint8_t byte;