[Mono-list] Mono.Unix.Magic libmagic wrapper

Jonathan Pryor jonpryor at vt.edu
Sat Sep 23 06:23:10 EDT 2006

On Fri, 2006-09-22 at 23:25 -0400, Milosz Tanski wrote:
> I wrote a wrapper for the unix libmagic library since it's very handy
> sometimes (and I'm using this wrapper in my app right now, so I figured
> might as well submit it). Sorry that's it's not a diff, but I'd know
> exactly how to integrate it with the class library build system.

I have a few questions/concerns/observations:

1.  Can libmagic be used on Windows without the use of Cygwin?  I think
it can be, but I'm not entirely sure.  If it can be, I'm not sure that
Mono.Unix is the best place for it (deliberately ignoring the Mono.Unix
types which can work on Windows, Mono.Unix.Native.Stdlib &
Mono.Unix.Native.StdioFileStream).  If libmagic can't work on Windows
without Cygwin, then Mono.Unix is probably a reasonable spot for it.

2.  I'm not fond of the name "Magic."  Yes, it's a `libmagic' wrapper,
but for those who don't know what `libmagic' is, it's not a very
informative name.  Considering that it's used by the file(1) command,
I'm sure some better name could be found.  Perhaps FileTypeInfo?

Of course, any name would need to be "stand-alone"-ish, and not be
easily confused with the existing UnixFileSystemInfo & UnixFileInfo

3.  The Magic.Descrition property should be Magic.Description.

4.  You should get libmagic to generate UTF-8 (it it doesn't do so by
default) and use UnixEncoding to do the UTF-8 -> string conversion (in
case Mono's Marshal.PtrToStringAuto ever stops doing UTF-8, and there's
a bug open to investigate that).

5.  If it does get into Mono.Unix, the magic_* methods taking a filename
should make use of the Mono.Unix.Native.FileNameMarshaler custom
marshaler for "proper" filename transfers (for when a filename contains
random binary data instead of being valid UTF-8).  See

6.  Documentation -- are you willing to write it? :-)

Thank you for the file.

 - Jon

More information about the Mono-list mailing list