chdir() => Change_directory()
improve portability
This commit is contained in:
parent
62944c724e
commit
a1f0f36062
@ -57,7 +57,6 @@ char * Bound_script[10];
|
||||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
#include <float.h> // for DBL_MAX
|
||||
#include <unistd.h> // chdir()
|
||||
#include <limits.h> //for INT_MIN
|
||||
#include <string.h> // strncpy()
|
||||
|
||||
@ -2059,7 +2058,7 @@ int L_Run(lua_State* L)
|
||||
{
|
||||
if (!Directory_exists(path_element))
|
||||
return luaL_error(L, "run: directory of script doesn't exist");
|
||||
chdir(path_element);
|
||||
Change_directory(path_element);
|
||||
}
|
||||
Extract_filename(path_element, full_path);
|
||||
if (luaL_loadfile(L,path_element) != 0)
|
||||
@ -2083,7 +2082,7 @@ int L_Run(lua_State* L)
|
||||
}
|
||||
nested_calls--;
|
||||
// restore directory
|
||||
chdir(saved_directory);
|
||||
Change_directory(saved_directory);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -2323,7 +2322,7 @@ void Run_script(const char *script_subdirectory, const char *script_filename)
|
||||
// This chdir is for the script's sake. Grafx2 itself will (try to)
|
||||
// not rely on what is the system's current directory.
|
||||
Extract_path(buf,Last_run_script);
|
||||
chdir(buf);
|
||||
Change_directory(buf);
|
||||
|
||||
L = luaL_newstate(); // used to be lua_open() on Lua 5.1, deprecated on 5.2
|
||||
|
||||
|
||||
@ -1518,7 +1518,7 @@ byte Button_Load_or_Save(T_Selector_settings *settings, byte load, T_IO_Context
|
||||
Display_bookmark(bookmark_dropdown[temp],temp);
|
||||
}
|
||||
|
||||
chdir(context->File_directory);
|
||||
Change_directory(context->File_directory);
|
||||
Get_current_directory(Selector->Directory,MAX_PATH_CHARACTERS);
|
||||
|
||||
// Affichage des premiers fichiers visibles:
|
||||
@ -2046,7 +2046,7 @@ byte Button_Load_or_Save(T_Selector_settings *settings, byte load, T_IO_Context
|
||||
has_clicked_ok=0;
|
||||
|
||||
// We must enter the directory
|
||||
if (!chdir(Selector_filename))
|
||||
if (Change_directory(Selector_filename) == 0)
|
||||
{
|
||||
#if defined (__MINT__)
|
||||
static char path[1024]={0};
|
||||
|
||||
9
src/io.c
9
src/io.c
@ -540,3 +540,12 @@ const char * Get_current_directory(char * buf, size_t size)
|
||||
return getcwd(buf, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
int Change_directory(const char * path)
|
||||
{
|
||||
#if defined(__WIN32__) || defined(WIN32)
|
||||
return (SetCurrentDirectoryA(path) ? 0 : -1);
|
||||
#else
|
||||
return chdir(path);
|
||||
#endif
|
||||
}
|
||||
|
||||
5
src/io.h
5
src/io.h
@ -32,6 +32,7 @@
|
||||
/// - opendir()
|
||||
/// - readdir()
|
||||
/// - getcwd()
|
||||
/// - chdir()
|
||||
/// - Also, don't assume "/" or "\\", use PATH_SEPARATOR
|
||||
/// If you don't, you break another platform.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
@ -130,3 +131,7 @@ 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);
|
||||
|
||||
///
|
||||
/// Change current directory. return 0 for success, -1 in case of error
|
||||
int Change_directory(const char * path);
|
||||
|
||||
@ -1723,7 +1723,7 @@ void Delete_safety_backups(void)
|
||||
|
||||
For_each_file(Config_directory, Add_backup_file);
|
||||
|
||||
chdir(Config_directory);
|
||||
Change_directory(Config_directory);
|
||||
for (element=Backups_main; element!=NULL; element=element->Next)
|
||||
{
|
||||
if(remove(element->String))
|
||||
|
||||
@ -73,7 +73,6 @@
|
||||
#if defined(__WIN32__)
|
||||
#include <windows.h>
|
||||
#include <shlwapi.h>
|
||||
#define chdir(dir) SetCurrentDirectory(dir)
|
||||
#elif defined (__MINT__)
|
||||
#include <mint/osbind.h>
|
||||
#elif defined(__macosx__)
|
||||
@ -489,12 +488,8 @@ int Init_program(int argc,char * argv[])
|
||||
Set_data_directory(program_directory,Data_directory);
|
||||
// Choose directory for settings (read/write)
|
||||
Set_config_directory(program_directory,Config_directory);
|
||||
#if defined(__MINT__)
|
||||
strcpy(Main.selector.Directory,program_directory);
|
||||
#else
|
||||
// On détermine le répertoire courant:
|
||||
getcwd(Main.selector.Directory,MAX_PATH_CHARACTERS);
|
||||
#endif
|
||||
Get_current_directory(Main.selector.Directory,MAX_PATH_CHARACTERS);
|
||||
|
||||
#ifdef ENABLE_FILENAMES_ICONV
|
||||
// Initialisation de iconv
|
||||
@ -1005,7 +1000,7 @@ void Program_shutdown(void)
|
||||
}
|
||||
|
||||
// On prend bien soin de passer dans le répertoire initial:
|
||||
if (chdir(Initial_directory)!=-1)
|
||||
if (Change_directory(Initial_directory)==0)
|
||||
{
|
||||
// On sauvegarde les données dans le .CFG et dans le .INI
|
||||
if (Config.Auto_save)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user