aboutsummaryrefslogtreecommitdiffhomepage
path: root/osdep
diff options
context:
space:
mode:
authorGravatar wm4 <wm4@nowhere>2017-04-11 12:16:07 +0200
committerGravatar wm4 <wm4@nowhere>2017-04-11 12:19:41 +0200
commite0d93178b9f6006a9386878f924408dbff32dd29 (patch)
tree206d97474bad182f60bdf41e04fc7e704031f618 /osdep
parente2464b832bc90af4da552352466d73a465b7f855 (diff)
win32: add UTF-8 getcwd() wrapper
Diffstat (limited to 'osdep')
-rw-r--r--osdep/io.c18
-rw-r--r--osdep/io.h2
2 files changed, 20 insertions, 0 deletions
diff --git a/osdep/io.c b/osdep/io.c
index 26889189cf..1e1bf19ccf 100644
--- a/osdep/io.c
+++ b/osdep/io.c
@@ -335,6 +335,24 @@ int mp_mkdir(const char *path, int mode)
return res;
}
+char *mp_win32_getcwd(char *buf, size_t size)
+{
+ wchar_t *wres = _wgetcwd(NULL, 0);
+ if (!wres)
+ return NULL;
+ char *t = mp_to_utf8(NULL, wres);
+ free(wres);
+ size_t st = strlen(t);
+ if (st >= size) {
+ talloc_free(t);
+ errno = ERANGE;
+ return NULL;
+ }
+ memcpy(buf, t, st + 1);
+ talloc_free(t);
+ return buf;
+}
+
FILE *mp_tmpfile(void)
{
// Reserve a file name in the format %TMP%\mpvXXXX.TMP
diff --git a/osdep/io.h b/osdep/io.h
index 333ed4f808..01c7c8bfdf 100644
--- a/osdep/io.h
+++ b/osdep/io.h
@@ -75,6 +75,7 @@ DIR *mp_opendir(const char *path);
struct dirent *mp_readdir(DIR *dir);
int mp_closedir(DIR *dir);
int mp_mkdir(const char *path, int mode);
+char *mp_win32_getcwd(char *buf, size_t size);
FILE *mp_tmpfile(void);
char *mp_getenv(const char *name);
off_t mp_lseek(int fd, off_t offset, int whence);
@@ -121,6 +122,7 @@ void mp_globfree(mp_glob_t *pglob);
#define readdir(...) mp_readdir(__VA_ARGS__)
#define closedir(...) mp_closedir(__VA_ARGS__)
#define mkdir(...) mp_mkdir(__VA_ARGS__)
+#define getcwd(...) mp_win32_getcwd(__VA_ARGS__)
#define tmpfile(...) mp_tmpfile(__VA_ARGS__)
#define getenv(...) mp_getenv(__VA_ARGS__)