On May 7, 9:24=A0am, mayoneez <mikko.oksala...@[EMAIL PROTECTED]
> wrote:
> I have a Carbon application and am experiencing a strange error with
> fopen.
>
> First time I open the file with fopen, it succeeds. I then close the
> file with fclose.
>
> But when I try to open the same file the second time (using the same
> code), it fails with errno =3D=3D 2. Also, if I try to open a different
> file, it fails. Only the first fopen succeeds.
>
> Any ideas? Here's the relevant code fragment:
>
> =A0 char filename[256];
> =A0 sprintf(filename, "./level%d.txt", m_current_level + 1);
> =A0 FILE* fp =3D fopen(filename, "r");
> =A0 if(fp) {
> =A0 =A0 ...
> =A0 =A0 fclose(fp);
> =A0 }
>
> I've debugged and filename is correct on the second time, as well.
>
> Using Xcode 3.1 (beta), linking with frameworks libglfw.a,
> Carbon.framework, OpenGL.framework, AGL.framework.
Okay. If I use a full path to the file(s), the fopen works all the
time. The reason the first open worked was because that was called
from a constructor of an object that was global. After that some lib/
framework changes the current working directory and that's why the
successive tries to open the files fail, since they are called later
in the execution of the program.
I guess it's the glfw lib that changes the working directory. I can't
believe Carbon or OpenGL would do that.


|