# New Ticket Created by  Carlin Bingham 
# Please include the string:  [perl #68402]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=68402 >


This is a basic patch to add a mkdir function. The (optional) mode
parameter uses the octal radix markers as in S02 (eg. 0o777, 0o755
etc.) It defaults to 0o777 to mirror Perl 5's behaviour.

Let me know if there is anything wrong with this or something that I
have missed.

Thanks.

--
Carlin
>From e108c3a56d172d05cea79ad9a79c81edb26c289c Mon Sep 17 00:00:00 2001
From: carlin <carlin-pub...@theintersect.org>
Date: Tue, 11 Aug 2009 02:27:58 +1200
Subject: [PATCH] Add mkdir() method

Error handling fix
---
 src/builtins/io.pir |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/src/builtins/io.pir b/src/builtins/io.pir
index 77fd0b5..7efa108 100644
--- a/src/builtins/io.pir
+++ b/src/builtins/io.pir
@@ -174,6 +174,29 @@ true value is returned.
     .tailcall '!FAIL'('Unable to change to directory "', newdir, '"')
 .end
 
+.sub 'mkdir'
+    .param string dirname
+    .param int dirmode :optional
+
+    if dirmode goto make
+    # Be permissive by default, as per reasoning in perldoc -f mkdir
+    dirmode = 0o777
+
+  make:
+    .local pmc os
+    os = root_new ['parrot';'OS']
+    push_eh failure
+    os.'mkdir'(dirname,dirmode)
+    pop_eh
+    $P0 = get_hll_global ['Bool'], 'True'
+    .return ($P0)
+
+  failure:
+    pop_eh
+    .tailcall '!FAIL'('Unable to create directory "', dirname, '"')
+.end
+
+
 =back
 
 =cut
-- 
1.6.0.4

Reply via email to