libobs/util: Add os_stat function (win32 compatibility)

Windows needs filenames to be processed as wide, while libobs operates
on UTF-8, so a windows-specific function is needed here.
master
jp9000 2016-04-03 18:02:45 -07:00
parent e460dfeb83
commit 81ac57cd6c
2 changed files with 37 additions and 0 deletions

View File

@ -85,6 +85,37 @@ int64_t os_fgetsize(FILE *file)
return size; return size;
} }
#ifdef _WIN32
int os_stat(const char *file, struct stat *st)
{
if (file) {
wchar_t w_file[512];
int size = os_utf8_to_wcs(file, 0, w_file, sizeof(w_file));
if (size > 0) {
struct _stat st_w32;
int ret = _wstat(w_file, &st_w32);
if (ret == 0) {
st->st_dev = st_w32.st_dev;
st->st_ino = st_w32.st_ino;
st->st_mode = st_w32.st_mode;
st->st_nlink = st_w32.st_nlink;
st->st_uid = st_w32.st_uid;
st->st_gid = st_w32.st_gid;
st->st_rdev = st_w32.st_rdev;
st->st_size = st_w32.st_size;
st->st_atime = st_w32.st_atime;
st->st_mtime = st_w32.st_mtime;
st->st_ctime = st_w32.st_ctime;
}
return ret;
}
}
return -1;
}
#endif
int os_fseeki64(FILE *file, int64_t offset, int origin) int os_fseeki64(FILE *file, int64_t offset, int origin)
{ {
#ifdef _MSC_VER #ifdef _MSC_VER

View File

@ -34,6 +34,12 @@ EXPORT FILE *os_wfopen(const wchar_t *path, const char *mode);
EXPORT FILE *os_fopen(const char *path, const char *mode); EXPORT FILE *os_fopen(const char *path, const char *mode);
EXPORT int64_t os_fgetsize(FILE *file); EXPORT int64_t os_fgetsize(FILE *file);
#ifdef _WIN32
EXPORT int os_stat(const char *file, struct stat *st);
#else
#define os_stat stat
#endif
EXPORT int os_fseeki64(FILE *file, int64_t offset, int origin); EXPORT int os_fseeki64(FILE *file, int64_t offset, int origin);
EXPORT int64_t os_ftelli64(FILE *file); EXPORT int64_t os_ftelli64(FILE *file);