summaryrefslogtreecommitdiffstats
path: root/src/polypcore
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2006-05-22 15:20:46 +0000
committerPierre Ossman <ossman@cendio.se>2006-05-22 15:20:46 +0000
commit4e3dc7ce68561c16254712d713b2ccd472b8afe7 (patch)
tree2b0494e14605f3f3e133765126eaee3c77c8b482 /src/polypcore
parentbf09399d0e84c43fbae3d24b5c71dc8d85b62fe7 (diff)
Wrap strerror() in a function that makes it thread safe and converts the
output to UTF-8. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@945 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src/polypcore')
-rw-r--r--src/polypcore/authkey.c13
-rw-r--r--src/polypcore/cli-command.c3
-rw-r--r--src/polypcore/conf-parser.c7
-rw-r--r--src/polypcore/core-scache.c5
-rw-r--r--src/polypcore/core-util.c31
-rw-r--r--src/polypcore/iochannel.c3
-rw-r--r--src/polypcore/ioline.c5
-rw-r--r--src/polypcore/log.c3
-rw-r--r--src/polypcore/pid.c25
-rw-r--r--src/polypcore/protocol-esound.c13
-rw-r--r--src/polypcore/protocol-simple.c5
-rw-r--r--src/polypcore/socket-client.c9
-rw-r--r--src/polypcore/socket-server.c35
-rw-r--r--src/polypcore/socket-util.c3
14 files changed, 95 insertions, 65 deletions
diff --git a/src/polypcore/authkey.c b/src/polypcore/authkey.c
index aee54fd4..6b462a23 100644
--- a/src/polypcore/authkey.c
+++ b/src/polypcore/authkey.c
@@ -35,6 +35,7 @@
#include <limits.h>
#include <sys/stat.h>
+#include <polyp/error.h>
#include <polyp/util.h>
#include <polypcore/core-util.h>
#include <polypcore/log.h>
@@ -53,7 +54,7 @@ static int generate(int fd, void *ret_data, size_t length) {
ftruncate(fd, 0);
if ((r = pa_loop_write(fd, ret_data, length)) < 0 || (size_t) r != length) {
- pa_log(__FILE__": failed to write cookie file: %s", strerror(errno));
+ pa_log(__FILE__": failed to write cookie file: %s", pa_cstrerror(errno));
return -1;
}
@@ -75,7 +76,7 @@ static int load(const char *fn, void *data, size_t length) {
if ((fd = open(fn, O_RDWR|O_CREAT|O_BINARY, S_IRUSR|S_IWUSR)) < 0) {
if (errno != EACCES || (fd = open(fn, O_RDONLY|O_BINARY)) < 0) {
- pa_log(__FILE__": failed to open cookie file '%s': %s", fn, strerror(errno));
+ pa_log(__FILE__": failed to open cookie file '%s': %s", fn, pa_cstrerror(errno));
goto finish;
} else
writable = 0;
@@ -84,7 +85,7 @@ static int load(const char *fn, void *data, size_t length) {
unlock = pa_lock_fd(fd, 1) >= 0;
if ((r = pa_loop_read(fd, data, length)) < 0) {
- pa_log(__FILE__": failed to read cookie file '%s': %s", fn, strerror(errno));
+ pa_log(__FILE__": failed to read cookie file '%s': %s", fn, pa_cstrerror(errno));
goto finish;
}
@@ -125,7 +126,7 @@ int pa_authkey_load(const char *path, void *data, size_t length) {
if (ret < 0)
pa_log(__FILE__": Failed to load authorization key '%s': %s", path,
- (ret == -1) ? strerror(errno) : "file corrupt");
+ (ret == -1) ? pa_cstrerror(errno) : "file corrupt");
return ret;
}
@@ -181,14 +182,14 @@ int pa_authkey_save(const char *fn, const void *data, size_t length) {
return -2;
if ((fd = open(p, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR)) < 0) {
- pa_log(__FILE__": failed to open cookie file '%s': %s", fn, strerror(errno));
+ pa_log(__FILE__": failed to open cookie file '%s': %s", fn, pa_cstrerror(errno));
goto finish;
}
unlock = pa_lock_fd(fd, 1) >= 0;
if ((r = pa_loop_write(fd, data, length)) < 0 || (size_t) r != length) {
- pa_log(__FILE__": failed to read cookie file '%s': %s", fn, strerror(errno));
+ pa_log(__FILE__": failed to read cookie file '%s': %s", fn, pa_cstrerror(errno));
goto finish;
}
diff --git a/src/polypcore/cli-command.c b/src/polypcore/cli-command.c
index 3adc9a21..039aa957 100644
--- a/src/polypcore/cli-command.c
+++ b/src/polypcore/cli-command.c
@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <errno.h>
+#include <polyp/error.h>
#include <polyp/xmalloc.h>
#include <polypcore/module.h>
@@ -900,7 +901,7 @@ int pa_cli_command_execute_file(pa_core *c, const char *fn, pa_strbuf *buf, int
assert(c && fn && buf);
if (!(f = fopen(fn, "r"))) {
- pa_strbuf_printf(buf, "open('%s') failed: %s\n", fn, strerror(errno));
+ pa_strbuf_printf(buf, "open('%s') failed: %s\n", fn, pa_cstrerror(errno));
if (!*fail)
ret = 0;
goto fail;
diff --git a/src/polypcore/conf-parser.c b/src/polypcore/conf-parser.c
index bc99b871..4bcb83dd 100644
--- a/src/polypcore/conf-parser.c
+++ b/src/polypcore/conf-parser.c
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <errno.h>
+#include <polyp/error.h>
#include <polyp/xmalloc.h>
#include <polypcore/log.h>
@@ -112,7 +113,8 @@ int pa_config_parse(const char *filename, FILE *f, const pa_config_item *t, void
goto finish;
}
- pa_log(__FILE__": WARNING: failed to open configuration file '%s': %s", filename, strerror(errno));
+ pa_log_warn(__FILE__": WARNING: failed to open configuration file '%s': %s",
+ filename, pa_cstrerror(errno));
goto finish;
}
@@ -122,7 +124,8 @@ int pa_config_parse(const char *filename, FILE *f, const pa_config_item *t, void
if (feof(f))
break;
- pa_log(__FILE__": WARNING: failed to read configuration file '%s': %s", filename, strerror(errno));
+ pa_log_warn(__FILE__": WARNING: failed to read configuration file '%s': %s",
+ filename, pa_cstrerror(errno));
goto finish;
}
diff --git a/src/polypcore/core-scache.c b/src/polypcore/core-scache.c
index 5cb38bee..1d60a910 100644
--- a/src/polypcore/core-scache.c
+++ b/src/polypcore/core-scache.c
@@ -41,6 +41,7 @@
#include <windows.h>
#endif
+#include <polyp/error.h>
#include <polyp/mainloop.h>
#include <polyp/channelmap.h>
#include <polyp/timeval.h>
@@ -359,7 +360,7 @@ static void add_file(pa_core *c, const char *pathname) {
e = pa_path_get_filename(pathname);
if (stat(pathname, &st) < 0) {
- pa_log(__FILE__": stat('%s') failed: %s", pathname, strerror(errno));
+ pa_log(__FILE__": stat('%s'): %s", pathname, pa_cstrerror(errno));
return;
}
@@ -381,7 +382,7 @@ int pa_scache_add_directory_lazy(pa_core *c, const char *pathname) {
/* If that fails, try to open it as shell glob */
if (glob(pathname, GLOB_ERR|GLOB_NOSORT, NULL, &p) < 0) {
- pa_log(__FILE__": Failed to open directory: %s", strerror(errno));
+ pa_log(__FILE__": failed to open directory '%s': %s", pathname, pa_cstrerror(errno));
return -1;
}
diff --git a/src/polypcore/core-util.c b/src/polypcore/core-util.c
index 36044c81..0e7f77a4 100644
--- a/src/polypcore/core-util.c
+++ b/src/polypcore/core-util.c
@@ -69,6 +69,7 @@
#include <samplerate.h>
+#include <polyp/error.h>
#include <polyp/xmalloc.h>
#include <polyp/util.h>
@@ -301,7 +302,7 @@ void pa_check_signal_is_blocked(int sig) {
if (pthread_sigmask(SIG_SETMASK, NULL, &set) < 0) {
#endif
if (sigprocmask(SIG_SETMASK, NULL, &set) < 0) {
- pa_log(__FILE__": sigprocmask() failed: %s", strerror(errno));
+ pa_log(__FILE__": sigprocmask(): %s", pa_cstrerror(errno));
return;
}
#ifdef HAVE_PTHREAD
@@ -314,7 +315,7 @@ void pa_check_signal_is_blocked(int sig) {
/* Check whether the signal is trapped */
if (sigaction(sig, NULL, &sa) < 0) {
- pa_log(__FILE__": sigaction() failed: %s", strerror(errno));
+ pa_log(__FILE__": sigaction(): %s", pa_cstrerror(errno));
return;
}
@@ -396,7 +397,7 @@ void pa_raise_priority(void) {
#ifdef HAVE_SYS_RESOURCE_H
if (setpriority(PRIO_PROCESS, 0, NICE_LEVEL) < 0)
- pa_log_warn(__FILE__": setpriority() failed: %s", strerror(errno));
+ pa_log_warn(__FILE__": setpriority(): %s", pa_cstrerror(errno));
else
pa_log_info(__FILE__": Successfully gained nice level %i.", NICE_LEVEL);
#endif
@@ -406,13 +407,13 @@ void pa_raise_priority(void) {
struct sched_param sp;
if (sched_getparam(0, &sp) < 0) {
- pa_log(__FILE__": sched_getparam() failed: %s", strerror(errno));
+ pa_log(__FILE__": sched_getparam(): %s", pa_cstrerror(errno));
return;
}
sp.sched_priority = 1;
if (sched_setscheduler(0, SCHED_FIFO, &sp) < 0) {
- pa_log_warn(__FILE__": sched_setscheduler() failed: %s", strerror(errno));
+ pa_log_warn(__FILE__": sched_setscheduler(): %s", pa_cstrerror(errno));
return;
}
@@ -563,7 +564,7 @@ static int is_group(gid_t gid, const char *name) {
data = pa_xmalloc(n);
if (getgrgid_r(gid, &group, data, n, &result) < 0 || !result) {
- pa_log(__FILE__ ": getgrgid_r(%u) failed: %s", gid, strerror(errno));
+ pa_log(__FILE__": getgrgid_r(%u): %s", gid, pa_cstrerror(errno));
goto finish;
}
@@ -575,8 +576,8 @@ finish:
/* XXX Not thread-safe, but needed on OSes (e.g. FreeBSD 4.X) that do not
* support getgrgid_r. */
if ((result = getgrgid(gid)) == NULL) {
- pa_log(__FILE__ ": getgrgid(%u) failed: %s", gid, strerror(errno));
- goto finish;
+ pa_log(__FILE__": getgrgid(%u): %s", gid, pa_cstrerror(errno));
+ goto finish;
}
r = strcmp(name, result->gr_name) == 0;
@@ -598,7 +599,7 @@ int pa_own_uid_in_group(const char *name, gid_t *gid) {
gids = pa_xmalloc(sizeof(GETGROUPS_T)*n);
if ((n = getgroups(n, gids)) < 0) {
- pa_log(__FILE__": getgroups() failed: %s", strerror(errno));
+ pa_log(__FILE__": getgroups(): %s", pa_cstrerror(errno));
goto finish;
}
@@ -696,7 +697,8 @@ int pa_lock_fd(int fd, int b) {
return 0;
}
- pa_log(__FILE__": %slock failed: %s", !b ? "un" : "", strerror(errno));
+ pa_log(__FILE__": %slock: %s", !b? "un" : "",
+ pa_cstrerror(errno));
#endif
#ifdef OS_IS_WIN32
@@ -730,7 +732,8 @@ int pa_lock_lockfile(const char *fn) {
struct stat st;
if ((fd = open(fn, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR)) < 0) {
- pa_log(__FILE__": failed to create lock file '%s': %s", fn, strerror(errno));
+ pa_log(__FILE__": failed to create lock file '%s': %s", fn,
+ pa_cstrerror(errno));
goto fail;
}
@@ -777,7 +780,8 @@ int pa_unlock_lockfile(const char *fn, int fd) {
assert(fn && fd >= 0);
if (unlink(fn) < 0) {
- pa_log_warn(__FILE__": WARNING: unable to remove lock file '%s': %s", fn, strerror(errno));
+ pa_log_warn(__FILE__": WARNING: unable to remove lock file '%s': %s",
+ fn, pa_cstrerror(errno));
r = -1;
}
@@ -787,7 +791,8 @@ int pa_unlock_lockfile(const char *fn, int fd) {
}
if (close(fd) < 0) {
- pa_log_warn(__FILE__": WARNING: failed to close lock file '%s': %s", fn, strerror(errno));
+ pa_log_warn(__FILE__": WARNING: failed to close lock file '%s': %s",
+ fn, pa_cstrerror(errno));
r = -1;
}
diff --git a/src/polypcore/iochannel.c b/src/polypcore/iochannel.c
index 10997d62..8af6a36b 100644
--- a/src/polypcore/iochannel.c
+++ b/src/polypcore/iochannel.c
@@ -38,6 +38,7 @@
#include "winsock.h"
+#include <polyp/error.h>
#include <polyp/xmalloc.h>
#include <polypcore/core-util.h>
@@ -253,7 +254,7 @@ int pa_iochannel_creds_enable(pa_iochannel *io) {
assert(io->ifd >= 0);
if (setsockopt(io->ifd, SOL_SOCKET, SO_PASSCRED, &t, sizeof(t)) < 0) {
- pa_log_error("setsockopt(SOL_SOCKET, SO_PASSCRED): %s", strerror(errno));
+ pa_log_error("setsockopt(SOL_SOCKET, SO_PASSCRED): %s", pa_cstrerror(errno));
return -1;
}
diff --git a/src/polypcore/ioline.c b/src/polypcore/ioline.c
index 9bb610fe..2e0a3e1a 100644
--- a/src/polypcore/ioline.c
+++ b/src/polypcore/ioline.c
@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <string.h>
+#include <polyp/error.h>
#include <polyp/xmalloc.h>
#include <polypcore/log.h>
@@ -275,7 +276,7 @@ static int do_read(pa_ioline *l) {
pa_ioline_puts(l, "\nExiting.\n");
do_write(l);
} else if (r < 0) {
- pa_log(__FILE__": read() failed: %s", strerror(errno));
+ pa_log(__FILE__": read(): %s", pa_cstrerror(errno));
failure(l);
return -1;
}
@@ -297,7 +298,7 @@ static int do_write(pa_ioline *l) {
while (!l->dead && pa_iochannel_is_writable(l->io) && l->wbuf_valid_length) {
if ((r = pa_iochannel_write(l->io, l->wbuf+l->wbuf_index, l->wbuf_valid_length)) < 0) {
- pa_log(__FILE__": write() failed: %s", r < 0 ? strerror(errno) : "EOF");
+ pa_log(__FILE__": write(): %s", r < 0 ? pa_cstrerror(errno) : "EOF");
failure(l);
return -1;
}
diff --git a/src/polypcore/log.c b/src/polypcore/log.c
index ce9df1a9..6cdffa51 100644
--- a/src/polypcore/log.c
+++ b/src/polypcore/log.c
@@ -94,6 +94,9 @@ void pa_log_levelv(pa_log_level_t level, const char *format, va_list ap) {
text = pa_vsprintf_malloc(format, ap);
+ if (!pa_utf8_valid(text))
+ pa_log_level(level, __FILE__": invalid UTF-8 string following below:");
+
for (t = text; t; t = n) {
if ((n = strchr(t, '\n'))) {
*n = 0;
diff --git a/src/polypcore/pid.c b/src/polypcore/pid.c
index e98dc97b..b8f53955 100644
--- a/src/polypcore/pid.c
+++ b/src/polypcore/pid.c
@@ -39,6 +39,7 @@
#include <windows.h>
#endif
+#include <polyp/error.h>
#include <polyp/xmalloc.h>
#include <polypcore/core-util.h>
@@ -56,7 +57,8 @@ static pid_t read_pid(const char *fn, int fd) {
assert(fn && fd >= 0);
if ((r = pa_loop_read(fd, t, sizeof(t)-1)) < 0) {
- pa_log(__FILE__": WARNING: failed to read PID file '%s': %s", fn, strerror(errno));
+ pa_log_warn(__FILE__": WARNING: failed to read PID file '%s': %s",
+ fn, pa_cstrerror(errno));
return (pid_t) -1;
}
@@ -86,7 +88,8 @@ static int open_pid_file(const char *fn, int mode) {
if ((fd = open(fn, mode, S_IRUSR|S_IWUSR)) < 0) {
if (mode != O_RDONLY || errno != ENOENT)
- pa_log(__FILE__": WARNING: failed to open PID file '%s': %s", fn, strerror(errno));
+ pa_log_warn(__FILE__": WARNING: failed to open PID file '%s': %s",
+ fn, pa_cstrerror(errno));
goto fail;
}
@@ -95,7 +98,8 @@ static int open_pid_file(const char *fn, int mode) {
goto fail;
if (fstat(fd, &st) < 0) {
- pa_log(__FILE__": Failed to fstat() PID file '%s': %s", fn, strerror(errno));
+ pa_log_warn(__FILE__": WARNING: failed to fstat() PID file '%s': %s",
+ fn, pa_cstrerror(errno));
goto fail;
}
@@ -107,7 +111,8 @@ static int open_pid_file(const char *fn, int mode) {
goto fail;
if (close(fd) < 0) {
- pa_log(__FILE__": Failed to close file '%s': %s", fn, strerror(errno));
+ pa_log_warn(__FILE__": WARNING: failed to close file '%s': %s",
+ fn, pa_cstrerror(errno));
goto fail;
}
@@ -164,7 +169,8 @@ int pa_pid_file_create(void) {
/* Overwrite the current PID file */
if (lseek(fd, 0, SEEK_SET) == (off_t) -1 || ftruncate(fd, 0) < 0) {
- pa_log(__FILE__": failed to truncate PID fil: %s.", strerror(errno));
+ pa_log(__FILE__": failed to truncate PID file '%s': %s",
+ fn, pa_cstrerror(errno));
goto fail;
}
@@ -198,7 +204,8 @@ int pa_pid_file_remove(void) {
pa_runtime_path("pid", fn, sizeof(fn));
if ((fd = open_pid_file(fn, O_RDWR)) < 0) {
- pa_log(__FILE__": WARNING: failed to open PID file '%s': %s", fn, strerror(errno));
+ pa_log_warn(__FILE__": WARNING: failed to open PID file '%s': %s",
+ fn, pa_cstrerror(errno));
goto fail;
}
@@ -211,7 +218,8 @@ int pa_pid_file_remove(void) {
}
if (ftruncate(fd, 0) < 0) {
- pa_log(__FILE__": failed to truncate PID file '%s': %s", fn, strerror(errno));
+ pa_log_warn(__FILE__": WARNING: failed to truncate PID file '%s': %s",
+ fn, pa_cstrerror(errno));
goto fail;
}
@@ -222,7 +230,8 @@ int pa_pid_file_remove(void) {
#endif
if (unlink(fn) < 0) {
- pa_log(__FILE__": failed to remove PID file '%s': %s", fn, strerror(errno));
+ pa_log_warn(__FILE__": WARNING: failed to remove PID file '%s': %s",
+ fn, pa_cstrerror(errno));
goto fail;
}
diff --git a/src/polypcore/protocol-esound.c b/src/polypcore/protocol-esound.c
index c11bdb21..01a72e84 100644
--- a/src/polypcore/protocol-esound.c
+++ b/src/polypcore/protocol-esound.c
@@ -30,6 +30,7 @@
#include <stdlib.h>
#include <limits.h>
+#include <polyp/error.h>
#include <polyp/sample.h>
#include <polyp/timeval.h>
#include <polyp/utf8.h>
@@ -812,7 +813,7 @@ static int do_read(struct connection *c) {
assert(c->read_data_length < sizeof(c->request));
if ((r = pa_iochannel_read(c->io, ((uint8_t*) &c->request) + c->read_data_length, sizeof(c->request) - c->read_data_length)) <= 0) {
- pa_log_debug(__FILE__": read() failed: %s", r < 0 ? strerror(errno) : "EOF");
+ pa_log_debug(__FILE__": read(): %s", r < 0 ? pa_cstrerror(errno) : "EOF");
return -1;
}
@@ -860,7 +861,7 @@ static int do_read(struct connection *c) {
assert(c->read_data && c->read_data_length < handler->data_length);
if ((r = pa_iochannel_read(c->io, (uint8_t*) c->read_data + c->read_data_length, handler->data_length - c->read_data_length)) <= 0) {
- pa_log_debug(__FILE__": read() failed: %s", r < 0 ? strerror(errno) : "EOF");
+ pa_log_debug(__FILE__": read(): %s", r < 0 ? pa_cstrerror(errno) : "EOF");
return -1;
}
@@ -880,7 +881,7 @@ static int do_read(struct connection *c) {
assert(c->scache.memchunk.memblock && c->scache.name && c->scache.memchunk.index < c->scache.memchunk.length);
if ((r = pa_iochannel_read(c->io, (uint8_t*) c->scache.memchunk.memblock->data+c->scache.memchunk.index, c->scache.memchunk.length-c->scache.memchunk.index)) <= 0) {
- pa_log_debug(__FILE__": read() failed: %s", r < 0 ? strerror(errno) : "EOF");
+ pa_log_debug(__FILE__": read(): %s", r < 0 ? pa_cstrerror(errno) : "EOF");
return -1;
}
@@ -935,7 +936,7 @@ static int do_read(struct connection *c) {
}
if ((r = pa_iochannel_read(c->io, (uint8_t*) c->playback.current_memblock->data+c->playback.memblock_index, l)) <= 0) {
- pa_log_debug(__FILE__": read() failed: %s", r < 0 ? strerror(errno) : "EOF");
+ pa_log_debug(__FILE__": read(): %s", r < 0 ? pa_cstrerror(errno) : "EOF");
return -1;
}
@@ -965,7 +966,7 @@ static int do_write(struct connection *c) {
assert(c->write_data_index < c->write_data_length);
if ((r = pa_iochannel_write(c->io, (uint8_t*) c->write_data+c->write_data_index, c->write_data_length-c->write_data_index)) < 0) {
- pa_log(__FILE__": write() failed: %s", strerror(errno));
+ pa_log(__FILE__": write(): %s", pa_cstrerror(errno));
return -1;
}
@@ -984,7 +985,7 @@ static int do_write(struct connection *c) {
if ((r = pa_iochannel_write(c->io, (uint8_t*) chunk.memblock->data+chunk.index, chunk.length)) < 0) {
pa_memblock_unref(chunk.memblock);
- pa_log(__FILE__": write(): %s", strerror(errno));
+ pa_log(__FILE__": write(): %s", pa_cstrerror(errno));
return -1;
}
diff --git a/src/polypcore/protocol-simple.c b/src/polypcore/protocol-simple.c
index caffd5c9..f15f882a 100644
--- a/src/polypcore/protocol-simple.c
+++ b/src/polypcore/protocol-simple.c
@@ -30,6 +30,7 @@
#include <errno.h>
#include <string.h>
+#include <polyp/error.h>
#include <polyp/xmalloc.h>
#include <polypcore/sink-input.h>
@@ -133,7 +134,7 @@ static int do_read(struct connection *c) {
}
if ((r = pa_iochannel_read(c->io, (uint8_t*) c->playback.current_memblock->data+c->playback.memblock_index, l)) <= 0) {
- pa_log_debug(__FILE__": read() failed: %s", r == 0 ? "EOF" : strerror(errno));
+ pa_log_debug(__FILE__": read(): %s", r == 0 ? "EOF" : pa_cstrerror(errno));
return -1;
}
@@ -167,7 +168,7 @@ static int do_write(struct connection *c) {
if ((r = pa_iochannel_write(c->io, (uint8_t*) chunk.memblock->data+chunk.index, chunk.length)) < 0) {
pa_memblock_unref(chunk.memblock);
- pa_log(__FILE__": write(): %s", strerror(errno));
+ pa_log(__FILE__": write(): %s", pa_cstrerror(errno));
return -1;
}
diff --git a/src/polypcore/socket-client.c b/src/polypcore/socket-client.c
index ec2f9a9e..aa885759 100644
--- a/src/polypcore/socket-client.c
+++ b/src/polypcore/socket-client.c
@@ -54,6 +54,7 @@
#include "winsock.h"
+#include <polyp/error.h>
#include <polyp/timeval.h>
#include <polyp/xmalloc.h>
@@ -139,7 +140,7 @@ static void do_call(pa_socket_client *c) {
lerror = sizeof(error);
if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void*)&error, &lerror) < 0) {
- pa_log(__FILE__": getsockopt(): %s", strerror(errno));
+ pa_log(__FILE__": getsockopt(): %s", pa_cstrerror(errno));
goto finish;
}
@@ -149,7 +150,7 @@ static void do_call(pa_socket_client *c) {
}
if (error != 0) {
- pa_log_debug(__FILE__": connect(): %s", strerror(error));
+ pa_log_debug(__FILE__": connect(): %s", pa_cstrerror(errno));
errno = error;
goto finish;
}
@@ -194,7 +195,7 @@ static int do_connect(pa_socket_client *c, const struct sockaddr *sa, socklen_t
pa_log_debug(__FILE__": connect(): %d", WSAGetLastError());
#else
if (errno != EINPROGRESS) {
- pa_log_debug(__FILE__": connect(): %s (%d)", strerror(errno), errno);
+ pa_log_debug(__FILE__": connect(): %s (%d)", pa_cstrerror(errno), errno);
#endif
return -1;
}
@@ -266,7 +267,7 @@ static int sockaddr_prepare(pa_socket_client *c, const struct sockaddr *sa, size
}
if ((c->fd = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) {
- pa_log(__FILE__": socket(): %s", strerror(errno));
+ pa_log(__FILE__": socket(): %s", pa_cstrerror(errno));
return -1;
}
diff --git a/src/polypcore/socket-server.c b/src/polypcore/socket-server.c
index 592b6a63..871fac11 100644
--- a/src/polypcore/socket-server.c
+++ b/src/polypcore/socket-server.c
@@ -64,6 +64,7 @@
#include <polyp/xmalloc.h>
#include <polyp/util.h>
+#include <polyp/error.h>
#include <polypcore/socket-util.h>
#include <polypcore/core-util.h>
@@ -94,7 +95,7 @@ static void callback(pa_mainloop_api *mainloop, pa_io_event *e, int fd, PA_GCC_U
pa_socket_server_ref(s);
if ((nfd = accept(fd, NULL, NULL)) < 0) {
- pa_log(__FILE__": accept(): %s", strerror(errno));
+ pa_log(__FILE__": accept(): %s", pa_cstrerror(errno));
goto finish;
}
@@ -173,7 +174,7 @@ pa_socket_server* pa_socket_server_new_unix(pa_mainloop_api *m, const char *file
assert(m && filename);
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
- pa_log(__FILE__": socket(): %s", strerror(errno));
+ pa_log(__FILE__": socket(): %s", pa_cstrerror(errno));
goto fail;
}
@@ -186,12 +187,12 @@ pa_socket_server* pa_socket_server_new_unix(pa_mainloop_api *m, const char *file
pa_socket_low_delay(fd);
if (bind(fd, (struct sockaddr*) &sa, SUN_LEN(&sa)) < 0) {
- pa_log(__FILE__": bind(): %s", strerror(errno));
+ pa_log(__FILE__": bind(): %s", pa_cstrerror(errno));
goto fail;
}
if (listen(fd, 5) < 0) {
- pa_log(__FILE__": listen(): %s", strerror(errno));
+ pa_log(__FILE__": listen(): %s", pa_cstrerror(errno));
goto fail;
}
@@ -227,7 +228,7 @@ pa_socket_server* pa_socket_server_new_ipv4(pa_mainloop_api *m, uint32_t address
assert(m && port);
if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
- pa_log(__FILE__": socket(PF_INET): %s", strerror(errno));
+ pa_log(__FILE__": socket(PF_INET): %s", pa_cstrerror(errno));
goto fail;
}
@@ -235,7 +236,7 @@ pa_socket_server* pa_socket_server_new_ipv4(pa_mainloop_api *m, uint32_t address
#ifdef SO_REUSEADDR
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
- pa_log(__FILE__": setsockopt(): %s", strerror(errno));
+ pa_log(__FILE__": setsockopt(): %s", pa_cstrerror(errno));
#endif
pa_socket_tcp_low_delay(fd);
@@ -246,12 +247,12 @@ pa_socket_server* pa_socket_server_new_ipv4(pa_mainloop_api *m, uint32_t address
sa.sin_addr.s_addr = htonl(address);
if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
- pa_log(__FILE__": bind(): %s", strerror(errno));
+ pa_log(__FILE__": bind(): %s", pa_cstrerror(errno));
goto fail;
}
if (listen(fd, 5) < 0) {
- pa_log(__FILE__": listen(): %s", strerror(errno));
+ pa_log(__FILE__": listen(): %s", pa_cstrerror(errno));
goto fail;
}
@@ -278,7 +279,7 @@ pa_socket_server* pa_socket_server_new_ipv6(pa_mainloop_api *m, const uint8_t ad
assert(m && port);
if ((fd = socket(PF_INET6, SOCK_STREAM, 0)) < 0) {
- pa_log(__FILE__": socket(PF_INET6): %s", strerror(errno));
+ pa_log(__FILE__": socket(PF_INET6): %s", pa_cstrerror(errno));
goto fail;
}
@@ -286,12 +287,12 @@ pa_socket_server* pa_socket_server_new_ipv6(pa_mainloop_api *m, const uint8_t ad
#ifdef IPV6_V6ONLY
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) < 0)
- pa_log(__FILE__": setsockopt(IPPROTO_IPV6, IPV6_V6ONLY): %s", strerror(errno));
+ pa_log(__FILE__": setsockopt(IPPROTO_IPV6, IPV6_V6ONLY): %s", pa_cstrerror(errno));
#endif
#ifdef SO_REUSEADDR
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
- pa_log(__FILE__": setsockopt(SOL_SOCKET, SO_REUSEADDR, 1): %s", strerror(errno));
+ pa_log(__FILE__": setsockopt(SOL_SOCKET, SO_REUSEADDR, 1): %s", pa_cstrerror(errno));
#endif
pa_socket_tcp_low_delay(fd);
@@ -302,12 +303,12 @@ pa_socket_server* pa_socket_server_new_ipv6(pa_mainloop_api *m, const uint8_t ad
memcpy(sa.sin6_addr.s6_addr, address, 16);
if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
- pa_log(__FILE__": bind(): %s", strerror(errno));
+ pa_log(__FILE__": bind(): %s", pa_cstrerror(errno));
goto fail;
}
if (listen(fd, 5) < 0) {
- pa_log(__FILE__": listen(): %s", strerror(errno));
+ pa_log(__FILE__": listen(): %s", pa_cstrerror(errno));
goto fail;
}
@@ -418,7 +419,7 @@ char *pa_socket_server_get_address(pa_socket_server *s, char *c, size_t l) {
socklen_t sa_len = sizeof(sa);
if (getsockname(s->fd, (struct sockaddr*) &sa, &sa_len) < 0) {
- pa_log(__FILE__": getsockname() failed: %s", strerror(errno));
+ pa_log(__FILE__": getsockname(): %s", pa_cstrerror(errno));
return NULL;
}
@@ -439,7 +440,7 @@ char *pa_socket_server_get_address(pa_socket_server *s, char *c, size_t l) {
char ip[INET6_ADDRSTRLEN];
if (!inet_ntop(AF_INET6, &sa.sin6_addr, ip, sizeof(ip))) {
- pa_log(__FILE__": inet_ntop() failed: %s", strerror(errno));
+ pa_log(__FILE__": inet_ntop(): %s", pa_cstrerror(errno));
return NULL;
}
@@ -454,7 +455,7 @@ char *pa_socket_server_get_address(pa_socket_server *s, char *c, size_t l) {
socklen_t sa_len = sizeof(sa);
if (getsockname(s->fd, (struct sockaddr*) &sa, &sa_len) < 0) {
- pa_log(__FILE__": getsockname() failed: %s", strerror(errno));
+ pa_log(__FILE__": getsockname(): %s", pa_cstrerror(errno));
return NULL;
}
@@ -474,7 +475,7 @@ char *pa_socket_server_get_address(pa_socket_server *s, char *c, size_t l) {
char ip[INET_ADDRSTRLEN];
if (!inet_ntop(AF_INET, &sa.sin_addr, ip, sizeof(ip))) {
- pa_log(__FILE__": inet_ntop() failed: %s", strerror(errno));
+ pa_log(__FILE__": inet_ntop(): %s", pa_cstrerror(errno));
return NULL;
}
diff --git a/src/polypcore/socket-util.c b/src/polypcore/socket-util.c
index acbb7c1f..06cdc625 100644
--- a/src/polypcore/socket-util.c
+++ b/src/polypcore/socket-util.c
@@ -59,6 +59,7 @@
#include "winsock.h"
+#include <polyp/error.h>
#include <polyp/xmalloc.h>
#include <polypcore/core-util.h>
@@ -198,7 +199,7 @@ int pa_unix_socket_is_stale(const char *fn) {
int fd = -1, ret = -1;
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
- pa_log(__FILE__": socket(): %s", strerror(errno));
+ pa_log(__FILE__": socket(): %s", pa_cstrerror(errno));
goto finish;
}