diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/chat/modules/CLib.sys.mjs | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/chat/modules/CLib.sys.mjs')
-rw-r--r-- | comm/chat/modules/CLib.sys.mjs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/comm/chat/modules/CLib.sys.mjs b/comm/chat/modules/CLib.sys.mjs new file mode 100644 index 0000000000..35226b565b --- /dev/null +++ b/comm/chat/modules/CLib.sys.mjs @@ -0,0 +1,64 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import { ctypes } from "resource://gre/modules/ctypes.sys.mjs"; + +var OS = Services.appinfo.OS.toLowerCase(); + +// type defs + +var FILE = ctypes.StructType("FILE"); +var fname_t = ctypes.char.ptr; +var wchar_t = ctypes.char16_t; + +// Set the abi and path to CLib based on the OS. +var libcAbi, libcPath; +var strdup = "strdup"; +var fopen = "fopen"; + +switch (OS) { + case "win32": + case "winnt": + libcAbi = ctypes.winapi_abi; + libcPath = ctypes.libraryName("msvcrt"); + strdup = "_strdup"; + fopen = "_wfopen"; + fname_t = wchar_t.ptr; + break; + case "darwin": + case "dragonfly": + case "netbsd": + case "openbsd": + libcAbi = ctypes.default_abi; + libcPath = ctypes.libraryName("c"); + break; + case "freebsd": + libcAbi = ctypes.default_abi; + libcPath = "libc.so.7"; + break; + case "linux": + libcAbi = ctypes.default_abi; + libcPath = "libc.so.6"; + break; + default: + throw new Error("Unknown OS"); +} + +var libc = ctypes.open(libcPath); + +export var CLib = { + FILE, + memcmp: libc.declare( + "memcmp", + libcAbi, + ctypes.int, + ctypes.void_t.ptr, + ctypes.void_t.ptr, + ctypes.size_t + ), + free: libc.declare("free", libcAbi, ctypes.void_t, ctypes.void_t.ptr), + strdup: libc.declare(strdup, libcAbi, ctypes.char.ptr, ctypes.char.ptr), + fclose: libc.declare("fclose", libcAbi, ctypes.int, FILE.ptr), + fopen: libc.declare(fopen, libcAbi, FILE.ptr, fname_t, fname_t), +}; |