Add "file_delete" method in String and NativeString.
authorJean-Sebastien Gelinas <calestar@gmail.com>
Fri, 24 Oct 2008 01:14:12 +0000 (21:14 -0400)
committerJean-Sebastien Gelinas <calestar@gmail.com>
Fri, 24 Oct 2008 01:14:12 +0000 (21:14 -0400)
Implemented native function to delete a file.

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

index 2bc580e..7dbf17a 100644 (file)
@@ -2,6 +2,7 @@
 #
 # Copyright 2004-2008 Jean Privat <jean@pryen.org>
 # Copyright 2008 Floréal Morandat <morandat@lirmm.fr>
+# Copyright 2008 Jean-Sébastien Gélinas <calestar@gmail.com>
 #
 # This file is free software, which comes along with NIT.  This software is
 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
@@ -197,6 +198,8 @@ redef class String
 
        meth file_stat: FileStat do return to_cstring.file_stat
 
+       meth file_delete: Bool do return to_cstring.file_delete
+
        meth strip_extension(ext: String): String
        do
                if has_suffix(ext) then
@@ -258,6 +261,7 @@ redef class NativeString
        private meth file_exists: Bool is extern "string_NativeString_NativeString_file_exists_0"
        private meth file_stat: FileStat is extern "string_NativeString_NativeString_file_stat_0"
        private meth file_mkdir: Bool is extern "string_NativeString_NativeString_file_mkdir_0"
+       private meth file_delete: Bool is extern "string_NativeString_NativeString_file_delete_0"
 end
 
 universal FileStat
index cf14118..50465f3 100644 (file)
@@ -2,6 +2,7 @@
  *
  * Copyright 2004-2008 Jean Privat <jean@pryen.org>
  * Copyright 2008 Floréal Morandat <morandat@lirmm.fr> 
+ * Copyright 2008 Jean-Sébastien Gélinas <calestar@gmail.com>
  *
  * This file is free software, which comes along with NIT.  This software is
  * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
@@ -47,3 +48,7 @@ int file_NativeFile_NativeFile_file_stat_0(FILE *f){
                return to_nit_file_stat(&buff);
        return 0;
 }
+
+extern int string_NativeString_NativeString_file_delete_0(char *f){
+  return (remove(f) == 0);
+}
index bca7e90..de67757 100644 (file)
@@ -4,6 +4,7 @@
  *
  * Copyright 2004-2008 Jean Privat <jean@pryen.org>
  * Copyright 2008 Floréal Morandat <morandat@lirmm.fr> 
+ * Copyright 2008 Jean-Sébastien Gélinas <calestar@gmail.com>
  *
  * This file is free software, which comes along with NIT.  This software is
  * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
@@ -22,6 +23,7 @@
 extern int string_NativeString_NativeString_file_exists_0(char *f);
 extern void *string_NativeString_NativeString_file_stat_0(char *f);
 extern void *file_NativeFile_NativeFile_file_stat_0(FILE *f);
+extern int string_NativeString_NativeString_file_delete_0(char *f);
 
 #define file_NativeFile_NativeFile_io_read_2(p, b, l) fread((b), 1, (l), (FILE*)(p))
 #define file_NativeFile_NativeFile_io_write_2(p, b, l) fwrite((b), 1, (l), (FILE*)(p))