c - How to get the absolute path of a file programmatically with out realpath() under linux? -
I know that it is possible to get a full path of the file with the realpath () function. However, according to the Buj section, the manpage, there are some problems in its implementation. The details are as follows:
BUGS
Avoid using this function. It is broken by design since then (unless non-standard solutions are used) Do not use the null attribute, it is impossible to determine the appropriate size for the output buffer, resolved_path. According to POSIX, the size buffer PATH_MAX is adequate, but PATH_MAX should not be defined deficient, and must be achieved using path conf (3). And asking the path conf (3) does not really help, because on one side POSIX warns that the result of path config (3) may be large and inappropriate for the modolding modulation. And on the other side, for the path conf (3) 1- can indicate that PATH_MAX is not bound.
There is a buffer overflow in libc4 and libc5 implementation (fixed in libc-5.4.13). In this way, set-user-id programs such as Mount (8) require a personalized version.
So, the question is what is the best practice to get the full path of the file?
I know this question is outdated, but I do not get any answers that address the main issue Are: Man page OP refers to incorrect and out-of-date, for at least two reasons.
One is that Posix 2008 is the added / mandatory support for the NULL
logic option, by which realpath
allocates the string to you Programs using this feature will be portable for all relevant versions of GNU / Linux, perhaps most other modern systems, and some posics will be in line with 2008.
The second reason is man page incorrect If you care about the maximum portability, then the best way to use the mixture of both methods is best. See POSIX document for details: If I am defined as PATH_MAX
. It is purely GNU religious ideology against "arbitrary boundaries". In the real world, if the length of the path is not limited to the length of the name, it can add all kinds of paths for misuse / dose, many such cases of failure that can not otherwise fail, and only realpath
PATH_MAX
, and otherwise zero
. It starts covering all the cases, but you can check out earlier versions of POSIX to see if what PATH_MAX
is not defined, what to do for it.
Comments
Post a Comment