[Mono-list] First attempt at a POSIX wrapper

Adam Keys akeys@post.cis.smu.edu
28 Nov 2002 11:02:24 -0600


--=-BXAxLMKOJvAWiLOjA2M5
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

In my infinite wisdom I attached the wrong bloody file.  The one
attached here is the most recent attempt.

Sorry for the confusion
-- 
AKK~
http://trmk.org/~adam/blog

--=-BXAxLMKOJvAWiLOjA2M5
Content-Disposition: attachment; filename=PosixProcess.cs
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; name=PosixProcess.cs; charset=ISO-8859-1

//
// PosixProcess.cs
// Process Environment functions:
//	getpid, getppid, getuid, geteuid, getgid, getegid
//	setuid, setgid, setpgid, setsid
//	getgroups, getlogin, getpgrp
//	uname, time, times, getenv, ctermid, ttyname, isatty, sysconf
//
// Author:
//    Adam Keys (adam@trmk.org)
//
// (C) 2002 Adam Keys
//

using System.Runtime.InteropServices;

// these are "typedef'd" for lack of a better thing to do
using pid_t =3D System.Int32;
using gid_t =3D System.Int32;
using uid_t =3D System.Int32;
using time_t =3D System.Int32;
using size_t =3D System.Int32;
using clock_t =3D System.Int32;

namespace POSIX {

class utsname {
	string _sysname;
	string _nodename;
	string _release;
	string _version;
	string _machine;
	string _domainname;

	public string sysname {
		get { return _sysname; }
	}

	public string nodename {
		get { return _nodename; }
	}

	public string release {
		get { return _release; }
	}

	public string version {
		get { return _version; }
	}

	public string machine {
		get { return _machine; }
	}

	public string domainname {
		get { return _domainname; }
	}
}

class tms {
	clock_t _tms_utime; // user time
	clock_t _tms_stime; // system time
	clock_t _tms_cutime; // children's user time
	clock_t _tms_cstime; // children's system time

	public clock_t tms_utime {
		get { return _tms_utime; }
	}

	public clock_t tms_stime {
		get { return _tms_stime; }
	}

	public clock_t tms_cutime {
		get { return _tms_cutime; }
	}

	public clock_t tms_cstime {
		get { return _tms_cstime; }
	}
}

class POSIX {

	// These all return int right now, but in reality they return a typedef
	// which may be kernel-dependent.  Should these return a struct instead?
	// Will that matter once they become internal calls?  Do we care?

	[DllImport("libc", EntryPoint=3D"getpid")]
	public static extern pid_t getpid();

	[DllImport("libc", EntryPoint=3D"getppid")]
	public static extern pid_t getppid();

	[DllImport("libc", EntryPoint=3D"getuid")]
	public static extern uid_t getuid();

	[DllImport("libc", EntryPoint=3D"geteuid")]
	public static extern uid_t geteuid();

	[DllImport("libc", EntryPoint=3D"getgid")]
	public static extern gid_t getgid();

	[DllImport("libc", EntryPoint=3D"getegid")]
	public static extern gid_t getegid();

	[DllImport("libc", EntryPoint=3D"setuid")]
	public static extern int setuid(uid_t uid);

	[DllImport("libc", EntryPoint=3D"setgid")]
	public static extern int setgid(gid_t gid);

	[DllImport("libc", EntryPoint=3D"setpgid")]
	public static extern int setpgid(gid_t pgid);

	[DllImport("libc", EntryPoint=3D"setsid")]
	public static extern pid_t setsid();

	[DllImport("libc", EntryPoint=3D"getgroups")]
	public static extern int getgroups(int size, gid_t[] list);

	[DllImport("libc", EntryPoint=3D"setgroups")]
	public static extern int setgroups(size_t size, gid_t[] list);

	[DllImport("libc", EntryPoint=3D"getlogin")]
	public static extern string getlogin();

	[DllImport("libc", EntryPoint=3D"getpgrp")]
	public static extern int getpgrp();

	[DllImport("libc", EntryPoint=3D"uname")]
	public static extern int uname(utsname buf);

	[DllImport("libc", EntryPoint=3D"time")]
	public static extern time_t time(time_t t);

	[DllImport("libc", EntryPoint=3D"times")]
	public static extern clock_t times(tms buf);

	[DllImport("libc", EntryPoint=3D"getenv")]
	public static extern string getenv(string name);

	[DllImport("libc", EntryPoint=3D"ctermid")]
	public static extern string ctermid(string s);

	[DllImport("libc", EntryPoint=3D"ttyname")]
	public static extern string ttyname(int desc);

	[DllImport("libc", EntryPoint=3D"isatty")]
	public static extern int isatty(int desc);

	[DllImport("libc", EntryPoint=3D"sysconf")]
	public static extern long sysconf(int name);
}
}

--=-BXAxLMKOJvAWiLOjA2M5--