summaryrefslogtreecommitdiffstats
path: root/htop.c
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-09-12 18:11:58 +0200
committercgzones <cgzones@googlemail.com>2020-09-17 21:55:26 +0200
commit1f5bd5c4c84c53915bcdd68398e77269fe26328c (patch)
tree6dbaa01abab77cea6b614cf6dd65a422e8ca54b5 /htop.c
parent5d4061732f25863d78cca06968cd938ae468b8bf (diff)
Avoid modifying optarg
It might be working, but lets rather not modify getopt's global variable `optarg`. Also there is no need to call `getenv("USER")`, just use `geteuid()`.
Diffstat (limited to 'htop.c')
-rw-r--r--htop.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/htop.c b/htop.c
index 2cf2602e..79526b88 100644
--- a/htop.c
+++ b/htop.c
@@ -131,21 +131,21 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
}
break;
case 'u':
- if (!optarg && optind < argc && argv[optind] != NULL &&
+ {
+ const char *username = optarg;
+ if (!username && optind < argc && argv[optind] != NULL &&
(argv[optind][0] != '\0' && argv[optind][0] != '-')) {
- optarg = argv[optind++];
+ username = argv[optind++];
}
- if (!optarg) {
- optarg = getenv("USER");
+ if (!username) {
flags.userId = geteuid();
- }
-
- if (!Action_setUserOnly(optarg, &(flags.userId))) {
- fprintf(stderr, "Error: invalid user \"%s\".\n", optarg);
+ } else if (!Action_setUserOnly(username, &(flags.userId))) {
+ fprintf(stderr, "Error: invalid user \"%s\".\n", username);
exit(1);
}
break;
+ }
case 'C':
flags.useColors = false;
break;

© 2014-2024 Faster IT GmbH | imprint | privacy policy