summaryrefslogtreecommitdiffstats
path: root/include/dnsjit/gen-compat.lua
diff options
context:
space:
mode:
Diffstat (limited to 'include/dnsjit/gen-compat.lua')
-rw-r--r--include/dnsjit/gen-compat.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/include/dnsjit/gen-compat.lua b/include/dnsjit/gen-compat.lua
new file mode 100644
index 0000000..65c40ec
--- /dev/null
+++ b/include/dnsjit/gen-compat.lua
@@ -0,0 +1,34 @@
+for line in io.lines("config.h") do
+ local n, s = line:match("define SIZEOF_(%S*) (%d+)")
+ if n and s then
+ if n:match("^PTHREAD") or n:match("^CK_") or n:match("^GNUTLS_") then
+ s = math.ceil(s / 8)
+ print("#if !defined(SIZEOF_"..n..") || SIZEOF_"..n.." == 0")
+ print("#error \""..n.." is undefined or zero\"")
+ print("#endif")
+ n = n:lower()
+ print("typedef struct "..n:sub(1,-3).." { uint64_t a["..s.."]; } "..n..";")
+ elseif n:match("^STRUCT") then
+ n = n:match("^STRUCT_(%S*)")
+ if n == "SOCKADDR_STORAGE" or n == "POLLFD" then
+ print("#if !defined(SIZEOF_STRUCT_"..n..") || SIZEOF_STRUCT_"..n.." == 0")
+ print("#error \""..n.." is undefined or zero\"")
+ print("#endif")
+ n = n:lower()
+ print("struct "..n.." { uint8_t a["..s.."]; };")
+ end
+ end
+ end
+end
+code, err = pcall(function()
+ local ffi = require("ffi")
+ ffi.cdef[[
+ ssize_t dummy;
+ ]]
+end)
+if code then
+ print("#include <unistd.h>")
+ print("typedef ssize_t luajit_ssize_t;")
+else
+ print("typedef long luajit_ssize_t;")
+end