Re: Strange fopen error



On May 7, 9:24 am, mayoneez <mikko.oksala...@xxxxxx> 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.
.



Relevant Pages

  • Re: Strange fopen error
    ... First time I open the file with fopen, it succeeds. ...   if{ ... framework changes the current working directory and that's why the ... I guess it's the glfw lib that changes the working directory. ...
    (comp.sys.mac.programmer.help)
  • Re: GRACE WAS A REALITY ONCE..DONT MISS THIS ONE..!
    ... 400 words on your hope for the Obama presidency, ... aisle who have caved and who say, "Well, I hope he succeeds. ... what is unfair about my saying I hope liberalism fails? ... Liberalism is our problem. ...
    (alt.vacation.las-vegas)
  • Re: .Net (C#) Service Fails To Start
    ... Interesting technique - but when my code fails, it does not seem to even get that far, and when it succeeds, I have no need to debug it, and I cannot predict when it will fail. ... I checked and there are no dependencies marked for the service. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: renaming a table
    ... > if it succeeds, truncate all rows in your target rable, copy the inbox rows ... If I do that and the download fails for some reason, ...
    (microsoft.public.sqlserver.ce)
  • Re: [PATCH 05/11] sysfs: sysfs_chmod_file handle multiple superblocks
    ... instead of failing half way through but given the interface of ... The latter never fails and the former should always ... succeed if inode_change_oksucceeds never fails ... struct iattr * sd_iattr; ...
    (Linux-Kernel)