summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2019-12-29 20:39:04 -0700
committerAaron Ball <nullspoon@oper.io>2019-12-29 20:39:04 -0700
commit303564d281e2bb476a5813eca4fc478874013c7c (patch)
tree9a754f7f5652371985b0e3145bb659d62136012f
parentc6f67b23e5996216ca30afb27baa914d32679005 (diff)
downloadterminus-303564d281e2bb476a5813eca4fc478874013c7c.tar.gz
terminus-303564d281e2bb476a5813eca4fc478874013c7c.tar.xz
Simplify get user home code
Previously there was a function for this (get_user_home: *sigh*). Now we just check if the getenv for HOME returns a null pointer and save double copying into a buffer.
-rw-r--r--src/main.c23
1 files changed, 6 insertions, 17 deletions
diff --git a/src/main.c b/src/main.c
index 9640ed8..4201592 100644
--- a/src/main.c
+++ b/src/main.c
@@ -59,19 +59,6 @@ long days_to_seconds(int days) {
/**
- * TODO
- */
-int get_user_home(char* out) {
- if(getenv("HOME") != NULL) {
- strcpy(out, getenv("HOME"));
- return 0;
- } else {
- return 1;
- }
-}
-
-
-/**
* Writes the current timestamp to the specified lastlogin file
*
* @param path Path to the lastlogin file
@@ -152,7 +139,6 @@ int exec_cmd(char* cmd) {
* Ye olde main function
*/
int main(int argc, char* argv[]) {
- char home[128];
int days;
char* cmd;
// Expected path to lastlogin file
@@ -167,10 +153,13 @@ int main(int argc, char* argv[]) {
return 1;
}
-
// Compose path to lastlogin file
- get_user_home(home);
- strcpy(lastlogin_path, home);
+ if(getenv("HOME")) {
+ strcpy(lastlogin_path, getenv("HOME"));
+ } else {
+ printf("ERROR: HOME is unset\n");
+ return 1;
+ }
strcat(lastlogin_path, "/.lastlogin");
// Parse program arguments

Generated by cgit