1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-07-05 08:06:44 +02:00

made error handling more consistent and added exit function

This commit is contained in:
Jfreegman
2013-09-11 00:02:27 -04:00
parent 2e84836f8c
commit 40dcfc82d2
6 changed files with 21 additions and 23 deletions

View File

@ -60,9 +60,9 @@ static void init_term()
signal(SIGWINCH, on_window_resize);
#if HAVE_WIDECHAR
if (setlocale(LC_ALL, "") == NULL) {
printf("Could not set your locale, plese check your locale settings or"
fprintf(stderr, "Could not set your locale, plese check your locale settings or"
"disable wide char support\n");
exit(1);
exit(EXIT_FAILURE);
}
#endif
initscr();
@ -91,7 +91,7 @@ static Tox *init_tox()
{
/* Init core */
Tox *m = tox_new();
if (!m)
if (m == NULL)
return NULL;
/* Callbacks */
@ -184,7 +184,7 @@ int init_connection(Tox *m)
fp = fopen(SRVLIST_FILE, "r");
if (!fp)
if (fp == NULL)
return 1;
char servers[MAXSERVERS][MAXLINE];
@ -208,7 +208,7 @@ int init_connection(Tox *m)
char *port = strtok(NULL, " ");
char *key = strtok(NULL, " ");
if (!ip || !port || !key)
if (ip == NULL || port == NULL || key == NULL)
return 3;
tox_IP_Port dht;
@ -320,7 +320,7 @@ static void load_data(Tox *m, char *path)
fprintf(stderr, "malloc() failed.\n");
fclose(fd);
endwin();
exit(1);
exit(EXIT_FAILURE);
}
if (fread(buf, len, 1, fd) != 1) {
@ -328,7 +328,7 @@ static void load_data(Tox *m, char *path)
free(buf);
fclose(fd);
endwin();
exit(1);
exit(EXIT_FAILURE);
}
tox_load(m, buf, len);
@ -349,7 +349,7 @@ static void load_data(Tox *m, char *path)
if ((st = store_data(m, path)) != 0) {
fprintf(stderr, "Store messenger failed with return code: %d\n", st);
endwin();
exit(1);
exit(EXIT_FAILURE);
}
}
}
@ -405,10 +405,11 @@ int main(int argc, char *argv[])
init_term();
Tox *m = init_tox();
if (!m) {
if (m == NULL) {
endwin();
fprintf(stderr, "Failed to initialize network. Aborting...\n");
exit(1);
exit(EXIT_FAILURE);
}
prompt = init_windows(m);