Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement mkdir
Signed-Off-By: Moritz Lenz <moritz@faui2k3.org>
  • Loading branch information
Geoffrey Broadwell authored and moritz committed Oct 21, 2009
1 parent 0117dd3 commit c4e6d0f
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion src/builtins/io.pir
Expand Up @@ -162,7 +162,7 @@ true value is returned.
push_eh failure
os.'chdir'(newdir)
pop_eh

# Update $*CWD and we're done.
$S0 = os."cwd"()
$P0 = box $S0
Expand All @@ -175,6 +175,47 @@ true value is returned.
.tailcall '!FAIL'('Unable to change to directory "', newdir, '"')
.end


=item mkdir STRING [, MODE]

Creates a new directory, optionally setting specific permissions (which
are modified by the user's umask). If omitted, the permissions default
to 0o777 (full access to all).
mkdir '/new/dir';
mkdir '/new/dir', 0o755;
On success a true value is returned.
=cut
.sub 'mkdir'
.param string newdir
.param int mode :optional
.param int has_mode :opt_flag
# Default mode to 0o777
if has_mode goto have_mode
mode = 0o777
have_mode:
# Try to create the directory; if we fail, exception thrown, so catch
# it and fail if needed.
.local pmc os
os = root_new ['parrot';'OS']
push_eh failure
os.'mkdir'(newdir, mode)
pop_eh
# Success, we're done.
$P0 = get_hll_global ['Bool'], 'True'
.return ($P0)

failure:
pop_eh
.tailcall '!FAIL'('Unable to create directory "', newdir, '"')
.end

=back

=cut
Expand Down

0 comments on commit c4e6d0f

Please sign in to comment.