Implement GetCurrentDir in the c rtl
authorkoda
Sat, 23 Apr 2016 16:32:18 -0400
changeset 11687 2c21bc80c95d
parent 11686 8fca9fd31357
child 11688 17d102f9515d
Implement GetCurrentDir in the c rtl
hedgewars/pas2cRedo.pas
project_files/hwc/rtl/fileio.c
project_files/hwc/rtl/fileio.h
--- a/hedgewars/pas2cRedo.pas	Sat Apr 23 16:18:07 2016 -0400
+++ b/hedgewars/pas2cRedo.pas	Sat Apr 23 16:32:18 2016 -0400
@@ -113,4 +113,5 @@
 
     Load_GL_VERSION_2_0 : procedure;
 
+    GetCurrentDir : function : PChar;
 
--- a/project_files/hwc/rtl/fileio.c	Sat Apr 23 16:18:07 2016 -0400
+++ b/project_files/hwc/rtl/fileio.c	Sat Apr 23 16:32:18 2016 -0400
@@ -8,9 +8,11 @@
 #include <stdlib.h>
 #include <assert.h>
 #include <sys/stat.h>
+#include <unistd.h>
 
 io_result_t IOResult;
 int FileMode;
+char cwd[1024];
 
 static void init(File f) {
     f->fp = NULL;
@@ -219,6 +221,17 @@
     return false;
 }
 
+char * fpcrtl_getCurrentDir(void) {
+
+    IOResult = IO_NO_ERROR;
+
+    if (getcwd(cwd, sizeof(cwd)) != NULL)
+        return cwd;
+
+    IOResult = IO_ERROR_DUMMY;
+    return "";
+}
+
 void __attribute__((overloadable)) fpcrtl_flush(Text f) {
     fflush(f->fp);
 }
--- a/project_files/hwc/rtl/fileio.h	Sat Apr 23 16:18:07 2016 -0400
+++ b/project_files/hwc/rtl/fileio.h	Sat Apr 23 16:32:18 2016 -0400
@@ -75,4 +75,7 @@
 bool        fpcrtl_fileExists(string255 filename);
 #define     fpcrtl_FileExists                           fpcrtl_fileExists
 
+char *      fpcrtl_getCurrentDir(void);
+#define     fpcrtl_GetCurrentDir                        fpcrtl_getCurrentDir
+
 #endif /* FILEIO_H_ */