mirror of
https://github.com/owntone/owntone-server.git
synced 2025-04-20 02:37:26 -04:00
Fixes for traditional chinese file system
This commit is contained in:
parent
5412de4bd1
commit
9e7de7965a
@ -366,7 +366,7 @@ int scan_path(char *path) {
|
|||||||
realpath(relative_path,mp3_path);
|
realpath(relative_path,mp3_path);
|
||||||
DPRINTF(E_DBG,L_SCAN,"Found %s\n",relative_path);
|
DPRINTF(E_DBG,L_SCAN,"Found %s\n",relative_path);
|
||||||
if(os_stat(mp3_path,&sb)) {
|
if(os_stat(mp3_path,&sb)) {
|
||||||
DPRINTF(E_WARN,L_SCAN,"Error statting: %s\n",strerror(errno));
|
DPRINTF(E_WARN,L_SCAN,"Error statting %s: %s\n",mp3_path,strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
if(sb.st_mode & S_IFDIR) { /* dir -- recurse */
|
if(sb.st_mode & S_IFDIR) { /* dir -- recurse */
|
||||||
if(conf_get_int("scanning","ignore_appledouble",1) &&
|
if(conf_get_int("scanning","ignore_appledouble",1) &&
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
/*
|
/**
|
||||||
* Win32 os functions that require unicode
|
* Win32 os functions that require unicode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _UNICODE
|
|
||||||
#define UNICODE
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
#endif
|
#endif
|
||||||
@ -69,14 +66,14 @@ int os_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) {
|
|||||||
/* filename is utf-8... let's convert to unicode */
|
/* filename is utf-8... let's convert to unicode */
|
||||||
util_utf8toutf16((unsigned char *)&utf16,sizeof(utf16),filename,(int)strlen(filename));
|
util_utf8toutf16((unsigned char *)&utf16,sizeof(utf16),filename,(int)strlen(filename));
|
||||||
|
|
||||||
dirp->dir_find_handle = FindFirstFile(utf16, &dirp->dir_find_data);
|
dirp->dir_find_handle = FindFirstFileW(utf16, &dirp->dir_find_data);
|
||||||
|
|
||||||
if (dirp->dir_find_handle == INVALID_HANDLE_VALUE) {
|
if (dirp->dir_find_handle == INVALID_HANDLE_VALUE) {
|
||||||
*result=NULL;
|
*result=NULL;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!FindNextFile (dirp->dir_find_handle, &dirp->dir_find_data)) {
|
if (!FindNextFileW(dirp->dir_find_handle, &dirp->dir_find_data)) {
|
||||||
*result = NULL;
|
*result = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -118,9 +115,42 @@ int os_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this is now pretty close to a true realpath implementation
|
||||||
|
*/
|
||||||
|
char *os_realpath(const char *pathname, char *resolved_path) {
|
||||||
|
char *ptr;
|
||||||
|
WCHAR utf16_rel_path[PATH_MAX+1];
|
||||||
|
WCHAR utf16_path[PATH_MAX+1];
|
||||||
|
int utf16_len;
|
||||||
|
|
||||||
|
/* need to take the utf-8 and convert to utf-16, then _fullpath, then back */
|
||||||
|
util_utf8toutf16((unsigned char *)&utf16_rel_path,PATH_MAX * sizeof(WCHAR),(char*)pathname,(int)strlen(pathname));
|
||||||
|
if(!_wfullpath(utf16_path,utf16_rel_path,PATH_MAX)) {
|
||||||
|
DPRINTF(E_FATAL,L_MISC,"Could not realpath %s\n",pathname);
|
||||||
|
}
|
||||||
|
util_utf16toutf8((unsigned char *)resolved_path,PATH_MAX,(unsigned char *)&utf16_path,
|
||||||
|
util_utf16_byte_len((unsigned char *)utf16_path));
|
||||||
|
|
||||||
|
ptr = resolved_path;
|
||||||
|
while(*ptr) {
|
||||||
|
// *ptr = tolower(*ptr);
|
||||||
|
if(*ptr == '/')
|
||||||
|
*ptr = '\\';
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(resolved_path[strlen(resolved_path)-1] == '\\') {
|
||||||
|
resolved_path[strlen(resolved_path)-1] = '\x0';
|
||||||
|
}
|
||||||
|
|
||||||
|
return &resolved_path[0];
|
||||||
|
}
|
||||||
|
|
||||||
int os_stat(const char *path, struct _stat *sb) {
|
int os_stat(const char *path, struct _stat *sb) {
|
||||||
WCHAR utf16_path[PATH_MAX+1];
|
WCHAR utf16_path[PATH_MAX+1];
|
||||||
|
|
||||||
|
DPRINTF(E_LOG,L_MISC,"Statting %s\n",path);
|
||||||
memset(utf16_path,0,sizeof(utf16_path));
|
memset(utf16_path,0,sizeof(utf16_path));
|
||||||
util_utf8toutf16((unsigned char *)&utf16_path,PATH_MAX * 2,(char*)path,(int)strlen(path));
|
util_utf8toutf16((unsigned char *)&utf16_path,PATH_MAX * 2,(char*)path,(int)strlen(path));
|
||||||
|
|
||||||
|
@ -451,30 +451,6 @@ int os_getuid(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* this is now pretty close to a true realpath implementation
|
|
||||||
*/
|
|
||||||
char *os_realpath(const char *pathname, char *resolved_path) {
|
|
||||||
char *ptr;
|
|
||||||
|
|
||||||
if(!_fullpath(resolved_path,pathname,PATH_MAX)) {
|
|
||||||
DPRINTF(E_FATAL,L_MISC,"Could not realpath %s\n",pathname);
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr = resolved_path;
|
|
||||||
while(*ptr) {
|
|
||||||
// *ptr = tolower(*ptr);
|
|
||||||
if(*ptr == '/')
|
|
||||||
*ptr = '\\';
|
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(strlen(resolved_path) && (resolved_path[strlen(resolved_path)-1] == '\\'))
|
|
||||||
resolved_path[strlen(resolved_path)-1] = '\0';
|
|
||||||
|
|
||||||
return &resolved_path[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int os_gettimeofday (struct timeval *tv, struct timezone* tz) {
|
int os_gettimeofday (struct timeval *tv, struct timezone* tz) {
|
||||||
union {
|
union {
|
||||||
|
@ -43,7 +43,7 @@ typedef struct {
|
|||||||
char dd_buf[DIRBLKSIZ]; /* directory block */
|
char dd_buf[DIRBLKSIZ]; /* directory block */
|
||||||
HANDLE dir_find_handle;
|
HANDLE dir_find_handle;
|
||||||
char dir_pathname[PATH_MAX+1];
|
char dir_pathname[PATH_MAX+1];
|
||||||
WIN32_FIND_DATA dir_find_data;
|
WIN32_FIND_DATAW dir_find_data;
|
||||||
} DIR;
|
} DIR;
|
||||||
|
|
||||||
/* win32-specific functions -- set up service, etc */
|
/* win32-specific functions -- set up service, etc */
|
||||||
|
19
src/util.c
19
src/util.c
@ -57,6 +57,20 @@ int util_must_exit(void) {
|
|||||||
return config.stop;
|
return config.stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int util_utf16_byte_len(unsigned char *utf16) {
|
||||||
|
unsigned char *src = utf16;
|
||||||
|
int len = 0;
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
if((src[0] == 0) && (src[1]==0))
|
||||||
|
return len;
|
||||||
|
len += 2;
|
||||||
|
src += 2;
|
||||||
|
}
|
||||||
|
return len; /* ?? */
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* calculate how long a utf16le string will be once converted
|
* calculate how long a utf16le string will be once converted
|
||||||
*/
|
*/
|
||||||
@ -168,7 +182,7 @@ int util_utf16toutf8(unsigned char *utf8, int dlen, unsigned char *utf16, int le
|
|||||||
|
|
||||||
*dst = '\x0';
|
*dst = '\x0';
|
||||||
|
|
||||||
return TRUE;
|
return new_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -197,6 +211,7 @@ int util_utf8toutf16_len(unsigned char *utf8) {
|
|||||||
src += (1 + trailing_bytes);
|
src += (1 + trailing_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out_len += 1;
|
||||||
return out_len;
|
return out_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,7 +321,7 @@ unsigned char *util_utf16touft8_alloc(unsigned char *utf16, int len) {
|
|||||||
|
|
||||||
*dst++ = '\x0';
|
*dst++ = '\x0';
|
||||||
*dst = '\x0';
|
*dst = '\x0';
|
||||||
return TRUE;
|
return new_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -32,6 +32,7 @@ extern int util_utf8toutf16_len(unsigned char *utf8);
|
|||||||
extern int util_utf16toutf8_len(unsigned char *utf16, int len);
|
extern int util_utf16toutf8_len(unsigned char *utf16, int len);
|
||||||
extern int util_utf8toutf16(unsigned char *utf16, int dlen, unsigned char *utf8, int len);
|
extern int util_utf8toutf16(unsigned char *utf16, int dlen, unsigned char *utf8, int len);
|
||||||
extern int util_utf16toutf8(unsigned char *utf8, int dlen, unsigned char *utf16, int len);
|
extern int util_utf16toutf8(unsigned char *utf8, int dlen, unsigned char *utf16, int len);
|
||||||
|
extern int util_utf16_byte_len(unsigned char *utf16);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user