First of all, it fails in the middle of the code in an so it's not working directory. However, that is what I am looking for: reasonable hypotheses as to
why the same code might fail in XCode and not X11. Forget the code. The code is propriety information; I am not allow to send it out. I don't want you to debug it; if I really want it to run in XCode I will debug it I just want some thoughts on the matter.
Things that might differ:
1. working directory.
2. environment variables.
3. standard input stream (stdin).
4. standard output streams (stdout or stderr).
5. process group (i.e. the "controlling terminal" paradigm)
6. signal disposition (disabled signal inheritance)
7. 64-bit vs. 32-bit runtime arch
8. real & effective user/group id (unlikely, IMHO)
9. file-creation mask (umask)
Most of these things are accessible to C programs for self-inspection. That is, you can write C code that prints them out, so you can see what differs.
I'm not sure how to get a path from a FILE* or a filedes, so I don't know about self-inspection of stdio streams. However, see 'man lsof' for how to see another cmd's open filedes's.
1. man getcwd
2. man getenv
3. man lsof (use 'lsof' to get info on other cmd)
4. man lsof
5. man getppid, man getpgid
6. man sigaction
7. sizeof(void*)
8. man geteuid, man getegid
9, man umask
Also see man execve for other things that are inherited by the new process executable. You might see something there that you can also self-inspect and verify. My 1-9 list is basically a summary of what execve tells you.
And you still haven't said what fails. For all anyone knows, you're simply overrunning a buffer somewhere, and it's failing in a different way in the different environments. It could be a fatal malfunction in Xcode for some reason (e.g. any of reasons 1-9 above), yet a non-fatal malfunction in Terminal or X11 terminal. Or perhaps not really a non-fatal malfunction, but a not-yet-fatal malfunction.
Oh, and you could run your program under gdb in the terminal, just so you can mess around with some of the environmental settings. Who knows, maybe it's the fact that you're running under the debugger in Xcode (assuming you are, which is no worse an assumption than all the others made so far).