[m-dev.] mkdir / rmdir posix modules
Michael Day
mikeday at corplink.com.au
Tue Jun 26 15:20:24 AEST 2001
Hi,
Could these two modules be added to extras/posix?
Plus two lines to posix.m:
:- include_module posix__mkdir.
:- include_module posix__rmdir.
Michael
-------------- next part --------------
%------------------------------------------------------------------------------%
% Copyright (C) 2001 The University of Melbourne.
% This file may only be copied under the terms of the GNU Library General
% Public License - see the file COPYING.LIB in the Mercury distribution.
%------------------------------------------------------------------------------%
%
% module: posix__mkdir.m
% main author: miked at lendtech.com.au
%
%------------------------------------------------------------------------------%
:- module posix__mkdir.
:- interface.
:- import_module string.
:- pred mkdir(string, mode, posix__result, io__state, io__state).
:- mode mkdir(in, in, out, di, uo) is det.
%------------------------------------------------------------------------------%
:- implementation.
:- import_module int.
:- pragma c_header_code("
#include <sys/types.h>
#include <sys/stat.h>
").
%------------------------------------------------------------------------------%
mkdir(Path, Mode, Result) -->
mkdir0(Path, Mode, Res),
( if { Res = 0 } then
{ Result = ok }
else
errno(Err),
{ Result = error(Err) }
).
:- pred mkdir0(string, mode, int, io__state, io__state).
:- mode mkdir0(in, in, out, di, uo) is det.
:- pragma c_code(mkdir0(Path::in, Mode::in, Res::out, IO0::di, IO::uo),
[will_not_call_mercury, thread_safe], "
Res = mkdir(Path, Mode);
IO = IO0;
").
%------------------------------------------------------------------------------%
-------------- next part --------------
%------------------------------------------------------------------------------%
% Copyright (C) 2001 The University of Melbourne.
% This file may only be copied under the terms of the GNU Library General
% Public License - see the file COPYING.LIB in the Mercury distribution.
%------------------------------------------------------------------------------%
%
% module: posix__rmdir.m
% main author: miked at lendtech.com.au
%
%------------------------------------------------------------------------------%
:- module posix__rmdir.
:- interface.
:- import_module string.
:- pred rmdir(string, posix__result, io__state, io__state).
:- mode rmdir(in, out, di, uo) is det.
%------------------------------------------------------------------------------%
:- implementation.
:- import_module int.
:- pragma c_header_code("
#include <unistd.h>
").
%------------------------------------------------------------------------------%
rmdir(Path, Result) -->
rmdir0(Path, Res),
( if { Res = 0 } then
{ Result = ok }
else
errno(Err),
{ Result = error(Err) }
).
:- pred rmdir0(string, int, io__state, io__state).
:- mode rmdir0(in, out, di, uo) is det.
:- pragma c_code(rmdir0(Path::in, Res::out, IO0::di, IO::uo),
[will_not_call_mercury, thread_safe], "
Res = rmdir(Path);
IO = IO0;
").
%------------------------------------------------------------------------------%
More information about the developers
mailing list