When calling the getcwd (Ubuntu 16.04 OS, gcc 5.4), an error occurs indicating that the executable file is not associated with any directory - the error code is 2 ENOENT . In the context of calling this function, it should be interpreted as:

The current working directory has been unlinked

which I, in fact, said above.

Sketched a separate program, where this function is called - it works correctly, and the output is the result corresponding to the current directory. From this I conclude that in the program where I decided to apply this function there are some factors that influence its execution. What tell me?

For example, in the code oriented under the Nix (cross-platform application), when starting, close the streams:

 fclose(stdin); fclose(stdout); fclose(stderr); 

Can not these actions become the very reason why getcwd does not work the way I expect?

  • actually the answer is simply, someone deleted the directory that the application considers the current working directory. - KoVadim
  • @KoVadim, and if I probably know that no one deleted it? - isnullxbh
  • @KoVadim, or perhaps some temporary-catalogs come into play? In general, thank you, thought put it) - isnullxbh
  • 2
    OK, I think you know that the current working directory is not permanent enough. For example, under Windows it is very easy to change it, just open the "open dialog", go to another directory and close by cancel / cross. It seems that nothing has changed, but everything ... by the way, you can look at ls -al /proc/<pid>/cwd - KoVadim
  • @KoVadim, thank you, useful advice) - isnullxbh

0