There is a small problem with the C Open () system call in connection with the file path on Linux (Ubuntu).
If I open the full path ("/ home / bob / desktop / folder / file", O_RDONL); It opens upright
But say that if I run my program on other program then the file path is not correct i.e. username can not be Bob
So, when I try to open Am ("./desktop / folder / file", O_RDONLY); File opened, this is the right way. I know (~ /) should not work, but not sure why (./) why not?
Any suggestions please?
Thanks,
when You can use the "./desktop/folder/file ", then it starts lookup in the current working directory. Therefore it depends on the directory in which the program is started. So if the current working directory is not
$ HOME then the path will not be the same as
~ / desktop / folder / file .
getenv function to get the value of the
home environment variable, and then create the full path.
char * home = getenv ("home"); If (house == faucet) goto error; Four * path = "/ desktop / folder / file" size_t len = strlen (home) + strlen (path) + 1; Four * full path = mall; If (full path == faucet) goto error; Streakpie (full path, house); Dome (full path, path); Int FD = Open (Full Path, Oardoneley); Freepath;
Comments
Post a Comment