0

I'm using Visual Studio and I'm connected to my Linux machine using remote development (https://learn.microsoft.com/en-us/cpp/linux/connect-to-your-remote-linux-computer?view=msvc-170). I'm trying to call the stat() function to find if a file exists, but it can never find it. I believe this is because; in the documentation for stat(), it says

If you are accessing a remote file through the Network File System, update operations to file permissions at the server are not reflected at the client until updates to data that is stored locally by the Network File System take place. (Several options on the Add Mounted File System (ADDMFS) command determine the time between refresh operations of local data.) Access to a remote file may also fail due to different mappings of user IDs (UID) or group IDs (GID) on the local and remote systems.

Is there a way to fix this? I'm wondering if there is a way to specify a remote file path though visual studio or something?

Katianie
  • 589
  • 1
  • 9
  • 38
  • There's a function called `access`, you could try that. – Paul Sanders Aug 01 '23 at 23:15
  • 2
    @PaulSanders I'm sure you will find that the C library function `access()` calls the system call `stat()` under the hood. – user207421 Aug 01 '23 at 23:38
  • On which machine are you calling `stat`? – Davis Herring Aug 01 '23 at 23:47
  • @DavisHerring Please look at the link, I'm doing remote development and the files are on the linux machine, I dont know how else to say it. – Katianie Aug 02 '23 at 13:03
  • @Katianie: Wait, you said both things: “calling stat on my PC” and “executing the program on my linux pc”. Those can’t both be true for any one execution; the link implies it’s the latter, but then if the file is also on the target machine why would you need a remote filename? – Davis Herring Aug 02 '23 at 13:15
  • @DavisHerring Ok I deleted the comment that confused you. Go with the link and what I wrote and how Paul understood it. I don't know how else to spell it out. – Katianie Aug 02 '23 at 13:24

1 Answers1

0

If your program is being built on the remote machine, presumably it is also being run there (unless you are also doing cross-compilation, which is a very different thing). You therefore do not need any special syntax to refer to files on that machine (which is remote for your editor but not your process).

You still have to worry about the usual questions like case-sensitivity and your current working directory (for the process, not the editor); the bit in the documentation you found is about network filesystems mounted by the target machine.

Davis Herring
  • 36,443
  • 4
  • 48
  • 76
  • Thanks again for the help. I'm almost 100% sure I'm calling stat the correct way stat("~/testfiles/test.txt", &buffer); but it always returns error. – Katianie Aug 02 '23 at 14:23
  • @Katianie: And there’s [the question](https://stackoverflow.com/q/15991241/8586227) I was (unknowingly) trying to get you to ask. – Davis Herring Aug 02 '23 at 16:27
  • Yea looks like a call to chdir("/home/"); before calling stat("/home/ed/testfiles/test.txt", &buffer) fixes the issue. Thanks again for the help. – Katianie Aug 02 '23 at 16:52
  • @Katianie: The `chdir` there doesn’t do anything for the `stat`, which is already using an absolute filename, but good. – Davis Herring Aug 02 '23 at 20:20