Platform independent directory access

Hello,

I’m looking for a cross-platform way do to opendir(3) and readdir(3).
This is POSIX, but of course windows wouldn’t let me #include <dirent.h>

If this something that has to be done differently for each platform?
If so, that would be a nice opportunity to write a SDL_io library.

  • Andreas–
    Check out my 3D lightcycle game: http://www.gltron.org
    More than 60’000 Downloads of the latest version (0.59)

“Andreas Umbach” wrote:

Hello,

I’m looking for a cross-platform way do to opendir(3) and readdir(3).
This is POSIX, but of course windows wouldn’t let me #include <dirent.h>

If this something that has to be done differently for each platform?
If so, that would be a nice opportunity to write a SDL_io library.

For C++, the Boost project (http://www.boost.org) seems to have a nicely
designed library for crossplatform directory handling (at least for
win32 and posix systems).

For C… I’m not sure. Bound to be something out there already :slight_smile:

Win32 and posix directory calls map to each other reasonably well, so
a wrapper shouldn’t be too hard. Not sure about directory stuff on MacOS
though.

Ben.–
Ben Campbell (Antipodean Straggler)
Programmer, Creature Labs
ben.campbell at creaturelabs.com
www.creaturelabs.com

Use a real compiler (like mingw32 or even Borland C++ 5.x), not that lame VC
(or shoud I say WC?)> ----- Original Message -----

From: marvin@dataway.ch (Andreas Umbach)
To:
Sent: Tuesday, June 27, 2000 2:17 PM
Subject: [SDL] platform independent directory access

Hello,

I’m looking for a cross-platform way do to opendir(3) and readdir(3).
This is POSIX, but of course windows wouldn’t let me #include <dirent.h>

If this something that has to be done differently for each platform?
If so, that would be a nice opportunity to write a SDL_io library.

  • Andreas

    Check out my 3D lightcycle game: http://www.gltron.org
    More than 60’000 Downloads of the latest version (0.59)

I did this kinda thing with mingw32 before, but quickly learned that
it only supported 8.3 filenames in win32. This may have been fixed
since then, I migrated from mingw32 before SDL 1.0 was released…

Herv? PARISSI wrote:

Use a real compiler (like mingw32 or even Borland C++ 5.x), not that lame
VC> (or shoud I say WC?)

----- Original Message -----
From: “Andreas Umbach”
To:
Sent: Tuesday, June 27, 2000 2:17 PM
Subject: [SDL] platform independent directory access

Hello,

I’m looking for a cross-platform way do to opendir(3) and readdir(3).
This is POSIX, but of course windows wouldn’t let me #include <dirent.h>

If this something that has to be done differently for each platform?
If so, that would be a nice opportunity to write a SDL_io library.

  • Andreas

    Check out my 3D lightcycle game: http://www.gltron.org
    More than 60’000 Downloads of the latest version (0.59)

If this something that has to be done differently for each platform?
If so, that would be a nice opportunity to write a SDL_io library.

Does SDL_gui have an ‘open file’ widget? If so, perhaps its directory-reading
code can be yanked out and made into its own library.

Also, someone here was working on a platform-independant way of handling
game settings ("~/.FILErc" under Linux, “FILE.ini” or something under Windows,
etc.). How’s that coming along?

-bill!

I did this kinda thing with mingw32 before, but quickly learned that
it only supported 8.3 filenames in win32.

Heheh… If people insist on using Windows, I feel they should need
to deal with SHORT~1.FIL names. :wink:

-bill!

Wasn’t there talk about adding file io routines to SDL itself? Whatever
happened to that idea?On Tue, 27 Jun 2000, William Kendrick wrote:

I did this kinda thing with mingw32 before, but quickly learned that
it only supported 8.3 filenames in win32.

Heheh… If people insist on using Windows, I feel they should need
to deal with SHORT~1.FIL names. :wink:

-bill!

For this kind of thing, I would simply wrap the Win32 calls with the POSIX
(or Standard Unix Specification, v2 [which is where I get the API
definitions]).

Here is the current one I have done, though it only has the Win32, though we
should add the Mac version someday (we are a Windows-Mac ‘shop’).

Later,
Tyler Wilson
Systems Programmer
Knowledge Adventure
Torrance, CA 90503
mailto:twilson at education.com

PS Are attachments okay on this list?> ----- Original Message -----

From: Ben Campbell [mailto:ben.campbell@cyberlife.co.uk]
Sent: Tuesday, June 27, 2000 6:08 AM
To: sdl at lokigames.com
Subject: [SDL] Re: platform independent directory access

“Andreas Umbach” wrote:

Hello,

I’m looking for a cross-platform way do to opendir(3) and readdir(3).
This is POSIX, but of course windows wouldn’t let me #include <dirent.h>

If this something that has to be done differently for each platform?
If so, that would be a nice opportunity to write a SDL_io library.

For C++, the Boost project (http://www.boost.org) seems to have a nicely
designed library for crossplatform directory handling (at least for
win32 and posix systems).

For C… I’m not sure. Bound to be something out there already :slight_smile:

Win32 and posix directory calls map to each other reasonably well, so
a wrapper shouldn’t be too hard. Not sure about directory stuff on MacOS
though.

Ben.

Ben Campbell (Antipodean Straggler)
Programmer, Creature Labs
ben.campbell at creaturelabs.com
www.creaturelabs.com

-------------- next part --------------
A non-text attachment was scrubbed…
Name: DIRENT.H
Type: application/octet-stream
Size: 754 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20000627/ed0237d4/attachment.obj
-------------- next part --------------
A non-text attachment was scrubbed…
Name: DIRENT.C
Type: application/octet-stream
Size: 2491 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20000627/ed0237d4/attachment-0001.obj

Wasn’t there talk about adding file io routines to SDL itself? Whatever
happened to that idea?

File io routines aren’t needed since C has them well standardised (stdio).
There are the SDL_RWops, which serve as generalized stdio streams that
allow any source (like memory, compressed files etc). BSD stdio allow this
for FILEs directly, but it isn’t in standard C so we can’t rely on that.

Directory manipulation isn’t at all present in C (but in Posix). I’d
suggest people to write Posix compatibility routines for other platforms,
rather than writing an additional layer.

I think this really does need to be addressed by SDL, as even using the
POSIX functions are not even close to being cross platform. Mainly,
directory delineations. Be/Linux: ‘/’, Win: ‘’, Mac: ‘:’. Not only
that, but Be needs some special setup code, as when an application is
launched from the tracker, the working path is not set, so any
accessing of relative paths will fail (I’m sorry, but it is
unacceptable to ask people to launch games from a terminal). I have
written my own framework to deal with this, but I really think it is
basic enough that SDL really needs to to somehow perform cross platform
file io.

Wasn’t there talk about adding file io routines to SDL itself?
Whatever
happened to that idea?

I did this kinda thing with mingw32 before, but quickly learned
that>On Tue, 27 Jun 2000, William Kendrick wrote:

it only supported 8.3 filenames in win32.

Heheh… If people insist on using Windows, I feel they should need
to deal with SHORT~1.FIL names. :wink:

-bill!

Directory manipulation isn’t at all present in C (but in Posix). I’d
suggest people to write Posix compatibility routines for other platforms,
rather than writing an additional layer.

I agree. I think POSIX directory compliancy is a must for software
development (at least, its the sort of thing I’d have a hard time living
without… I know I’m spoiled ;). It may be beyond the scope of inclusion
in core SDL… but as an addon library I know that I would use it.

(It’s something I need so much I’d probably try to do it, if I only had
other development platforms in addition to my Linux and BeOS boxes).On Tue, 27 Jun 2000, Mattias Engdegard wrote:


Sam Hart http://www.physics.arizona.edu/~hart/
Web Page Highlights: Video Game History, Black Hole Simulation, & more.
OTHER WEB SITES MAINTAINED BY SAM HART
http://www.geekcomix.com/ - Geekcomix, the Daily Geek Comic Strip Site
http://www.physics.arizona.edu/~hart/gw/ - Ghostworks (Alt./Linux Computing)

Sam Hart wrote:

Directory manipulation isn’t at all present in C (but in Posix). I’d
suggest people to write Posix compatibility routines for other platforms,
rather than writing an additional layer.

I agree. I think POSIX directory compliancy is a must for software
development (at least, its the sort of thing I’d have a hard time living
without… I know I’m spoiled ;). It may be beyond the scope of inclusion
in core SDL… but as an addon library I know that I would use it.

Glargh! glob() is really useful!!! Make sure your library has it!!!
(according to the man page, it is in POSIX.2)–
Pierre Phaneuf
http://ludusdesign.com/

Sam Hart wrote:

Directory manipulation isn’t at all present in C (but in Posix). I’d
suggest people to write Posix compatibility routines for other platforms,
rather than writing an additional layer.

I agree. I think POSIX directory compliancy is a must for software
development (at least, its the sort of thing I’d have a hard time living
without… I know I’m spoiled ;). It may be beyond the scope of inclusion
in core SDL… but as an addon library I know that I would use it.

Glargh! glob() is really useful!!! Make sure your library has it!!!
(according to the man page, it is in POSIX.2)

BeOS doesn’t have it. :frowning:

-Sam Lantinga, Lead Programmer, Loki Entertainment Software

William Kendrick wrote:

If this something that has to be done differently for each platform?
If so, that would be a nice opportunity to write a SDL_io library.

Does SDL_gui have an ‘open file’ widget? If so, perhaps its directory-reading
code can be yanked out and made into its own library.

Also, someone here was working on a platform-independant way of handling
game settings ("~/.FILErc" under Linux, “FILE.ini” or something under Windows,
etc.). How’s that coming along?

-bill!

Not yet. I’ve just about got the listbox widget done, which
will enable the file-list to be even thought of… :slight_smile:

-Ray

Current mingw32 (gcc-2.95.2) supports opendir() with LFN
Don’t be that jalous, there wouldn’t have any gnome or kde if
M$ didn’t do Win95 with a cool interface (it’s just the slow & the bugs that are
bad)

Herve PARISSI
"You assume too much" (The Menace Phantom)> ----- Original Message -----

From: nbs@sonic.net (Bill Kendrick)
To:
Sent: Tuesday, June 27, 2000 4:16 PM
Subject: Re: [SDL] platform independent directory access

I did this kinda thing with mingw32 before, but quickly learned that
it only supported 8.3 filenames in win32.

Heheh… If people insist on using Windows, I feel they should need
to deal with SHORT~1.FIL names. :wink:

-bill!

“A” == A Umbach writes:

Hello, I’m looking for a cross-platform way do to opendir(3) and
readdir(3). This is POSIX, but of course windows wouldn’t let me
#include <dirent.h>

If this something that has to be done differently for each platform?
If so, that would be a nice opportunity to write a SDL_io library.

Andreas

Check out my 3D lightcycle game: http://www.gltron.org More than
60’000 Downloads of the latest version (0.59)

Use glib. It’s a utility library written in C, used by GTK and
GNOME. It provides definitions and wrappers for Windows so you can use opendir
transparently. Plus, it has so many other useful things that you will
wonder how you ever got along without it. I have never tried
compiling on Windows, but I know it has been done.

It can be found at www.gtk.org – look at the online reference to see
what it provides (memory allocation, logging, string completion,
hooks, a lexical scanner, lists, hash tables, trees, etc).

=wl–
Albert ``Willy’’ Lee, Emacs user, game programmer
"They call me CRAZY - just because I DARE to DREAM of a RACE of
SUPERHUMAN MONSTERS!"

Use glib. It’s a utility library written in C, used by GTK and
GNOME. It provides definitions and wrappers for Windows so you can
use opendir transparently.

Ok, but what about MacOS and BeOS? What do people who want their programs
to be portable to those OS’s have to do???

-bill!

At 10:44 Uhr -0700 28.06.2000, William Kendrick wrote:

Use glib. It’s a utility library written in C, used by GTK and
GNOME. It provides definitions and wrappers for Windows so you can
use opendir transparently.

Ok, but what about MacOS and BeOS? What do people who want their programs
to be portable to those OS’s have to do???

-bill!

I dunno if this helps you, but exult includes a func that translates
a unix path to Win/MacOS path. Afterwards, you can just use std c lib.

I can provide you with the code, if ya want.

Bye,

Max–

Max “The Black Fingolfin” Horn
mailto:Max_Horn
http://www.quendi.de - please use my guestbook!

Ok, but what about MacOS and BeOS? What do people who want their programs
to be portable to those OS’s have to do???

-bill!

I dunno if this helps you, but exult includes a func that translates
a unix path to Win/MacOS path. Afterwards, you can just use std c lib.

I can provide you with the code, if ya want.

That would be nice. I am presently working on something that /should/
handle Win/MacOS files… but I haven’t a system to test them on… so it
would be nice to have one that works.

I’m familiar w/ exult, all I personally would need is the file it’s
contained in an /maybe/ the line number… though I’m sure there would be
others on the list that would be interrested in more ;)On Wed, 28 Jun 2000, Max Horn wrote:


Sam Hart http://www.physics.arizona.edu/~hart/
Web Page Highlights: Video Game History, Black Hole Simulation, & more.
OTHER WEB SITES MAINTAINED BY SAM HART
http://www.geekcomix.com/ - Geekcomix, the Daily Geek Comic Strip Site
http://www.physics.arizona.edu/~hart/gw/ - Ghostworks (Alt./Linux Computing)

At 12:39 Uhr -0700 28.06.2000, Sam Hart wrote:>On Wed, 28 Jun 2000, Max Horn wrote:

Ok, but what about MacOS and BeOS? What do people who want their programs
to be portable to those OS’s have to do???

-bill!

I dunno if this helps you, but exult includes a func that translates
a unix path to Win/MacOS path. Afterwards, you can just use std c lib.

I can provide you with the code, if ya want.

That would be nice. I am presently working on something that /should/
handle Win/MacOS files… but I haven’t a system to test them on… so it
would be nice to have one that works.

I’m familiar w/ exult, all I personally would need is the file it’s
contained in an /maybe/ the line number… though I’m sure there would be
others on the list that would be interrested in more :wink:

it’s in utils.cc, function Switch_slash() (line 51). Make sure to get
the latest CVS, I checked it in yesterday.

You call Switch_slash() a bit similiar to strcpy. Example:

FILE* fopen_portable( const char * fname, const char * mode )
{
char name[512];
Switch_slash(name, fname);
return fopen( name, mode );
}

Of course, make sure the C lib doesn’t already convert path
delimeters on its own :slight_smile:

Also, Switch_slash() is not perfect. It doesn’t handle absolute
pathes (which would be very complicated, considering that DOS/Win,
Unix and MacOS handle this all completly different).

bye,

max


Max “The Black Fingolfin” Horn
mailto:Max_Horn
http://www.quendi.de - please use my guestbook!