[Mono-list] First attempt at a POSIX wrapper

Simon Waite simon@psionics.demon.co.uk
Thu, 28 Nov 2002 09:23:42 -0000


nice reference (perl-based) here:

http://www.perl.com/doc/manual/html/lib/POSIX.html


----- Original Message -----
From: "Adam Keys" <akeys@post.cis.smu.edu>
To: <lupus@ximian.com>; "Mono List" <mono-list@ximian.com>
Sent: Wednesday, November 27, 2002 10:49 PM
Subject: [Mono-list] First attempt at a POSIX wrapper


> I've included my first (very rough) attempt at a POSIX wrapper.  This is
> more of an exploratory prototype than anything else.  Its highly
> unlikely that you'll find that it works correctly, let alone useful.
> Regardless I wanted to get Paulo and the rest of the list's feelings on
> it.
>
> Issues:
>
> o No test suite yet.  I'm not sure if I should just test whether the
> functions are invoked properly (they return and the runtime doesn't
> crash) or some sanity checks on the output should be included.  I
> presume we're going to rely on the host vendor to make sure the
> P/Invoked functions do the write thing.  I have included a quick hack at
> what they might look at based on TemplateTest.cs.
>
> o Things like uid_t, pid_t, time_t, etc. are aliased to System.Int32.
> It's my understanding that these are usually kernel specific items.
> Should we attempt to generate a file that defines these properly on a
> per-platform basis?
>
> o Should said types be thrown into a separate PosixTypes.cs file?
>
> o Is the implementation of utsname and tms the right way to go when a
> function returns a struct?  Since classes are reference types, I presume
> the caller can pass in an object to be filled in, just as a C caller
> would do.
>
> o Should all the directly-mapped POSIX functions be thrown into one
> POSIX.POSIX class or should they be broken out as I've started to do
> here?
>
> o The only place I could find info on what is in POSIX and what's not is
> http://j4p.sourceforge.net/.  I checked the POSIX man page and it has
> stuff like cos and asin which I wouldn't think are in the POSIX
> standards.  So, I need some canonical source from which I can determine
> which functions to include.
>
> I think that pretty much covers my thoughts at the time.
>
> Looking forward to feedback,
> --
> AKK~
> http://trmk.org/~adam/blog
>


----------------------------------------------------------------------------
----


//
// Posix.cs
//
// Author:
//    Adam Keys (adam@trmk.org)
//
// (C) 2002 Adam Keys
//

using System.Runtime.InteropServices;

namespace POSIX {
class POSIX {
[DllImport ("libc.so.6", EntryPoint="getpid")]
public static extern int getpid();

[DllImport ("libc.so.6", EntryPoint="getppid")]
public static extern int getppid();

[DllImport ("libc.so.6", EntryPoint="chown")]
public static extern int chown (string path, int owner, int group);

[DllImport ("libc.so.6", EntryPoint="execv")]
public static extern int execv (string path, string[] argv);
}
}