# New Ticket Created by Kay-Uwe Huell # Please include the string: [perl #41320] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=41320 >
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi parrot-team, needed rename() function, which I have implemented in os.pmc (POSIX only). Attached you will find the patch. Regards, Kiwi diffstat: src/pmc/os.pmc | 24 ++++++++++++++++++++++++ t/pmc/os.t | 24 ++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFtc6MHSiAp6bcIcgRAi+WAKC8w//gH+9LEqW4gjniVSswzv6oYACdHxw0 YGmA42xPlHWef6wOIJY5Y4M= =zep0 -----END PGP SIGNATURE-----
Index: src/pmc/os.pmc
===================================================================
--- src/pmc/os.pmc (Revision 16765)
+++ src/pmc/os.pmc (Arbeitskopie)
@@ -485,8 +485,32 @@
return NULL;
#endif
}
+/*
+=item C<rename(STRING* oldpath, STRING* newpath)>
+This method is a wrapper for rename(2). On error a SystemError exception is
+thrown.
+=cut
+*/
+ METHOD void rename(STRING* oldpath, STRING* newpath) {
+#ifndef WIN32
+ char *coldpath = string_to_cstring(interp, oldpath) ;
+ char *cnewpath = string_to_cstring(interp, newpath) ;
+ int ret ;
+
+ ret = rename(coldpath, cnewpath) ;
+ if (ret < 0)
+ {
+ char *errmsg = strerror(errno) ;
+ real_exception(interp, NULL, E_SystemError, errmsg) ;
+ }
+#else
+ real_exception(interp, NULL, E_NotImplementedError,
+ "Win32 is not POSIX. Need win32 developer!");
+#endif
+ }
+
}
/*
Index: t/pmc/os.t
===================================================================
--- t/pmc/os.t (Revision 16765)
+++ t/pmc/os.t (Arbeitskopie)
@@ -6,7 +6,7 @@
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 14;
+use Parrot::Test tests => 15;
use Parrot::Config;
use Cwd;
use File::Spec;
@@ -194,7 +194,7 @@
# test readdir
SKIP: {
- skip 'broken on windows', 1 if ($MSWin32);
+ skip 'not implemented on windows yet', 1 if ($MSWin32);
opendir IN, '.';
my @entries = readdir IN;
@@ -212,6 +212,26 @@
CODE
}
+# test rename
+SKIP: {
+ skip 'not implemented on windows yet', 1 if ($MSWin32);
+
+ `touch ____some_test_file` ;
+
+ pir_output_is( <<'CODE', <<"OUT", 'Test OS.rename' );
+.sub main :main
+ $P1 = new .OS
+ $P1.rename('____some_test_file', '___some_other_file')
+ $I0 = stat '___some_other_file', 0
+ print $I0
+ print "\n"
+ $P1.rm('___some_other_file')
+.end
+CODE
+1
+OUT
+}
+
# test lstat
my $lstat;
pmc_os_rename.patch.sig
Description: Binary data
