Talk About Network

Google





Mac > Mac Programmer Help > Re: Strange fop...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 4 Topic 3734 of 3889
Post > Topic >>

Re: Strange fopen error

by mayoneez <mikko.oksalahti@[EMAIL PROTECTED] > May 8, 2008 at 03:33 AM

On 7 touko, 14:37, Gregory Weston <u...@[EMAIL PROTECTED]
> wrote:
> In article
> <4153d0be-e4f8-4ec9-bdb6-13a924427...@[EMAIL PROTECTED]
>,
>
>
>
>  mayoneez <mikko.oksala...@[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

Thanks. That's a good advice.
 




 4 Posts in Topic:
Strange fopen error
mayoneez <mikko.oksala  2008-05-06 23:24:28 
Re: Strange fopen error
mayoneez <mikko.oksala  2008-05-06 23:49:03 
Re: Strange fopen error
Gregory Weston <uce@[E  2008-05-07 07:37:13 
Re: Strange fopen error
mayoneez <mikko.oksala  2008-05-08 03:33:02 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Wed Jan 7 18:44:21 PST 2009.