[Mono-dev] Fixing KeventWatcher: dealing with 32 / 64 bit operating systems

Robert Jordan robertj at gmx.net
Sat Sep 19 05:46:06 EDT 2009


Romain Tartière wrote:
> My problem is related to the various structs (kevent and timespec).
> 
> Basically, a 32 bit FreeBSD needs:
> ------8<------------------------
> struct timespec {
> 	public int tv_sec;
> 	public int tv_usec;
> }
> ------8<------------------------
> while a 64 bit FreeBSD needs:
> ------8<------------------------
> struct timespec {
> 	public long tv_sec;
> 	public long tv_usec;
> }
> ------8<------------------------
> 
> I would like to know what would be the best way to handle this
> difference.  I can't find any relevant information on the Internet (I am
> probably missing the good keywords), and the solutions I see (duplicate
> code or encapsulate) look a bit weak to my eyes.

For *BSD, timespec is declared like this in native code:

struct timespec {
	time_t  tv_sec;         /* seconds */
	long    tv_nsec;        /* and nanoseconds */
};

while "time_t" is an "int32_t" on 32-bit and "int64_t" on 64-bit.
Long is "int32_t" on 32-bit and "int64_t" on 64-bit, so we can
use IntPtr in the C# p/invoke declaration:

struct timespec {
	public IntPtr tv_sec;
	public IntPtr tv_usec;
}

Robert



More information about the Mono-devel-list mailing list