aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2024-01-24 19:29:42 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2024-01-24 19:29:42 +0300
commitd444a5d7405016a5094e26050cfb453bcd6f882a (patch)
tree64e64cdc97dc128b5cf4a7aebeec32ef5bf47e63
parentb45726451da90bba61d75f817982d2abdfbb0542 (diff)
downloadapplause2-d444a5d7405016a5094e26050cfb453bcd6f882a.tar.gz
evdev: access struct dirent via helper function applause_dirent_name() instead directly from Lua
* the structure is highly platform-dependant and might even differ between 32-bit and 64-bit systems * in particular this fixes EvdevStream on FreeBSD
-rw-r--r--evdev.c7
-rw-r--r--evdev.h1
-rw-r--r--evdev.lua14
3 files changed, 10 insertions, 12 deletions
diff --git a/evdev.c b/evdev.c
index 8cc4aa4..6b9d494 100644
--- a/evdev.c
+++ b/evdev.c
@@ -6,6 +6,7 @@
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
+#include <dirent.h>
#include <sys/ioctl.h>
#include <sys/types.h>
@@ -25,6 +26,12 @@ struct applause_evdev {
pthread_t thread;
};
+const char *
+applause_dirent_name(const struct dirent *entry)
+{
+ return entry->d_name;
+}
+
char *
applause_evdev_getname(const char *node)
{
diff --git a/evdev.h b/evdev.h
index 764b11b..68442e3 100644
--- a/evdev.h
+++ b/evdev.h
@@ -8,6 +8,7 @@ typedef struct applause_evdev_sample {
typedef struct applause_evdev applause_evdev;
+const char *applause_dirent_name(const struct dirent *entry);
char *applause_evdev_getname(const char *node);
applause_evdev *applause_evdev_new(const char *node, bool grab);
void applause_evdev_pull(applause_evdev *evdev, applause_evdev_sample *sample);
diff --git a/evdev.lua b/evdev.lua
index 2f05bc2..09b359a 100644
--- a/evdev.lua
+++ b/evdev.lua
@@ -64,16 +64,6 @@ enum applause_evdev_abs {
*/
typedef struct __dirstream DIR;
-/* FIXME: Does this work on 32-bit? Can this be defined portably? */
-struct dirent {
- unsigned long d_ino; /* Inode number */
- unsigned long d_off; /* Not an offset; see below */
- unsigned short d_reclen; /* Length of this record */
- unsigned char d_type; /* Type of file; not supported
- by all filesystem types */
- char d_name[256]; /* Null-terminated filename */
-};
-
DIR *opendir(const char *name);
struct dirent *readdir(DIR *dirp);
int closedir(DIR *dirp);
@@ -96,7 +86,7 @@ function EvdevStream.list()
while true do
local entry = C.readdir(dir)
if entry == nil then break end
- local filename = ffi.string(entry[0].d_name)
+ local filename = ffi.string(C.applause_dirent_name(entry))
local devname = ffi.gc(C.applause_evdev_getname("/dev/input/"..filename), C.free)
if devname ~= nil then
print(filename:match("%d+$")..": "..ffi.string(devname))
@@ -137,7 +127,7 @@ function EvdevStream:ctor(id, grab)
while true do
local entry = C.readdir(dir)
if entry == nil then error("Evdev device not found!") end
- node = "/dev/input/"..ffi.string(entry[0].d_name)
+ node = "/dev/input/"..ffi.string(C.applause_dirent_name(entry))
local name = ffi.gc(C.applause_evdev_getname(node), C.free)
if name ~= nil and ffi.string(name):match(id) then break end
end