Merge pull request #136 from Joshix-1/fix-for-missing-envvars
Fix #133 and don't throw an error if $HOME,$SHELL or $USER aren't set.
This commit is contained in:
commit
ae793ea029
1 changed files with 13 additions and 5 deletions
16
uwufetch.c
16
uwufetch.c
|
@ -184,12 +184,12 @@ 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)
|
||||||
|
if (homedir != NULL)
|
||||||
config = fopen(strcat(homedir, "/.config/uwufetch/config"), "r");
|
config = fopen(strcat(homedir, "/.config/uwufetch/config"), "r");
|
||||||
else
|
else
|
||||||
config = fopen(config_directory, "r");
|
config = fopen(config_directory, "r");
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue