[vlc-commits] [Git][videolan/vlc][master] 3 commits: windows: use inline functions to redirect POSIX file API
Steve Lhomme (@robUx4)
gitlab at videolan.org
Fri Mar 3 14:11:17 UTC 2023
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
f3da50cd by Steve Lhomme at 2023-03-03T13:57:15+00:00
windows: use inline functions to redirect POSIX file API
Depend on _CRT_INTERNAL_NONSTDC_NAMES to detect if the aliases are
missing or not.
- - - - -
e58ce9d4 by Steve Lhomme at 2023-03-03T13:57:15+00:00
vlc_fixups: define C/POSIX features when_CRT_DECLARE_NONSTDC_NAMES is not set
This is the build setup to be compatible with Xbox builds.
- - - - -
e09c4f90 by Steve Lhomme at 2023-03-03T13:57:15+00:00
fixups: force _CRT_DECLARE_NONSTDC_NAMES when compiling for Xbox
This way we won't use API calls not available on Xbox.
We might as well set it for MSVC desktop builds too to make sure we always
keep Xbox compatibility.
- - - - -
2 changed files:
- compat/windows/unistd.h
- include/vlc_fixups.h
Changes:
=====================================
compat/windows/unistd.h
=====================================
@@ -9,19 +9,14 @@
// Windows is not a real POSIX system and doesn't provide this header
// provide a dummy one so the code can compile
-#if defined(_GAMING_XBOX_SCARLETT) || defined(_GAMING_XBOX_XBOXONE) || defined(_XBOX_ONE)
-# define _CRT_DECLARE_NONSTDC_NAMES 0
-#else
// many functions commonly found in unistd.h are found in io.h and process.h
-# define _CRT_DECLARE_NONSTDC_NAMES 1
-#endif
#include <io.h>
#include <process.h>
// defines corresponding to stdin/stdout/stderr without the __acrt_iob_func() call
-#define STDIN_FILENO 0
-#define STDOUT_FILENO 1
-#define STDERR_FILENO 2
+#define STDIN_FILENO 0
+#define STDOUT_FILENO 1
+#define STDERR_FILENO 2
// _access() doesn't function the same as access(), but this should work
#define R_OK 04
@@ -30,15 +25,37 @@
typedef int pid_t;
// redirect missing functions from the GDK
-#define strdup(s) _strdup(s)
-
-#define read(fd, dst, count) _read(fd, dst, count)
-#define write(fd, src, count) _write(fd, src, count)
-#define close(fd) _close(fd)
-#define dup(fd) _dup(fd)
-#define dup2(fd, f2) _dup2(fd,f2)
-#define setmode(fd, m) _setmode(fd,m)
-#define fdopen(a, b) _fdopen(a, b)
+#if defined(_CRT_INTERNAL_NONSTDC_NAMES) && !_CRT_INTERNAL_NONSTDC_NAMES
+static inline FILE *fdopen(int fd, const char *mode)
+{
+ return _fdopen(fd, mode);
+}
+static inline int close(int fd)
+{
+ return _close(fd);
+}
+static inline int read(int fd, void *dst, unsigned int dst_size)
+{
+ return _read(fd, dst, dst_size);
+}
+static inline int write(int fd, const void *src, unsigned int src_size)
+{
+ return _write(fd, src, src_size);
+}
+static inline int setmode(int fd, int mode)
+{
+ return _setmode(fd, mode);
+}
+static inline int dup(int fd)
+{
+ return _dup(fd);
+}
+static inline int dup2(int src, int dst)
+{
+ return _dup2(src, dst);
+}
+#endif // !_CRT_INTERNAL_NONSTDC_NAMES
+
#endif // WINSDK_UNISTD_H__
=====================================
include/vlc_fixups.h
=====================================
@@ -37,11 +37,21 @@
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS 1
#endif
+#if defined(_GAMING_XBOX_SCARLETT) || defined(_GAMING_XBOX_XBOXONE) || defined(_XBOX_ONE)
+// make sure we don't use MS POSIX aliases that won't link
+# undef _CRT_DECLARE_NONSTDC_NAMES
+# define _CRT_DECLARE_NONSTDC_NAMES 0
+#endif
+
// sys/stat.h values
#define S_IWUSR _S_IWRITE
#define S_IRUSR _S_IREAD
#define S_IFIFO _S_IFIFO
+#define S_IFMT _S_IFMT
+#define S_IFCHR _S_IFCHR
+#define S_IFREG _S_IFREG
+#define S_IFDIR _S_IFDIR
#define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
#define S_ISBLK(m) (0)
@@ -174,6 +184,11 @@ typedef struct
!defined (HAVE_WRITEV) || \
!defined (HAVE_READV)
# include <sys/types.h> /* ssize_t, pid_t */
+
+# if defined(_CRT_INTERNAL_NONSTDC_NAMES) && !_CRT_INTERNAL_NONSTDC_NAMES
+// MS POSIX aliases missing
+typedef _off_t off_t;
+# endif
#endif
#if !defined (HAVE_DIRFD) || \
@@ -741,6 +756,30 @@ int clock_nanosleep(clockid_t clock_id, int flags,
# endif
#endif
+#ifdef _WIN32
+# if defined(_CRT_INTERNAL_NONSTDC_NAMES) && !_CRT_INTERNAL_NONSTDC_NAMES
+# include <string.h>
+// the MS POSIX aliases are missing
+static inline char *strdup(const char *str)
+{
+ return _strdup(str);
+}
+
+# define O_WRONLY _O_WRONLY
+# define O_CREAT _O_CREAT
+# define O_APPEND _O_APPEND
+# define O_TRUNC _O_TRUNC
+# define O_BINARY _O_BINARY
+# define O_EXCL _O_EXCL
+# define O_RDWR _O_RDWR
+# define O_TEXT _O_TEXT
+# define O_NOINHERIT _O_NOINHERIT
+# define O_RDONLY _O_RDONLY
+
+# endif // !_CRT_INTERNAL_NONSTDC_NAMES
+#endif // _WIN32
+
+
#ifdef __cplusplus
} /* extern "C" */
#endif
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/11538a1e0fc59201bb36fa92b579064d80e39a85...e09c4f9039ea2ebb53b07f1c11aa29e531bc2a56
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/11538a1e0fc59201bb36fa92b579064d80e39a85...e09c4f9039ea2ebb53b07f1c11aa29e531bc2a56
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list