getcwd() => Get_current_directory()

This commit is contained in:
Thomas Bernard 2018-02-12 11:24:23 +01:00
parent 2ef2e04a7e
commit 62944c724e
4 changed files with 26 additions and 40 deletions

View File

@ -2010,7 +2010,7 @@ int L_Run(lua_State* L)
return luaL_error(L, "run: too many nested calls (100)"); return luaL_error(L, "run: too many nested calls (100)");
// store the current directory (on the stack) // store the current directory (on the stack)
getcwd(saved_directory,MAX_PATH_CHARACTERS); Get_current_directory(saved_directory,MAX_PATH_CHARACTERS);
#if defined (__AROS__) #if defined (__AROS__)
// Convert path written on Linux/Windows norms to AROS norms : // Convert path written on Linux/Windows norms to AROS norms :

View File

@ -438,13 +438,8 @@ void Read_list_of_files(T_Fileselector *list, byte selected_format)
const char * current_path = NULL; const char * current_path = NULL;
char curdir[MAX_PATH_CHARACTERS]; char curdir[MAX_PATH_CHARACTERS];
#if defined (__MINT__) #if defined (__MINT__)
char path[1024]={0};
char path2[1024]={0};
char currentDrive=0;
T_Fileselector_item *item=0; T_Fileselector_item *item=0;
bool bFound=false; bool bFound=false;
path[0]='\0';
path2[0]='\0';
#endif #endif
callback_data.list = list; callback_data.list = list;
@ -456,19 +451,7 @@ void Read_list_of_files(T_Fileselector *list, byte selected_format)
// Après effacement, il ne reste ni fichier ni répertoire dans la liste // Après effacement, il ne reste ni fichier ni répertoire dans la liste
// On lit tous les répertoires: // On lit tous les répertoires:
current_path = Get_current_directory(curdir, MAX_PATH_CHARACTERS);
#if defined (__MINT__)
currentDrive='A';
currentDrive=currentDrive+Dgetdrv();
Dgetpath(path,0);
sprintf(path2,"%c:\%s",currentDrive,path);
strcat(path2,PATH_SEPARATOR);
current_path=path2;
#else
current_path=getcwd(curdir,MAX_PATH_CHARACTERS);
#endif
For_each_directory_entry(current_path, &callback_data, Read_dir_callback); For_each_directory_entry(current_path, &callback_data, Read_dir_callback);
@ -1535,20 +1518,8 @@ byte Button_Load_or_Save(T_Selector_settings *settings, byte load, T_IO_Context
Display_bookmark(bookmark_dropdown[temp],temp); Display_bookmark(bookmark_dropdown[temp],temp);
} }
#if defined(__MINT__) chdir(context->File_directory);
{ Get_current_directory(Selector->Directory,MAX_PATH_CHARACTERS);
static char path[1024]={0};
chdir(context->File_directory);
Dgetpath(path,0);
strcat(path,PATH_SEPARATOR);
strcpy(Selector->Directory,path);
}
#else
{
chdir(context->File_directory);
getcwd(Selector->Directory,MAX_PATH_CHARACTERS);
}
#endif
// Affichage des premiers fichiers visibles: // Affichage des premiers fichiers visibles:
Reload_list_of_files(Selector->Format_filter,file_scroller); Reload_list_of_files(Selector->Format_filter,file_scroller);
@ -2092,13 +2063,7 @@ byte Button_Load_or_Save(T_Selector_settings *settings, byte load, T_IO_Context
Extract_filename(previous_directory, Selector->Directory); Extract_filename(previous_directory, Selector->Directory);
} }
#if defined (__MINT__) Get_current_directory(Selector->Directory,MAX_PATH_CHARACTERS);
currentDrive=currentDrive+Dgetdrv();
Dgetpath(path,0);
sprintf(Selector->Directory,"%c:\%s",currentDrive,path);
#else
getcwd(Selector->Directory,MAX_PATH_CHARACTERS);
#endif
// read the new directory // read the new directory
Read_list_of_files(&Filelist, Selector->Format_filter); Read_list_of_files(&Filelist, Selector->Format_filter);
Sort_list_of_files(&Filelist); Sort_list_of_files(&Filelist);

View File

@ -2,6 +2,7 @@
*/ */
/* Grafx2 - The Ultimate 256-color bitmap paint program /* Grafx2 - The Ultimate 256-color bitmap paint program
Copyright 2018 Thomas Bernard
Copyright 2011 Pawel Góralski Copyright 2011 Pawel Góralski
Copyright 2008 Yves Rizoud Copyright 2008 Yves Rizoud
Copyright 2007 Adrien Destugues Copyright 2007 Adrien Destugues
@ -524,3 +525,18 @@ void Release_lock_file(const char *file_directory)
strcat(lock_filename,"gfx2.lck"); strcat(lock_filename,"gfx2.lck");
remove(lock_filename); remove(lock_filename);
} }
const char * Get_current_directory(char * buf, size_t size)
{
#if defined(__MINT__)
buf[0] = 'A'+Dgetdrv();
buf[1] = ':';
buf[2] = '\\';
Dgetpath(buf+3,0);
strcat(buf,PATH_SEPARATOR);
return buf;
#else
return getcwd(buf, size);
#endif
}

View File

@ -2,6 +2,7 @@
*/ */
/* Grafx2 - The Ultimate 256-color bitmap paint program /* Grafx2 - The Ultimate 256-color bitmap paint program
Copyright 2018 Thomas Bernard
Copyright 2011 Pawel Góralski Copyright 2011 Pawel Góralski
Copyright 2008 Yves Rizoud Copyright 2008 Yves Rizoud
Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud) Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud)
@ -30,6 +31,7 @@
/// - fstat() /// - fstat()
/// - opendir() /// - opendir()
/// - readdir() /// - readdir()
/// - getcwd()
/// - Also, don't assume "/" or "\\", use PATH_SEPARATOR /// - Also, don't assume "/" or "\\", use PATH_SEPARATOR
/// If you don't, you break another platform. /// If you don't, you break another platform.
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -125,3 +127,6 @@ byte Create_lock_file(const char *file_directory);
/// Release a lock file created by ::Create_lock_file /// Release a lock file created by ::Create_lock_file
void Release_lock_file(const char *file_directory); void Release_lock_file(const char *file_directory);
///
/// Return the current directory, equivalent to getcwd()
const char * Get_current_directory(char * buf, size_t size);