From 7dcf01fdf6adf3247ab5689e27205a0f7374827e Mon Sep 17 00:00:00 2001 From: BigDave Date: Tue, 17 Jul 2018 19:44:41 +0100 Subject: [PATCH] Set current dir at runtime Maybe later we could have an option for this --- .vscode/settings.json | 3 ++- interpreter.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index c37f2dd..b14b870 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -40,6 +40,7 @@ "files.associations": { "ph7int.h": "c", "ph7.h": "c", - "stdlib.h": "c" + "stdlib.h": "c", + "direct.h": "c" } } \ No newline at end of file diff --git a/interpreter.c b/interpreter.c index 6b39c6c..9e4caaa 100644 --- a/interpreter.c +++ b/interpreter.c @@ -184,6 +184,25 @@ int main(int argc, char **argv) { PH7_VM_CONFIG_IMPORT_PATH, "test" ); + + char* cwd; + // Get the current working directory: +#ifdef __WINNT__ + if((cwd = _getcwd( NULL, 0 )) == NULL) +#else + if((cwd = getcwd( NULL, 0 )) == NULL) +#endif + perror("_getcwd error"); + else + { + printf("cwd: %s\n", cwd); + rc = ph7_vm_config(pVm, + PH7_VM_CONFIG_IMPORT_PATH, + cwd + ); + free(cwd); + } + if(rc != PH7_OK) { Fatal("Error while installing the VM output consumer callback"); }