mirror of
https://github.com/fltk/fltk.git
synced 2026-06-01 23:06:54 +08:00
Fix unicode support in scandir_win32.c by using GetFileAttributesW (#455)
* Fix unicode support in scandir_win32.c by using GetFileAttributesW * Remove the useless comments in scandir_win32.c
This commit is contained in:
+7
-9
@@ -88,29 +88,27 @@ int fl_scandir(const char *dirname, struct dirent ***namelist,
|
|||||||
}
|
}
|
||||||
strcpy(findIn, dirname);
|
strcpy(findIn, dirname);
|
||||||
|
|
||||||
/* #if defined(__GNUC__) */
|
|
||||||
/* #warning FIXME This probably needs to be MORE UTF8 aware now */
|
|
||||||
/* #endif */
|
|
||||||
for (d = findIn; *d; d++) if (*d=='/') *d='\\';
|
for (d = findIn; *d; d++) if (*d=='/') *d='\\';
|
||||||
if (len==0) { strcpy(findIn, ".\\*"); }
|
if (len==0) { strcpy(findIn, ".\\*"); }
|
||||||
if ((len==2)&&findIn[1]==':'&&isalpha(findIn[0])) { *d++ = '\\'; *d = 0; }
|
if ((len==2)&&findIn[1]==':'&&isalpha(findIn[0])) { *d++ = '\\'; *d = 0; }
|
||||||
if ((len==1)&& (d[-1]=='.')) { strcpy(findIn, ".\\*"); is_dir = 1; }
|
if ((len==1)&& (d[-1]=='.')) { strcpy(findIn, ".\\*"); is_dir = 1; }
|
||||||
if ((len>0) && (d[-1]=='\\')) { *d++ = '*'; *d = 0; is_dir = 1; }
|
if ((len>0) && (d[-1]=='\\')) { *d++ = '*'; *d = 0; is_dir = 1; }
|
||||||
if ((len>1) && (d[-1]=='.') && (d[-2]=='\\')) { d[-1] = '*'; is_dir = 1; }
|
if ((len>1) && (d[-1]=='.') && (d[-2]=='\\')) { d[-1] = '*'; is_dir = 1; }
|
||||||
if (!is_dir) { /* this file may still be a directory that we need to list */
|
|
||||||
DWORD attr = GetFileAttributes(findIn);
|
|
||||||
if (attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY) )
|
|
||||||
strcpy(d, "\\*");
|
|
||||||
}
|
|
||||||
{ /* Create a block to limit the scope while we find the initial "wide" filename */
|
{ /* Create a block to limit the scope while we find the initial "wide" filename */
|
||||||
/* unsigned short * wbuf = (unsigned short*)malloc(sizeof(short) *(len + 10)); */
|
/* unsigned short * wbuf = (unsigned short*)malloc(sizeof(short) *(len + 10)); */
|
||||||
/* wbuf[fl_utf2unicode(findIn, strlen(findIn), wbuf)] = 0; */
|
/* wbuf[fl_utf2unicode(findIn, strlen(findIn), wbuf)] = 0; */
|
||||||
unsigned short *wbuf = NULL;
|
unsigned short *wbuf = NULL;
|
||||||
unsigned wlen = fl_utf8toUtf16(findIn, (unsigned) strlen(findIn), NULL, 0); /* Pass NULL to query length */
|
unsigned wlen = fl_utf8toUtf16(findIn, (unsigned) strlen(findIn), NULL, 0); /* Pass NULL to query length */
|
||||||
wlen++; /* add a little extra for termination etc. */
|
wlen++; /* add a little extra for termination etc. */
|
||||||
wbuf = (unsigned short*)malloc(sizeof(unsigned short)*wlen);
|
wbuf = (unsigned short*)malloc(sizeof(unsigned short)*(wlen+2));
|
||||||
wlen = fl_utf8toUtf16(findIn, (unsigned) strlen(findIn), wbuf, wlen); /* actually convert the filename */
|
wlen = fl_utf8toUtf16(findIn, (unsigned) strlen(findIn), wbuf, wlen); /* actually convert the filename */
|
||||||
wbuf[wlen] = 0; /* NULL terminate the resultant string */
|
wbuf[wlen] = 0; /* NULL terminate the resultant string */
|
||||||
|
if (!is_dir) { /* this file may still be a directory that we need to list */
|
||||||
|
DWORD attr = GetFileAttributesW(wbuf);
|
||||||
|
if (attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY) ) {
|
||||||
|
wbuf[wlen] = '\\'; wbuf[wlen+1] = '*'; wbuf[wlen+2] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
h = FindFirstFileW(wbuf, &findw); /* get a handle to the first filename in the search */
|
h = FindFirstFileW(wbuf, &findw); /* get a handle to the first filename in the search */
|
||||||
free(wbuf); /* release the "wide" buffer before the pointer goes out of scope */
|
free(wbuf); /* release the "wide" buffer before the pointer goes out of scope */
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user