file: add getcwd
authorJean Privat <jean@pryen.org>
Tue, 3 Sep 2013 15:34:04 +0000 (11:34 -0400)
committerJean Privat <jean@pryen.org>
Tue, 3 Sep 2013 18:10:39 +0000 (14:10 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/standard/file.nit
lib/standard/file_nit.h

index a6b1aef..0b2c71f 100644 (file)
@@ -47,6 +47,10 @@ redef class Object
        do
                return stdin.read_line
        end
+
+       # Return the working (current) directory
+       protected fun getcwd: String do return file_getcwd.to_s
+       private fun file_getcwd: NativeString is extern "string_NativeString_NativeString_file_getcwd_0"
 end
 
 # File Abstract Stream
index 4291f02..56ed616 100644 (file)
@@ -48,6 +48,7 @@ extern int string_NativeString_NativeString_file_delete_0(char *f);
 #define file_FileStat_FileStat_size_0(self) (((struct stat*)self)->st_size)
 
 #define string_NativeString_NativeString_file_mkdir_0(p) (mkdir(p, 0777))
+#define string_NativeString_NativeString_file_getcwd_0(p) (getcwd(NULL, 0))
 
 #define file_stdin_poll_in(self) file_stdin_poll_in_()
 int file_stdin_poll_in_(void);