In article
<4153d0be-e4f8-4ec9-bdb6-13a924427e63@[EMAIL PROTECTED]
>,
mayoneez <mikko.oksalahti@[EMAIL PROTECTED]
> wrote:
> On May 7, 9:24 am, 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 == 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:
> >
> > char filename[256];
> > sprintf(filename, "./level%d.txt", m current level + 1);
> > FILE* fp = fopen(filename, "r");
> > if(fp) {
> > ...
> > fclose(fp);
> > }
> >
> > 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.
Never make any assumption about the current working directory. It
doesn't matter which framework changed it in your specific case today
because there's absolutely no guarantee that it will ever be a
predictable value at launch time.
--
"Harry?" Ron's voice was a mere whisper. "Do you smell something ...
burning?"
- Harry Potter and the Odor of the Phoenix


|