如何在 macOS 上将 libbsm/openbsm 与 Swift5 一起使用?
How Do I use libbsm/openbsm with Swift5 on macOS?
我尝试在 Xcode11 中使用 libbsm/openbsm 库和 Swift5。
为什么?我不能罚款AUDITPIPE_SET_PRESELECT_MODE
.
我可以在 Swift 中使用 libbsm/openbsm 吗?
var mode = AUDITPIPE_PRESELECT_MODE_LOCAL // <- works very well
if ioctl(auditFD, AUDITPIPE_SET_PRESELECT_MODE, &mode) == -1 {
return -1
}
我 运行 遇到了同样的问题 Swift 无法导入这些复杂的宏。奎因“爱斯基摩人!”指出我将它们声明为 c 常量的方向。所以我在我的项目中的一个 c 文件中创建了它们。
在 .h 文件中我做了以下操作:
#include <stdio.h>
#include <bsm/libbsm.h>
#include <sys/ioctl.h>
#include <security/audit/audit_ioctl.h>
// -- Macros used for creating an auditpipe
extern unsigned long QAUDITPIPE_SET_PRESELECT_MODE;
extern unsigned long QAUDITPIPE_GET_QLIMIT_MAX;
extern unsigned long QAUDITPIPE_SET_QLIMIT;
extern unsigned long QAUDITPIPE_SET_PRESELECT_FLAGS;
extern unsigned long QAUDITPIPE_SET_PRESELECT_NAFLAGS;
// -- End auditpipe macros
在我的 .c 文件中我有:
unsigned long QAUDITPIPE_SET_PRESELECT_MODE = AUDITPIPE_SET_PRESELECT_MODE;
unsigned long QAUDITPIPE_GET_QLIMIT_MAX = AUDITPIPE_GET_QLIMIT_MAX;
unsigned long QAUDITPIPE_SET_QLIMIT = AUDITPIPE_SET_QLIMIT;
unsigned long QAUDITPIPE_SET_PRESELECT_FLAGS = AUDITPIPE_SET_PRESELECT_FLAGS;
unsigned long QAUDITPIPE_SET_PRESELECT_NAFLAGS = AUDITPIPE_SET_PRESELECT_NAFLAGS;
所以现在我可以在 Swift 代码中使用 QAUDITPIPE_SET_PRESELECT_MODE。效果很好!
我尝试在 Xcode11 中使用 libbsm/openbsm 库和 Swift5。
为什么?我不能罚款AUDITPIPE_SET_PRESELECT_MODE
.
我可以在 Swift 中使用 libbsm/openbsm 吗?
var mode = AUDITPIPE_PRESELECT_MODE_LOCAL // <- works very well
if ioctl(auditFD, AUDITPIPE_SET_PRESELECT_MODE, &mode) == -1 {
return -1
}
我 运行 遇到了同样的问题 Swift 无法导入这些复杂的宏。奎因“爱斯基摩人!”指出我将它们声明为 c 常量的方向。所以我在我的项目中的一个 c 文件中创建了它们。
在 .h 文件中我做了以下操作:
#include <stdio.h>
#include <bsm/libbsm.h>
#include <sys/ioctl.h>
#include <security/audit/audit_ioctl.h>
// -- Macros used for creating an auditpipe
extern unsigned long QAUDITPIPE_SET_PRESELECT_MODE;
extern unsigned long QAUDITPIPE_GET_QLIMIT_MAX;
extern unsigned long QAUDITPIPE_SET_QLIMIT;
extern unsigned long QAUDITPIPE_SET_PRESELECT_FLAGS;
extern unsigned long QAUDITPIPE_SET_PRESELECT_NAFLAGS;
// -- End auditpipe macros
在我的 .c 文件中我有:
unsigned long QAUDITPIPE_SET_PRESELECT_MODE = AUDITPIPE_SET_PRESELECT_MODE;
unsigned long QAUDITPIPE_GET_QLIMIT_MAX = AUDITPIPE_GET_QLIMIT_MAX;
unsigned long QAUDITPIPE_SET_QLIMIT = AUDITPIPE_SET_QLIMIT;
unsigned long QAUDITPIPE_SET_PRESELECT_FLAGS = AUDITPIPE_SET_PRESELECT_FLAGS;
unsigned long QAUDITPIPE_SET_PRESELECT_NAFLAGS = AUDITPIPE_SET_PRESELECT_NAFLAGS;
所以现在我可以在 Swift 代码中使用 QAUDITPIPE_SET_PRESELECT_MODE。效果很好!