API change...

Ryan C. Gordon icculus at clutteredmind.org
Sun Sep 18 17:47:00 EDT 2005

Having to eat your own dogfood really teaches you some good lessons.

The new file enumeration callback API in the development branch has 
changed slightly.

You used to do this:

void mycallback(void *data, const char *filename)
     MyObj *myobj = (MyObj *) data;
     myobj->printf("The file %s is in this enumeration.\n", filename);

PHYSFS_enumerateFilesCallback("/dir/to/enumerate", mycallback, myobj);

This worked fine for very basic enumerations, but frequently you'd need 
to know the directory being enumerated in the callback...the (filename) 
parameter in the callback doesn't contain any path info.

So you'd have to do all this nastiness:

typedef struct
    MyObj *myobj;
    const char *origpath;
} FileCallbackData;

void mycallback(void *data, const char *filename)
     FileCallbackData *fcbd = (FileCallbackData *) data;
     MyObj *myobj = fcbd->myobj;
     const char *origpath = fcbd->origpath;
     myobj->printf("The file %s is in %s.\n", filename, origpath);

const char *dirname = "/dir/to/enumerate";
FileCallbackData fcbd = { myobj, dirname };
PHYSFS_enumerateFilesCallback(dirname, mycallback, &fcbd);

Having to pass all this around is silly, because physfs could do that 
for you.

So now the callback signature is:

void callback(void *data, const char *origdir, const char *filename);

So you do this:

void mycallback(void *data, const char *origdir, const char *filename)
     MyObj *myobj = (MyObj *) data;
     myobj->printf("The file %s is in %s.\n", filename, origdir);

PHYSFS_enumerateFilesCallback("/dir/to/enumerate", mycallback, myobj);

The call to PHYSFS_enumerateFilesCallback() is identical at the source 
level, it's just the callback itself that has changed. Any programs 
using this API can just add the extra param to their callback and ignore 
it to keep existing functionality.

And, usual disclaimers: these new APIs are breaking now, but won't once 
the development branch stabilizes.

This is in subversion now, revision #769. The stable 1.0 branch hasn't 


More information about the physfs mailing list