Mercurial > hg > nnchat
comparison main.c @ 621:29b8ff5b625b
Use th_get_error() and th_error_str().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 27 May 2014 07:27:14 +0300 |
parents | a1abf812785f |
children | bb6b07b44800 |
comparison
equal
deleted
inserted
replaced
620:a1abf812785f | 621:29b8ff5b625b |
---|---|
6 #include "util.h" | 6 #include "util.h" |
7 #include "network.h" | 7 #include "network.h" |
8 #include "ui.h" | 8 #include "ui.h" |
9 #include "th_args.h" | 9 #include "th_args.h" |
10 #include "th_config.h" | 10 #include "th_config.h" |
11 #include <errno.h> | |
12 #include <unistd.h> | 11 #include <unistd.h> |
13 #include <fcntl.h> | 12 #include <fcntl.h> |
14 #ifdef __WIN32 | 13 #ifdef __WIN32 |
15 #include <shlwapi.h> | 14 #include <shlwapi.h> |
16 #include <shfolder.h> | 15 #include <shfolder.h> |
877 int fds[2]; | 876 int fds[2]; |
878 pid_t pid; | 877 pid_t pid; |
879 | 878 |
880 if (pipe(fds) == -1) | 879 if (pipe(fds) == -1) |
881 { | 880 { |
882 int ret = errno; | 881 int ret = th_get_error(); |
883 printMsgQ(currWin, "Could not open process communication pipe! (%d, %s)\n", ret, strerror(ret)); | 882 printMsgQ(currWin, "Could not open process communication pipe! (%d, %s)\n", |
883 ret, th_error_str(ret)); | |
884 return 0; | 884 return 0; |
885 } | 885 } |
886 | 886 |
887 if ((pid = fork()) < 0) | 887 if ((pid = fork()) < 0) |
888 { | 888 { |
893 dup2(fds[1], STDOUT_FILENO); | 893 dup2(fds[1], STDOUT_FILENO); |
894 dup2(fds[0], STDERR_FILENO); | 894 dup2(fds[0], STDERR_FILENO); |
895 char *url = th_strdup_printf("openurl(%s,new-tab)", uri); | 895 char *url = th_strdup_printf("openurl(%s,new-tab)", uri); |
896 execlp(setBrowser, setBrowser, "-remote", url, (void *)NULL); | 896 execlp(setBrowser, setBrowser, "-remote", url, (void *)NULL); |
897 th_free(url); | 897 th_free(url); |
898 _exit(errno); | 898 _exit(th_get_error()); |
899 } | 899 } |
900 | 900 |
901 wait(&status); | 901 wait(&status); |
902 #endif | 902 #endif |
903 | 903 |
1200 #else | 1200 #else |
1201 if ((cfgfd = open(setConfigFile, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR)) == -1 || | 1201 if ((cfgfd = open(setConfigFile, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR)) == -1 || |
1202 (ctx.fp = fdopen(cfgfd, "w")) == NULL) | 1202 (ctx.fp = fdopen(cfgfd, "w")) == NULL) |
1203 #endif | 1203 #endif |
1204 { | 1204 { |
1205 int err = th_get_error(); | |
1205 printMsgQ(currWin, "Could not create configuration to file '%s', %d: %s\n", | 1206 printMsgQ(currWin, "Could not create configuration to file '%s', %d: %s\n", |
1206 setConfigFile, errno, strerror(errno)); | 1207 setConfigFile, err, th_error_str(err)); |
1207 goto error; | 1208 goto error; |
1208 } | 1209 } |
1209 | 1210 |
1210 printMsgQ(currWin, "Configuration saved in file '%s', res=%d\n", | 1211 printMsgQ(currWin, "Configuration saved in file '%s', res=%d\n", |
1211 setConfigFile, th_cfg_write(&ctx, cfg)); | 1212 setConfigFile, th_cfg_write(&ctx, cfg)); |
1810 #else | 1811 #else |
1811 if ((logFd = open(win->logFilename, O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR)) == -1 || | 1812 if ((logFd = open(win->logFilename, O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR)) == -1 || |
1812 (win->logFile = fdopen(logFd, "a")) == NULL) | 1813 (win->logFile = fdopen(logFd, "a")) == NULL) |
1813 #endif | 1814 #endif |
1814 { | 1815 { |
1816 int err = th_get_error(); | |
1815 errorMsg("Could not open logfile '%s' for appending, %d: %s\n", | 1817 errorMsg("Could not open logfile '%s' for appending, %d: %s\n", |
1816 win->logFilename, errno, strerror(errno)); | 1818 win->logFilename, err, th_error_str(err)); |
1817 goto error; | 1819 goto error; |
1818 } | 1820 } |
1819 | 1821 |
1820 printMsg(win, "Logging to '%s'.\n", win->logFilename); | 1822 printMsg(win, "Logging to '%s'.\n", win->logFilename); |
1821 | 1823 |