mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 14:05:08 +00:00
LibC: Change putenv (and getenv) to not copy, but directly return the environ values.
This is in keeping with how putenv should function. It does mean that the shell's export command now leaks, but that's not a difficult fix. Contributes to #29.
This commit is contained in:
parent
c5434e0cfa
commit
b2dd12daac
4 changed files with 59 additions and 47 deletions
|
@ -70,7 +70,13 @@ static int sh_export(int argc, char** argv)
|
|||
fprintf(stderr, "usage: export variable=value\n");
|
||||
return 1;
|
||||
}
|
||||
putenv(const_cast<char*>(String::format("%s=%s", parts[0].characters(), parts[1].characters()).characters()));
|
||||
|
||||
// FIXME: Yes, this leaks.
|
||||
// Maybe LibCore should grow a CEnvironment which is secretly a map to char*,
|
||||
// so it can keep track of the environment pointers as needed?
|
||||
const auto& s = String::format("%s=%s", parts[0].characters(), parts[1].characters());
|
||||
char *ev = strndup(s.characters(), s.length());
|
||||
putenv(ev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -408,7 +414,9 @@ int main(int argc, char** argv)
|
|||
if (pw) {
|
||||
g.username = pw->pw_name;
|
||||
g.home = pw->pw_dir;
|
||||
putenv(const_cast<char*>(String::format("HOME=%s", pw->pw_dir).characters()));
|
||||
const auto& s = String::format("HOME=%s", pw->pw_dir);
|
||||
char *ev = strndup(s.characters(), s.length());
|
||||
putenv(ev);
|
||||
}
|
||||
endpwent();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue