This is an archive of the discontinued LLVM Phabricator instance.

LLDB - Simplify GetProgramFileSpec
ClosedPublic

Authored by devnexen on May 7 2018, 4:00 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

devnexen created this revision.May 7 2018, 4:00 AM

I think the new version may actually be wrong. Shouldn't it be PATH_MAX+1? That said, what's the motivation for changing this?

I think the new version may actually be wrong. Shouldn't it be PATH_MAX+1? That said, what's the motivation for changing this?

I actually think PATH_MAX/MAXPATHLEN is correct. Otherwise it s just simplifying it.

I don't personally know, but the one example I came across online is using +1.

https://common-lisp.net/~alendvai/darcs/sbcl/src/runtime/bsd-os.c

Search the page for the function os_get_runtime_executable_path. Let's see what @emaste has to say.

emaste added a comment.Sep 9 2019, 6:28 AM

From sysctl_kern_proc_pathname:

error = vn_fullpath(req->td, vp, &retbuf, &freebuf);
vrele(vp);
if (error)
        return (error);
error = SYSCTL_OUT(req, retbuf, strlen(retbuf) + 1);

and in vn_fullpath:

buf = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);

So the pathname, including the '\0' fits in MAXPATHLEN/PATH_MAX.

Herald added a project: Restricted Project. · View Herald TranscriptSep 9 2019, 6:28 AM
emaste accepted this revision.Sep 9 2019, 6:29 AM

This is fine with me as a little simplification and avoid an extra syscall.

This revision is now accepted and ready to land.Sep 9 2019, 6:29 AM
This revision was automatically updated to reflect the committed changes.