Skip to content

Commit 2fce712

Browse files
Update libretro-common
1 parent 387527f commit 2fce712

19 files changed

Lines changed: 1816 additions & 790 deletions

libretro/libretro-common/compat/compat_posix_string.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ char *retro_strdup__(const char *orig)
6060
char *ret = (char*)malloc(_len);
6161
if (!ret)
6262
return NULL;
63-
strlcpy(ret, orig, _len);
63+
memcpy(ret, orig, _len);
6464
return ret;
6565
}
6666

@@ -99,5 +99,4 @@ char *retro_strtok_r__(char *str, const char *delim, char **saveptr)
9999

100100
return first;
101101
}
102-
103102
#endif

libretro/libretro-common/compat/compat_strl.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,17 @@
2727

2828
/* Implementation of strlcpy()/strlcat() based on OpenBSD. */
2929

30-
#ifndef __MACH__
31-
size_t strlcpy(char *s, const char *source, size_t len)
30+
#if !(defined(__MACH__) && defined(__APPLE__))
31+
size_t strlcpy(char *s, const char *in, size_t len)
3232
{
33-
size_t _len = len;
34-
size_t __len = 0;
35-
if (_len)
36-
while (--_len && (*s++ = *source++)) __len++;
37-
if (!_len)
38-
{
39-
if (len) *s = '\0';
40-
while (*source++) __len++;
41-
}
42-
return __len;
33+
size_t _len = strlen(in);
34+
if (len)
35+
{
36+
size_t __len = _len < len - 1 ? _len : len - 1;
37+
memcpy(s, in, __len);
38+
s[__len] = '\0';
39+
}
40+
return _len;
4341
}
4442

4543
size_t strlcat(char *s, const char *source, size_t len)

libretro/libretro-common/compat/fopen_utf8.c

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,18 @@
2323
#include <compat/fopen_utf8.h>
2424
#include <encodings/utf.h>
2525
#include <stdio.h>
26+
#include <string.h>
2627
#include <stdlib.h>
28+
#include <boolean.h>
29+
#if defined(__WINRT__)
30+
#include <stdint.h>
31+
#include <windows.h>
32+
#include <fileapifromapp.h>
33+
#include <io.h>
34+
#include <fcntl.h>
35+
#endif
2736

28-
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500 || defined(_XBOX)
37+
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500 || (defined(_XBOX) && !defined(__WINRT__))
2938
#ifndef LEGACY_WIN32
3039
#define LEGACY_WIN32
3140
#endif
@@ -49,12 +58,75 @@ void *fopen_utf8(const char * filename, const char * mode)
4958
if (filename_w)
5059
{
5160
FILE *ret = NULL;
61+
#if defined(__WINRT__)
62+
HANDLE file_handle = INVALID_HANDLE_VALUE;
63+
DWORD desired_access = 0;
64+
DWORD creation_disposition = OPEN_EXISTING;
65+
int open_flags = O_BINARY;
66+
int fd = -1;
67+
bool append = mode && strchr(mode, 'a');
68+
bool write = mode && strchr(mode, 'w');
69+
bool plus = mode && strchr(mode, '+');
70+
wchar_t *path = filename_w;
71+
72+
while (*path)
73+
{
74+
if (*path == L'/')
75+
*path = L'\\';
76+
path++;
77+
}
78+
79+
if (mode && strchr(mode, 'r'))
80+
desired_access |= GENERIC_READ;
81+
if (write || append || plus)
82+
desired_access |= GENERIC_WRITE;
83+
if (plus)
84+
desired_access |= GENERIC_READ;
85+
86+
if (append)
87+
creation_disposition = OPEN_ALWAYS;
88+
else if (write)
89+
creation_disposition = CREATE_ALWAYS;
90+
91+
if (plus)
92+
open_flags |= O_RDWR;
93+
else if (append || write)
94+
open_flags |= O_WRONLY;
95+
else
96+
open_flags |= O_RDONLY;
97+
98+
if (append)
99+
open_flags |= O_APPEND;
100+
if (write || append)
101+
open_flags |= O_CREAT;
102+
if (write)
103+
open_flags |= O_TRUNC;
104+
105+
file_handle = CreateFile2FromAppW(filename_w, desired_access,
106+
FILE_SHARE_READ | FILE_SHARE_WRITE,
107+
creation_disposition, NULL);
108+
if (file_handle != INVALID_HANDLE_VALUE)
109+
{
110+
fd = _open_osfhandle((intptr_t)file_handle, open_flags);
111+
if (fd != -1)
112+
ret = _fdopen(fd, mode);
113+
114+
if (!ret)
115+
{
116+
if (fd != -1)
117+
_close(fd);
118+
else
119+
CloseHandle(file_handle);
120+
}
121+
}
122+
#else
52123
wchar_t *mode_w = utf8_to_utf16_string_alloc(mode);
53124
if (mode_w)
54125
{
55126
ret = _wfopen(filename_w, mode_w);
56127
free(mode_w);
57128
}
129+
#endif
58130
free(filename_w);
59131
return ret;
60132
}

0 commit comments

Comments
 (0)