34
34
#include <LCUI/LCUI.h>
35
35
#include <LCUI/font/charset.h>
36
36
37
- int LCUI_OpenDirA (const char * filepath , LCUI_Dir * dir )
37
+ int LCUI_OpenDirA (const char * path , LCUI_Dir * dir )
38
38
{
39
39
#if defined(LCUI_BUILD_IN_WIN32 ) || (_WIN32 )
40
- int len ;
40
+ size_t len ;
41
41
char * newpath ;
42
+ char name [] = "\\*" ;
42
43
43
- len = strlen (filepath ) + 5 ;
44
- newpath = malloc (len * sizeof (char ));
44
+ len = strlen (path ) + 1 ;
45
+ newpath = malloc (len * sizeof (char ) + sizeof ( name ) );
45
46
if (newpath == NULL ) {
46
47
return - ENOMEM ;
47
48
}
48
- /* 需要加上通配符 */
49
- sprintf_s (newpath , len , "%s\\*" , filepath );
49
+ strcpy ( newpath , path );
50
+ strcpy (newpath + len - 1 , name );
50
51
dir -> handle = FindFirstFileA (newpath , & dir -> entry .dataA );
51
52
free (newpath );
52
53
if (dir -> handle == INVALID_HANDLE_VALUE ) {
@@ -68,15 +69,18 @@ int LCUI_OpenDirA(const char *filepath, LCUI_Dir *dir)
68
69
int LCUI_OpenDirW (const wchar_t * path , LCUI_Dir * dir )
69
70
{
70
71
#if defined(LCUI_BUILD_IN_WIN32 ) || (_WIN32 )
71
- int len ;
72
+ size_t len ;
72
73
wchar_t * newpath ;
74
+ wchar_t name [] = L"\\*" ;
75
+
73
76
74
- len = wcslen (path ) + 5 ;
75
- newpath = malloc (len * sizeof (wchar_t ));
77
+ len = wcslen (path ) + 1 ;
78
+ newpath = malloc (len * sizeof (wchar_t ) + sizeof ( name ) );
76
79
if (!newpath ) {
77
80
return - ENOMEM ;
78
81
}
79
- swprintf (newpath , len , L"%s\\*" , path );
82
+ wcscpy (newpath , path );
83
+ wcscpy (newpath + len - 1 , name );
80
84
dir -> handle = FindFirstFileW (newpath , & dir -> entry .dataW );
81
85
free (newpath );
82
86
if (dir -> handle == INVALID_HANDLE_VALUE ) {
0 commit comments