develooper Front page | perl.perl5.porters | Postings from November 2006

POSIX::remove() and directories

Thread Next
From:
Dintelmann, Peter
Date:
November 22, 2006 08:42
Subject:
POSIX::remove() and directories
Message ID:
3852726AFA94DE4F87E616F13F416A5F0A912F@naimucu1.ffz00k.rootdom.net
The POSIX documents available to me and Stevens' APUE
say that the remove() function should be equivalent to
rmdir() if the given path is a directory. However I do
not have an original copy of POSIX.1-1990 (I think the
POSIX module is based on that version) to double-check 
this.

Here is a proposal for a patch to achieve the described
behaviour with the POSIX module.

$ diff -urd perl-current/ext/POSIX/POSIX.pm /var/tmp/POSIX.pm
--- perl-current/ext/POSIX/POSIX.pm     2006-08-16 15:13:35.000000000 +0200
+++ /var/tmp/POSIX.pm   2006-11-22 17:23:04.000000000 +0100
@@ -421,7 +421,7 @@

 sub remove {
     usage "remove(filename)" if @_ != 1;
-    CORE::unlink($_[0]);
+    (-d $_[0]) ? CORE::rmdir($_[0]) : CORE::unlink($_[0]);
 }

 sub rename {



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About