summaryrefslogtreecommitdiffstats
path: root/input
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-11-26 21:21:56 +0100
committerDiogo Franco (Kovensky) <diogomfranco@gmail.com>2015-01-25 17:00:14 +0900
commitf24b8cbd47a9e75c635b1537aff16de18d350021 (patch)
tree621b05d169fdd9010ab58e4e7b467710efdb4da5 /input
parentb7061982079f33217e3d44f10d9892257f47c7ca (diff)
downloadmpv-f24b8cbd47a9e75c635b1537aff16de18d350021.tar.bz2
mpv-f24b8cbd47a9e75c635b1537aff16de18d350021.tar.xz
Do not call strerror()
...because everything is terrible. strerror() is not documented as having to be thread-safe by POSIX and C11. (Which is pretty much bullshit, because both mandate threads and some form of thread-local storage - so there's no excuse why implementation couldn't implement this in a thread-safe way. Especially with C11 this is ridiculous, because there is no way to use threads and convert error numbers to strings at the same time!) Since we heavily use threads now, we should avoid unsafe functions like strerror(). strerror_r() is in POSIX, but GNU/glibc deliberately fucks it up and gives the function different semantics than the POSIX one. It's a bit of work to convince this piece of shit to expose the POSIX standard function, and not the messed up GNU one. strerror_l() is also in POSIX, but only since the 2008 standard, and thus is not widespread. The solution is using avlibc (libavutil, by its official name), which handles the unportable details for us, mostly. We avoid some pain.
Diffstat (limited to 'input')
-rw-r--r--input/joystick.c15
-rw-r--r--input/lirc.c3
2 files changed, 12 insertions, 6 deletions
diff --git a/input/joystick.c b/input/joystick.c
index ba71da8b52..e3df106735 100644
--- a/input/joystick.c
+++ b/input/joystick.c
@@ -28,6 +28,7 @@
#include <errno.h>
#include <poll.h>
+#include "common/common.h"
#include "common/msg.h"
#include "keycodes.h"
@@ -65,7 +66,8 @@ static struct ctx *joystick_init(struct input_ctx *ictx, struct mp_log *log, cha
fd = open( dev ? dev : JS_DEV , O_RDONLY | O_NONBLOCK );
if(fd < 0) {
- mp_err(log, "Can't open joystick device %s: %s\n",dev ? dev : JS_DEV,strerror(errno));
+ mp_err(log, "Can't open joystick device %s: %s\n",dev ? dev : JS_DEV,
+ mp_strerror(errno));
return NULL;
}
@@ -83,7 +85,8 @@ static struct ctx *joystick_init(struct input_ctx *ictx, struct mp_log *log, cha
initialized = 1;
break;
}
- MP_ERR(ctx, "Error while reading joystick device: %s\n",strerror(errno));
+ MP_ERR(ctx, "Error while reading joystick device: %s\n",
+ mp_strerror(errno));
close(fd);
talloc_free(ctx);
return NULL;
@@ -117,10 +120,12 @@ static int mp_input_joystick_read(void *pctx, int fd) {
continue;
else if(errno == EAGAIN)
return 0;
- if( r < 0)
- MP_ERR(ctx, "Error while reading joystick device: %s\n",strerror(errno));
- else
+ if( r < 0) {
+ MP_ERR(ctx, "Error while reading joystick device: %s\n",
+ mp_strerror(errno));
+ } else {
MP_ERR(ctx, "Error while reading joystick device: %s\n","EOF");
+ }
return -1;
}
l += r;
diff --git a/input/lirc.c b/input/lirc.c
index 2805043c03..db8d4f8e79 100644
--- a/input/lirc.c
+++ b/input/lirc.c
@@ -25,6 +25,7 @@
#include <stdlib.h>
#include <poll.h>
+#include "common/common.h"
#include "common/msg.h"
#include "input.h"
@@ -49,7 +50,7 @@ static struct ctx *mp_input_lirc_init(struct input_ctx *ictx, struct mp_log *log
mode = fcntl(lirc_sock, F_GETFL);
if (mode < 0 || fcntl(lirc_sock, F_SETFL, mode | O_NONBLOCK) < 0) {
- mp_err(log, "setting non-blocking mode failed: %s\n", strerror(errno));
+ mp_err(log, "setting non-blocking mode failed: %s\n", mp_strerror(errno));
lirc_deinit();
return NULL;
}