[A5] Filesystem - al_make_directory
wiseguy

Wasn't going to create a new post for this but then I thought since it was a different topic I probably should:

I wanted to drop a note about something I noticed tonight when I was working. There is an inconsistency with the documentation and the actual way the libary works in the filesystem code.

According to both the manual on A.cc and at docs.liballeg.org, al_make_directory should:

Quote:

Creates a new directory on the filesystem. This function also creates any parent directories as needed.

Returns true on success (including if the directory already exists), otherwise returns false on error. Fills in Allegro's errno to indicate the error.

However, the following code shows that if the directory already exists, the function will return false rather than true. This caused me quite some trouble today before I actually thought of testing for the true return value. Was this changed a while back?

  returnValue = al_make_directory("monsters");

I was using this code to return false on a file saving routine:

if (!al_make_directory("monsters")
 return false;

After finding out about the true return values, I had to change that code to this:

al_change_directory("data");
if (!al_change_directory("monsters")
 al_make_directory("monsters");
else
 al_change_directory("..");
al_change_directory("..");

Also, since the data directory already exists, when the monsters directory did not, this command failed every time as well:

al_make_directory("data/monsters");

I assume this is because al_make_directory tries to make the parent directories as well, and since it is returning false because data already exists, it does not create the monsters directory.

Just wanted to mention that in case it wasn't an intentional change.

WG

Peter Wang

Thanks. This was because stat() behaves strangely on Windows and al_make_directory was only tested properly under Wine.

Thread #606195. Printed from Allegro.cc