[Mono-dev] System.IO or Mono.Unix

David Brown mono at davidb.org
Fri Dec 22 13:58:19 EST 2006

Luciano _ wrote:

> First: I'm developing an application that use System.IO and i read that
> there are some IO operation classes in the Mono.Unix namespace. Which
is the
> best solution? System.IO or Mono.Unix? I'm developing a Linux-Only
> Application.

The simple answer would be: does your application depend on knowledge of
the specifics of Linux or Unix filesystem semantics?  If so, you should use
the native calls.  Otherwise, use the portable calls.

For example, writing Linux backup software would definitely need to use the
Mono.Unix calls, since the program needs to accurately backup the
information directly.

> Second: Could someone explain (example) how
> Mono.Unix.DirectoryInfo.GetEntries works?  i need to get all the
> directories/files/symbolic links and: length, datetime creation and
> modified, fullpath, etc.  I don't understand how to use the returned
> (Mono.Unix.Native.Dirent) and how to convert to UnixFileInfo or
> UnixSymbolicLinkInfo.

The only portable field in the Dirent is d_name, which will give you a
string.  Use Mono.Unix.Native.lstat to get the rest of the information.
The names UnixSymbolicLinkInfo and UnixFileInfo are kind of misleading.  I
personally think that wrapper is more confusing than it is worth.  The
lstat will fill in a Mono.Unix.Native.Stat which will have what you want.
Remember, you might need the routines in Mono.Unix.Marshal to convert the
Posix time fields to something useful in the rest of Mono.  I have not had
success doing these conversions without confusion between localtime and
UTC, though.

The question you are asking suggests you need to use the native calls.


More information about the Mono-devel-list mailing list