Fixes for traditional chinese file system

This commit is contained in:
Ron Pedde 2006-08-23 05:02:08 +00:00
parent 5412de4bd1
commit 9e7de7965a
6 changed files with 56 additions and 34 deletions

View File

@ -366,7 +366,7 @@ int scan_path(char *path) {
realpath(relative_path,mp3_path);
DPRINTF(E_DBG,L_SCAN,"Found %s\n",relative_path);
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 {
if(sb.st_mode & S_IFDIR) { /* dir -- recurse */
if(conf_get_int("scanning","ignore_appledouble",1) &&

View File

@ -1,10 +1,7 @@
/*
/**
* Win32 os functions that require unicode
*/
#define _UNICODE
#define UNICODE
#ifdef HAVE_CONFIG_H
# include "config.h"
#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 */
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) {
*result=NULL;
return 2;
}
} else {
if (!FindNextFile (dirp->dir_find_handle, &dirp->dir_find_data)) {
if (!FindNextFileW(dirp->dir_find_handle, &dirp->dir_find_data)) {
*result = NULL;
return 0;
}
@ -118,9 +115,42 @@ int os_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) {
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) {
WCHAR utf16_path[PATH_MAX+1];
DPRINTF(E_LOG,L_MISC,"Statting %s\n",path);
memset(utf16_path,0,sizeof(utf16_path));
util_utf8toutf16((unsigned char *)&utf16_path,PATH_MAX * 2,(char*)path,(int)strlen(path));

View File

@ -451,30 +451,6 @@ int os_getuid(void) {
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) {
union {

View File

@ -43,7 +43,7 @@ typedef struct {
char dd_buf[DIRBLKSIZ]; /* directory block */
HANDLE dir_find_handle;
char dir_pathname[PATH_MAX+1];
WIN32_FIND_DATA dir_find_data;
WIN32_FIND_DATAW dir_find_data;
} DIR;
/* win32-specific functions -- set up service, etc */

View File

@ -57,6 +57,20 @@ int util_must_exit(void) {
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
*/
@ -168,7 +182,7 @@ int util_utf16toutf8(unsigned char *utf8, int dlen, unsigned char *utf16, int le
*dst = '\x0';
return TRUE;
return new_len;
}
/**
@ -197,6 +211,7 @@ int util_utf8toutf16_len(unsigned char *utf8) {
src += (1 + trailing_bytes);
}
out_len += 1;
return out_len;
}
@ -306,7 +321,7 @@ unsigned char *util_utf16touft8_alloc(unsigned char *utf16, int len) {
*dst++ = '\x0';
*dst = '\x0';
return TRUE;
return new_len;
}
/*

View File

@ -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_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_utf16_byte_len(unsigned char *utf16);