tuitfun writes:
 > i am new to gnuwin32. i am trying to compile a test program from glibc that
 > uses scandir. i compiled it with:
 > gcc scandirtst.c -I/c/Program\ Files/GnuWin32/include/glibc/  /c/Program\
 > Files/GnuWin32/lib/libgw32c.a -lole32 -luuid -o scandirtst

please note that scandir() is not portable even across Unix platforms.

No offence to the people behind gnuwin32, in general their porting
effort is very nice. But I think one should avoid using "libgw32c" if
at all possible.

What follows is a bit of a rant, and not relevant just for test and
toy programs. But if you intend to write something more substantial
for a wider audience, please take these points into consideration.

You are making yourself a disfavour if you think that you can use Unix
code directly on Windows, especially code that needs to handle *any*
file name that might occur on a Windows system. You might not yourself
have ever seen files with names in anything else than your locale's
codepage. But this issue is important if your code has or might
eventually have users all over the world. In some locales it might be
quite common to come across files with names that can't be expressed
in the system codepage. For instance, in Israel I guess it happens
that one needs to handle both Hebrew and Arabic file names (in
addition to file names in just plain ASCII).

On Unix, file names are just a sequence of bytes (C type char). Any
interpretation of these byte sequences is up to user-level code, the
kernel doesn't care. 

On Windows file names are in Unicode encoded as UTF-16, i.e. a
sequence of two-byte "words" (C type wchar_t). Using char APIs like
scandir() or opendir(), readdir(), closedir() will not be able to
return all files names from a folder. Use the _wopendir(), _wreaddir()
and _wclosedir() functions instead.

You might want to wrap this into something cross-platform, that would
use the wide-character APIs on Windows. Use UTF-8 for filenames in
your upper level code, converting to UTF-16 only when you actually
call the wide char APIs to manipulate files. Luckily most modern
Unixes strongly suggest UTF-8 is used for file name encodings, so you
won't need to do any conversions to your UTF-8 filenames on Unix.

Or, you could use a cross-platform library that already does all this,
like GLib.

--tml

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
GnuWin32-Users mailing list
GnuWin32-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gnuwin32-users

Reply via email to