Fix #133 and don't throw an error if $HOME,$SHELL or $USER aren't set.

This commit is contained in:
Joshix-1 2021-10-02 22:34:37 +02:00
parent 50cc6b66f9
commit a576673bb8

View file

@ -184,13 +184,13 @@ int main(int argc, char *argv[])
void parse_config() void parse_config()
{ {
char line[256]; char line[256];
char homedir[64]; char *homedir = getenv("HOME");
sprintf(homedir, "%s", getenv("HOME"));
// opening and reading the config file // opening and reading the config file
FILE *config; FILE *config;
if (config_directory == NULL) if (config_directory == NULL)
config = fopen(strcat(homedir, "/.config/uwufetch/config"), "r"); if (homedir != NULL)
config = fopen(strcat(homedir, "/.config/uwufetch/config"), "r");
else else
config = fopen(config_directory, "r"); config = fopen(config_directory, "r");
if (config == NULL) if (config == NULL)
@ -479,7 +479,11 @@ void get_info()
if (sscanf(line, "model name : %[^\n]", cpu_model)) if (sscanf(line, "model name : %[^\n]", cpu_model))
#endif #endif
break; break;
sprintf(user, "%s", getenv("USER")); char *tmp_user = getenv("USER");
if (tmp_user == NULL)
sprintf(user, "%s", "");
else
sprintf(user, "%s", tmp_user);
if (iscygwin == 0) if (iscygwin == 0)
fclose(os_release); fclose(os_release);
} }
@ -525,7 +529,11 @@ void get_info()
fclose(cpuinfo); fclose(cpuinfo);
#endif #endif
gethostname(host, 256); gethostname(host, 256);
sprintf(shell, "%s", getenv("SHELL")); char *tmp_shell = getenv("SHELL");
if (tmp_shell == NULL)
sprintf(shell, "%s", "");
else
sprintf(shell, "%s", tmp_shell);
if (strlen(shell) > 16) if (strlen(shell) > 16)
memmove(&shell, &shell[27], strlen(shell)); // android shell was too long, this works only for termux memmove(&shell, &shell[27], strlen(shell)); // android shell was too long, this works only for termux