summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Stiborsky <martin.stiborsky@gmail.com>2015-01-05 19:54:48 +0100
committerMartin Stiborsky <martin.stiborsky@gmail.com>2015-01-05 19:54:48 +0100
commit7d52029ae3a8bb21951106fe8e3e88156a57859b (patch)
tree19e7294ef85f340a45f89e45e23cc5b3a8f904cc
parenta3839aa69f643c34022dc456368126fe17b036fb (diff)
removed the whoami function, replaced with an inline getpwuid call
-rw-r--r--i3lock.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/i3lock.c b/i3lock.c
index fd32f97..bead884 100644
--- a/i3lock.c
+++ b/i3lock.c
@@ -9,6 +9,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>
+#include <sys/types.h>
#include <string.h>
#include <unistd.h>
#include <stdbool.h>
@@ -659,18 +660,8 @@ static void raise_loop(xcb_window_t window) {
}
}
-char* whoami(void) {
- uid_t uid = geteuid();
- struct passwd *pw = getpwuid(uid);
- if (pw) {
- return pw->pw_name;
- } else {
- errx(EXIT_FAILURE, "Username not known!\n");
- }
-}
-
int main(int argc, char *argv[]) {
- char *username = whoami();
+ char *username = getpwuid(getuid())->pw_name;
char *image_path = NULL;
int ret;
struct pam_conv conv = {conv_callback, NULL};
@@ -695,6 +686,9 @@ int main(int argc, char *argv[]) {
{NULL, no_argument, NULL, 0}
};
+ if (username == NULL)
+ err(EXIT_FAILURE, "getpwuid() failed");
+
char *optstring = "hvnbdc:p:ui:teI:f";
while ((o = getopt_long(argc, argv, optstring, longopts, &optind)) != -1) {
switch (o) {