From f5e086e75e211aab76082684de3a8d34b04c6dd0 Mon Sep 17 00:00:00 2001 From: Jean-Sebastien Gelinas Date: Thu, 23 Oct 2008 21:14:12 -0400 Subject: [PATCH] Add "file_delete" method in String and NativeString. Implemented native function to delete a file. --- lib/standard/file.nit | 4 ++++ lib/standard/file_nit.c | 5 +++++ lib/standard/file_nit.h | 2 ++ 3 files changed, 11 insertions(+) diff --git a/lib/standard/file.nit b/lib/standard/file.nit index 2bc580e..7dbf17a 100644 --- a/lib/standard/file.nit +++ b/lib/standard/file.nit @@ -2,6 +2,7 @@ # # Copyright 2004-2008 Jean Privat # Copyright 2008 Floréal Morandat +# Copyright 2008 Jean-Sébastien Gélinas # # 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 diff --git a/lib/standard/file_nit.c b/lib/standard/file_nit.c index cf14118..50465f3 100644 --- a/lib/standard/file_nit.c +++ b/lib/standard/file_nit.c @@ -2,6 +2,7 @@ * * Copyright 2004-2008 Jean Privat * Copyright 2008 Floréal Morandat + * Copyright 2008 Jean-Sébastien Gélinas * * 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); +} diff --git a/lib/standard/file_nit.h b/lib/standard/file_nit.h index bca7e90..de67757 100644 --- a/lib/standard/file_nit.h +++ b/lib/standard/file_nit.h @@ -4,6 +4,7 @@ * * Copyright 2004-2008 Jean Privat * Copyright 2008 Floréal Morandat + * Copyright 2008 Jean-Sébastien Gélinas * * 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)) -- 1.7.9.5