Moonlight-XboxOG latest
Moonlight Xbox OG is a port of the Moonlight Game Streaming client to the original Xbox console.
ffmpeg_compat.h
Go to the documentation of this file.
1
6#pragma once
7
8#ifdef NXDK
9
10 #include <errno.h>
11 #include <stdarg.h>
12 #include <stddef.h>
13 #include <stdint.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include <sys/types.h>
17 #include <wchar.h>
18
19 #ifdef __cplusplus
20extern "C" {
21 #endif
22
23 #ifndef ENOSYS
25 #define ENOSYS 38
26 #endif
27
28 #ifndef O_BINARY
30 #define O_BINARY 0
31 #endif
32
33 #ifndef F_SETFD
35 #define F_SETFD 2
36 #endif
37
38 #ifndef FD_CLOEXEC
40 #define FD_CLOEXEC 1
41 #endif
42
43 #ifndef CP_ACP
45 #define CP_ACP 0U
46 #endif
47
48 #ifndef CP_UTF8
50 #define CP_UTF8 65001U
51 #endif
52
53 #ifndef MB_ERR_INVALID_CHARS
55 #define MB_ERR_INVALID_CHARS 0x00000008UL
56 #endif
57
58 #ifndef WC_ERR_INVALID_CHARS
60 #define WC_ERR_INVALID_CHARS 0x00000080UL
61 #endif
62
64 #define access moonlight_nxdk_ffmpeg_access
66 #define close moonlight_nxdk_ffmpeg_close
68 #define fcntl moonlight_nxdk_ffmpeg_fcntl
70 #define fdopen moonlight_nxdk_ffmpeg_fdopen
72 #define isatty moonlight_nxdk_ffmpeg_isatty
74 #define GetFullPathNameW moonlight_nxdk_ffmpeg_GetFullPathNameW
76 #define mkstemp moonlight_nxdk_ffmpeg_mkstemp
78 #define MultiByteToWideChar moonlight_nxdk_ffmpeg_MultiByteToWideChar
80 #define open moonlight_nxdk_ffmpeg_open
82 #define strerror_r moonlight_nxdk_ffmpeg_strerror_r
84 #define tempnam moonlight_nxdk_ffmpeg_tempnam
86 #define usleep moonlight_nxdk_ffmpeg_usleep
88 #define WideCharToMultiByte moonlight_nxdk_ffmpeg_WideCharToMultiByte
89
97 static inline int moonlight_nxdk_ffmpeg_access(const char *path, int mode) {
98 (void) path;
99 (void) mode;
100 errno = ENOSYS;
101 return -1;
102 }
103
110 static inline int moonlight_nxdk_ffmpeg_close(int fd) {
111 (void) fd;
112 return 0;
113 }
114
123 static inline int moonlight_nxdk_ffmpeg_fcntl(int fd, int cmd, ...) {
124 (void) fd;
125 (void) cmd;
126 errno = ENOSYS;
127 return -1;
128 }
129
137 static inline FILE *moonlight_nxdk_ffmpeg_fdopen(int fd, const char *mode) {
138 (void) fd;
139 (void) mode;
140 errno = ENOSYS;
141 return NULL;
142 }
143
150 static inline int moonlight_nxdk_ffmpeg_isatty(int fd) {
151 (void) fd;
152 return 0;
153 }
154
160 static inline int64_t gethrtime(void) {
161 return 0;
162 }
163
173 static inline unsigned long moonlight_nxdk_ffmpeg_GetFullPathNameW(const wchar_t *path, unsigned long buffer_size, wchar_t *buffer, wchar_t **file_part) {
174 size_t length;
175 wchar_t *last_separator;
176
177 if (path == NULL) {
178 return 0;
179 }
180
181 length = wcslen(path);
182 last_separator = NULL;
183 for (size_t index = 0; index < length; ++index) {
184 if (path[index] == L'\\' || path[index] == L'/') {
185 last_separator = (wchar_t *) &path[index + 1U];
186 }
187 }
188
189 if (file_part != NULL) {
190 *file_part = last_separator;
191 }
192
193 if (buffer == NULL || buffer_size == 0U) {
194 return (unsigned long) (length + 1U);
195 }
196
197 if (length + 1U > buffer_size) {
198 if (buffer_size > 0U) {
199 wcsncpy(buffer, path, buffer_size - 1U);
200 buffer[buffer_size - 1U] = L'\0';
201 }
202 return (unsigned long) (length + 1U);
203 }
204
205 wcscpy(buffer, path);
206 return (unsigned long) length;
207 }
208
215 static inline int moonlight_nxdk_ffmpeg_mkstemp(char *pattern) {
216 (void) pattern;
217 errno = ENOSYS;
218 return -1;
219 }
220
232 static inline int moonlight_nxdk_ffmpeg_MultiByteToWideChar(unsigned int code_page, unsigned long flags, const char *source, int source_length, wchar_t *destination, int destination_length) {
233 size_t length;
234
235 (void) code_page;
236 (void) flags;
237
238 if (source == NULL) {
239 return 0;
240 }
241
242 length = source_length >= 0 ? (size_t) source_length : strlen(source) + 1U;
243 if (destination == NULL || destination_length <= 0) {
244 return (int) length;
245 }
246
247 if ((size_t) destination_length < length) {
248 return 0;
249 }
250
251 for (size_t index = 0; index < length; ++index) {
252 destination[index] = (unsigned char) source[index];
253 }
254
255 return (int) length;
256 }
257
266 static inline int moonlight_nxdk_ffmpeg_open(const char *path, int flags, ...) {
267 (void) path;
268 (void) flags;
269 errno = ENOSYS;
270 return -1;
271 }
272
281 static inline int moonlight_nxdk_ffmpeg_strerror_r(int errnum, char *buffer, size_t buffer_size) {
282 const char *message;
283
284 if (buffer == NULL || buffer_size == 0) {
285 errno = EINVAL;
286 return -1;
287 }
288
289 message = strerror(errnum);
290 if (message == NULL) {
291 message = "Unknown error";
292 }
293
294 strncpy(buffer, message, buffer_size - 1U);
295 buffer[buffer_size - 1U] = '\0';
296 return 0;
297 }
298
306 static inline char *moonlight_nxdk_ffmpeg_tempnam(const char *dir, const char *prefix) {
307 (void) dir;
308 (void) prefix;
309 errno = ENOSYS;
310 return NULL;
311 }
312
319 static inline int moonlight_nxdk_ffmpeg_usleep(unsigned int usec) {
320 (void) usec;
321 return 0;
322 }
323
337 static inline int moonlight_nxdk_ffmpeg_WideCharToMultiByte(unsigned int code_page, unsigned long flags, const wchar_t *source, int source_length, char *destination, int destination_length, const char *default_char, int *used_default_char) {
338 size_t length;
339
340 (void) code_page;
341 (void) flags;
342 (void) default_char;
343 if (used_default_char != NULL) {
344 *used_default_char = 0;
345 }
346
347 if (source == NULL) {
348 return 0;
349 }
350
351 length = source_length >= 0 ? (size_t) source_length : wcslen(source) + 1U;
352 if (destination == NULL || destination_length <= 0) {
353 return (int) length;
354 }
355
356 if ((size_t) destination_length < length) {
357 return 0;
358 }
359
360 for (size_t index = 0; index < length; ++index) {
361 destination[index] = (char) source[index];
362 }
363
364 return (int) length;
365 }
366
367 #ifdef __cplusplus
368}
369 #endif
370
371#endif
#define ENOSYS
Error code used when an FFmpeg compatibility operation is unsupported.
Definition ffmpeg_compat.h:25