This is an archive of the discontinued LLVM Phabricator instance.

Introduce getenv to LLVM libc
ClosedPublic

Authored by rtenneti on Feb 9 2022, 7:22 PM.

Details

Summary

Add support for getenv as defined by the Open Group's "System Interface &
Header" in https://pubs.opengroup.org/onlinepubs/7908799/xsh/getenv.html

getenv requires a standard way of accessing the environment,
so a pointer to the environment is added to the startup in crt1.
Consquently, this function is not usable on top of other libcs.

Added starts_with method to StringView. getenv function uses it.

Co-authored-by: Jeff Bailey <jeffbailey@google.com>

Diff Detail

Event Timeline

rtenneti created this revision.Feb 9 2022, 7:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 9 2022, 7:22 PM
rtenneti requested review of this revision.Feb 9 2022, 7:22 PM

Overall LGTM but I will make a fine grained pass in a day and get back to you. Thanks for working on this.

rtenneti updated this revision to Diff 407597.Feb 10 2022, 10:19 AM

Added Stdlib to posix.td to fix integration tests.
Added few more test cases.

sivachandra accepted this revision.Feb 12 2022, 12:47 AM
sivachandra added inline comments.
libc/loader/linux/x86_64/start.cpp
31–32

Nit: Now that you have declared app as an extern, we can remove this TODO.

libc/src/stdlib/getenv.cpp
33

Nit: I didn't understand this comment.

This revision is now accepted and ready to land.Feb 12 2022, 12:47 AM
jeffbailey added inline comments.Feb 12 2022, 8:09 AM
libc/src/stdlib/getenv.cpp
33

This comment was my reminder to myself that starts_with could match stems as well as entire variables and that I needed to make sure that the equals sign came next.

rtenneti updated this revision to Diff 408307.Feb 13 2022, 5:59 PM
rtenneti marked 3 inline comments as done.

Fixed comments.

rtenneti updated this revision to Diff 408308.Feb 13 2022, 6:05 PM

Fixed comments.

rtenneti updated this revision to Diff 408309.Feb 13 2022, 6:08 PM

Fixed comments.

Fixed comments

rtenneti accepted this revision.Feb 13 2022, 7:07 PM
This revision was automatically updated to reflect the committed changes.