- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 libffi 在 macos (10.11) 上访问 stat()。这是 SWI-Prolog 的新的基于 FFI 的外部接口(interface)的一部分。此接口(interface)解析 <sys/stat.h>
头获取函数原型(prototype)和struct stat
类型。但是,我得到了虚假的值。如果我编译下面的代码并链接mystat
,它工作正常从生成的.dylib
.
#include <sys/stat.h>
int
mystat(const char *name, struct stat *buf)
{ return stat(name, buf);
}
stat
函数来自
dlsym()
.在
/usr/lib/libc.dylib
上都试过了和
/usr/lib/libSystem.B.dylib
.这给出了相同的结果。如果我运行
nm
在上面的 dylib 上我得到
U _stat$INODE64
.
dlsym
不适用于
stat$INODE64
.查看 libc.dylib 我们得到
534_> nm /usr/lib/libc.dylib | grep stat
0000000000001ac5 T R8289209$_pthread_attr_setdetachstate
0000000000001af7 T R8289209$_stat
U _pthread_attr_setdetachstate
U _stat
最佳答案
您要查找的符号在 /usr/lib/system/libsystem_kernel.dylib
中定义。 :
$ ~ nm -g /usr/lib/system/libsystem_kernel.dylib | grep '_stat\$INODE64'
0000000000002ed0 T _stat$INODE64
dlsym
找到它:
#include <sys/stat.h>
#include <dlfcn.h>
#include <stdio.h>
#include <string.h>
int
(*real_stat)(const char *path, struct stat *buf);
int main() {
const char *path = "/usr/lib/system/libsystem_kernel.dylib";
int err;
struct stat st;
void *lib = dlopen(path, RTLD_LOCAL);
real_stat = dlsym(lib, "stat$INODE64");
if((err = real_stat(path, &st)))
fprintf(stderr, "Can't stat %s: %s\n", path, strerror(err));
printf("%s inode: %lld\n", path, st.st_ino);
dlclose(lib);
return 0;
}
real_stat
返回的 inode 号匹配
stat(1)
返回的那个:
$ ~ cc stat.c
$ ~ ./a.out
/usr/lib/system/libsystem_kernel.dylib inode: 4335860614
$ ~ stat -r /usr/lib/system/libsystem_kernel.dylib
16777220 4335860614 0100755 1 0 0 0 545424 1564436981 1564436981 1565194657 1564436981 4096 448 524320 /usr/lib/system/libsystem_kernel.dylib
stat
像这样被错误地声明:
struct stat;
int stat(const char *restrict path, struct stat *restrict buf);
int mystat(const char *path, struct stat *buf) {
return stat(path, buf);
}
stat
:
$ ~ cc -dynamiclib wrong-stat.c -o libwrongstat.dylib
$ ~ nm libwrongstat.dylib
0000000000000f70 T _mystat
U _stat
U dyld_stub_binder
<sys/stat.h>
声明
stat
使用特殊
assembler names for functions与
$INODE64
后缀,以避免与现有的
stat
冲突(详见
stat(2)
)。如果
stat
可以修复库声明为使用后缀引用新的汇编程序名称:
struct stat;
int stat(const char *path, struct stat *buf) __asm("_stat$INODE64");
int mystat(const char *path, struct stat *buf) {
return stat(path, buf);
}
$ ~ cc -dynamiclib correct-stat.c -o libcorrectstat.dylib
$ ~ nm libcorrectstat.dylib
0000000000000f70 T _mystat
U _stat$INODE64
U dyld_stub_binder
<sys/stat.h>
提取正确的符号声明。
关于macos - OSX stat() 和 libffi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48380955/
所以,我正在尝试创建一种 ls 函数。这是我对每个文件的描述的代码 struct stat fileStat; struct dirent **files; num_entries = scandir
我最近一直在尝试实现我自己的 linux ls 命令版本。一切都很好,但是当我尝试使用 ls -l 功能时,struct stat 的某些字段未初始化 - 我得到 NULL 指针或垃圾值,尽管它似乎只
我在 Yii 中遇到 STAT 关系问题。我不确定我正在寻找的东西是否可以通过本地 Yii 关系实现。我会尽力描述我的问题,如果不清楚,请询问任何具体细节。 我有三个表,因此有三个模型 | table
我正在为一个严重依赖 scipy.stats.stats(scipy 版本 0.9.0)的包创建一个 django-powered (1.3) 接口(interface),称为 ovl 。在早期开发阶
为了安全起见,我喜欢显式初始化我的变量(当您编写大量代码时,它通常会使它更安全,因为您的代码最终不会崩溃那么多。) 对于大多数类型,无论是结构还是整数等基本 C++ 类型,我都可以编写以下内容: ti
我一直在使用 stat() 检查文件是否存在,据我所知,这比尝试打开文件更好。但是,stat() 不适用于包含其他语言的 unicode 字符的文件名。是否有 stat() 的宽字符版本或我可以使用的
错误: File "/usr/lib/python2.7/dist-packages/statsmodels/regression/linear_model.py", line 36, in
下面是我要运行的脚本。我不能在 awk 中使用 stat。 cat /etc/passwd | awk 'BEGIN{FS=":"}{print $6 }' | (stat $6 | sed -n '
我正在尝试拟合 xlog 线性回归。我使用 Seaborn regplot 来绘制拟合,看起来很合适(绿线)。然后,因为 regplot 不提供系数。我使用 stats.linregress 来查找系
我正在尝试使用共享库 (libscplugin.so) 中包含的方法。 我已经满足了库的所有要求: libc.so 带有指向 libc.so.6 的符号链接(symbolic link) libz.s
嘿,感谢阅读。 我正在制作一个程序,它接受 1 个参数(目录)并使用 opendir()/readdir() 读取目录中的所有文件,并使用 stat 显示文件类型(reg、链接、目录等)。当我在 sh
简单问题:在 Linux 中,我 stat() 一个不是设备的文件。 st_rdev 字段的期望值是多少?我可以运行 major(stat.st_rdev) 和 minor(stat.st_rdev)
我正在尝试为我的 Angular 6 应用程序生成 stats.json 文件。下面的事情我已经尝试过,但根本没有生成文件。我的系统需要有 “npm 运行”在每个 angular cli 命令之前。
我正在尝试使用返回的 stat 结构中的 st_mode,该结构是我通过以下方式从 stat() 调用获得的; char *fn = "test.c" struct s
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我有一个程序,是我通过修改原始暗网(深度学习图像识别,Yolov2)的许多地方而制作的。几个月前我一直在使用它,但是今天当我编译它时,它给了我一个错误: gcc -DSAVE_LAYER_INPUT
我预计 scipy.stats.mstats.pearsonr 对于屏蔽数组输入的结果将与 scipy.stats.pearsonr 对于输入数据的 unmasked 值给出相同的结果,但它不会't:
给定 tmp.c: #include #include #include int main(int argc, const char *argv[]) { struct stat st;
In [15]: a = np.array([0.5, 0.5, 0, 0, 0]) In [16]: b = np.array([1, 0, 0, 0, 0]) In [17]: entropy(a
当我们运行 stat filename我们得到 Access: 2021-06-25 15:40:18.532621916 +0530 Modify: 2020-08-13 15:57:30.0000
我是一名优秀的程序员,十分优秀!