For_each_directory_entry: remove MAX_PATH_CHARACTER
This commit is contained in:
parent
eb175c7efa
commit
81bf106865
82
src/io.c
82
src/io.c
@ -618,12 +618,16 @@ void For_each_directory_entry(const char * directory_name, void * pdata, T_File_
|
|||||||
{
|
{
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
WIN32_FIND_DATAW fd;
|
WIN32_FIND_DATAW fd;
|
||||||
word search_string[MAX_PATH_CHARACTERS];
|
size_t len;
|
||||||
|
word * search_string;
|
||||||
HANDLE h;
|
HANDLE h;
|
||||||
|
|
||||||
Unicode_char_strlcpy(search_string, directory_name, MAX_PATH_CHARACTERS);
|
len = strlen(directory_name) + 3;
|
||||||
Unicode_char_strlcat(search_string, "\\*", MAX_PATH_CHARACTERS);
|
search_string = (word *)malloc(sizeof(word) * len);
|
||||||
|
Unicode_char_strlcpy(search_string, directory_name, len);
|
||||||
|
Unicode_char_strlcat(search_string, "\\*", len);
|
||||||
h = FindFirstFileW((WCHAR *)search_string, &fd);
|
h = FindFirstFileW((WCHAR *)search_string, &fd);
|
||||||
|
free(search_string);
|
||||||
if (h != INVALID_HANDLE_VALUE)
|
if (h != INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
@ -653,54 +657,56 @@ void For_each_directory_entry(const char * directory_name, void * pdata, T_File_
|
|||||||
#else
|
#else
|
||||||
DIR* current_directory; // current directory
|
DIR* current_directory; // current directory
|
||||||
struct dirent* entry; // directory entry struct
|
struct dirent* entry; // directory entry struct
|
||||||
char full_filename[MAX_PATH_CHARACTERS];
|
|
||||||
word * unicode_filename = NULL;
|
|
||||||
word unicode_buffer[MAX_PATH_CHARACTERS];
|
|
||||||
int filename_position;
|
|
||||||
|
|
||||||
current_directory=opendir(directory_name);
|
current_directory = opendir(directory_name);
|
||||||
if(current_directory == NULL) return; // Invalid directory
|
if(current_directory == NULL)
|
||||||
|
return; // Invalid directory
|
||||||
|
|
||||||
filename_position = strlen(directory_name);
|
while ((entry = readdir(current_directory)) != NULL)
|
||||||
memcpy(full_filename, directory_name, filename_position+1);
|
|
||||||
#if defined(__AROS__)
|
|
||||||
if (filename_position==0 || (strcmp(full_filename+filename_position-1,PATH_SEPARATOR) && strcmp(full_filename+filename_position-1,":")))
|
|
||||||
#else
|
|
||||||
if (filename_position==0 || strcmp(full_filename+filename_position-1,PATH_SEPARATOR))
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
strcat(full_filename, PATH_SEPARATOR);
|
word * unicode_filename = NULL;
|
||||||
filename_position = strlen(full_filename);
|
char * full_filename;
|
||||||
}
|
struct stat st;
|
||||||
while ((entry=readdir(current_directory)))
|
|
||||||
{
|
|
||||||
struct stat Infos_enreg;
|
|
||||||
#ifdef ENABLE_FILENAMES_ICONV
|
#ifdef ENABLE_FILENAMES_ICONV
|
||||||
char * input = entry->d_name;
|
|
||||||
size_t inbytesleft = strlen(entry->d_name);
|
|
||||||
char * output = (char *)unicode_buffer;
|
|
||||||
size_t outbytesleft = sizeof(unicode_buffer) - 2;
|
|
||||||
unicode_filename = NULL;
|
|
||||||
if (cd_utf16 != (iconv_t)-1)
|
if (cd_utf16 != (iconv_t)-1)
|
||||||
{
|
{
|
||||||
size_t r = iconv(cd_utf16, &input, &inbytesleft, &output, &outbytesleft);
|
char * input = entry->d_name;
|
||||||
|
size_t inbytesleft = strlen(entry->d_name);
|
||||||
|
char * output;
|
||||||
|
size_t outbytesleft;
|
||||||
|
size_t r;
|
||||||
|
|
||||||
|
unicode_filename = malloc(sizeof(word) * (inbytesleft + 1));
|
||||||
|
output = (char *)unicode_filename;
|
||||||
|
outbytesleft = sizeof(word) * inbytesleft;
|
||||||
|
r = iconv(cd_utf16, &input, &inbytesleft, &output, &outbytesleft);
|
||||||
if (r != (size_t)-1)
|
if (r != (size_t)-1)
|
||||||
{
|
{
|
||||||
output[0] = '\0';
|
output[0] = '\0';
|
||||||
output[1] = '\0';
|
output[1] = '\0';
|
||||||
unicode_filename = unicode_buffer;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
free(unicode_filename);
|
||||||
|
unicode_filename = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
strcpy(&full_filename[filename_position], entry->d_name);
|
full_filename = Filepath_append_to_dir(directory_name, entry->d_name);
|
||||||
stat(full_filename,&Infos_enreg);
|
if (stat(full_filename, &st) < 0)
|
||||||
Callback(
|
GFX2_Log(GFX2_WARNING, "stat(\"%s\") failed\n", full_filename);
|
||||||
pdata,
|
else
|
||||||
entry->d_name,
|
{
|
||||||
unicode_filename,
|
Callback(
|
||||||
S_ISREG(Infos_enreg.st_mode),
|
pdata,
|
||||||
S_ISDIR(Infos_enreg.st_mode),
|
entry->d_name,
|
||||||
File_is_hidden(entry->d_name, full_filename));
|
unicode_filename,
|
||||||
|
S_ISREG(st.st_mode),
|
||||||
|
S_ISDIR(st.st_mode),
|
||||||
|
File_is_hidden(entry->d_name, full_filename));
|
||||||
|
}
|
||||||
|
free(full_filename);
|
||||||
|
free(unicode_filename);
|
||||||
}
|
}
|
||||||
closedir(current_directory);
|
closedir(current_directory);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user